D For A Web Developer
Adam D. Ruppe via Digitalmars-d
digitalmars-d at puremagic.com
Wed Apr 30 07:48:46 PDT 2014
On Wednesday, 30 April 2014 at 09:22:06 UTC, Chris wrote:
> Is there any documentation for web.d, including example apps?
Not much, I've done some before but it is pretty scattered and I
don't even know where it all is right now.
> I basically implemented the most important JS features for DOM
> manipulation and added stuff I'd always wanted in JS.
Yeah, dom.d is kinda my magical group of nice convenience too.
The .addChild() helper makes building a tree in code so simple
that I rarely even thing about innerHTML anymore.
addChild takes a tag name and two child strings which are
customized based on the tag name:
addChild("a", "Link test", "http://link-target.com/"); // makes
<a href="httpp....">Link test</a>
addChild("span", "foo", "bar"); // makes <span
class="bar">foo</span>
addChild("div", Html("<b>lol</b>")); // <div><b>lol</b></div>
(normally, the second argument is innerText and the third
argument is the big customization point.)
dom.d's Form class makes them stupid-simple to use too.
auto form = document.requireSelector!Form("#my-form");
form.setValue("something", "else");
setValue finds the element with that particular name and sets teh
value based on what it is. So if it is an <input>, it sets value.
If it is a <textarea>, it sets innerText. If it is <select>, it
sets the attribute on the right <option>, or can add an option if
needed. It can also implicitly create a hidden element if needed.
The Link class has a similar function for link URL params.
And, of course, these can be done in a loop:
void forwardParams() {
foreach(k, v; cgi.post)
form.setValue(k, v);
}
so simple!
More information about the Digitalmars-d
mailing list