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 1Following JavaScript code: sys.puts(
DIV({id: 'meaning', onclick: 'alert(42)'},
"Meaning")
)
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: 'http://www.spam.com'}, 'Click me!!!')
)
sys.puts(my_template)
link.class = 'spam'
sys.puts(link)
Would output: <div><a href="http://www.spam.com">Click me!!!</a></div>
<a href="http://www.spam.com" class="spam">Click me!!!</a>
node.magic_dom is a port of MagicDOM, which is a DSL for AJS I built in 2007.
Announcements
·
Code
·
JavaScript
·
node.js
•
16. May 2010
|
|