D to Javascript converter (a hacked up dmd)

Adam D. Ruppe destructionator at gmail.com
Mon Feb 27 07:55:53 PST 2012


On Monday, 27 February 2012 at 15:39:50 UTC, Andrea Fontana wrote:
> About jquery: i mean what about a d function similar to  $() 
> jquery
> function for better elements handling (instead of 
> getElementById() )

Have you seen my dom library? :P

It's all server side but it is just awesome. Lots of
convenience functions, getting elements is easy, and
operating on them as a group is too, either through
a wrapper struct or just using foreach yourself.

I definitely want to port some of it to the javascript
output.

https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff
the file is dom.d. It also depends on characterencodings.d.

The most jquery-like interface is Document's opIndex:

document[`#something .my-thing > p`].addClass("matched")
   .appendText("matched me!");


Though, I really think that querySelectorAll + foreach
wipes out jquery's element selection advantage.

querySelectorAll is in all browsers IE8 and up. Adding
foreach to javascript can be done with text macro
(see html.d in my github) or D->JS of course has foreach
too!


The zip of d->js actually breaks on foreach here, but
it was an easy fix. I'll push up the changes this next
weekend.


Anyway, here's how it looks:

foreach(element; document.querySelectorAll("#blah > p"))
     // do something to element



More information about the Digitalmars-d-announce mailing list