node.magic_dom: A DSL for building HTML in node.js

I have released node.magic_dom, a DSL which makes it easy to build HTML directly in JavaScript. I think it would be pretty cool to build a template system around magic_dom, similar to Python's Stan.

Example 1

Following JavaScript code:

    DIV({id: 'meaning', onclick: 'alert(42)'}, 

Would output:

<div id="meaning" onclick="alert(42)">Meaning</div>

Example 2:

It's possible to alter a DOM element dynamically, e.g.

var link, my_template;
my_template = DIV(
    link = A({href: ''}, 'Click me!!!')

link.class = 'spam'

Would output:

<div><a href="">Click me!!!</a></div>
<a href="" class="spam">Click me!!!</a>

node.magic_dom is a port of MagicDOM, which is a DSL for AJS I built in 2007.

16. May 2010 Announcements · Code · JavaScript · node.js
© Amir Salihefendic