Laconic: A Sane Method of Generating DOM Content in JavaScript
joestelmach.github.com
Laconic: A Sane Method of Generating DOM Content in JavaScript
1–10 of 51 posts
Re: Laconic: A Sane Method of Generating DOM Content in JavaScript
#2Re: Laconic: A Sane Method of Generating DOM Content in JavaScript
#3https://github.com/petehunt/htmldry/blob/master/demos/events...
It's a little more HAML-inspired though.
Re: Laconic: A Sane Method of Generating DOM Content in JavaScript
#4[0]: http://i.imgur.com/RNBYd.png
[1]: http://msdn.microsoft.com/en-us/library/dd347148(v=VS.85).as...
Re: Laconic: A Sane Method of Generating DOM Content in JavaScript
#5 div(span('hello world')).inject(document.body);
Very simple to do and even simpler to use.Re: Laconic: A Sane Method of Generating DOM Content in JavaScript
#6The problem I see is that this only works for "all known HTML tags." If you want to use custom tags, like (I believe that's what meteor uses), this won't cut it since it uses $.el.tagname syntax, every tag has to be loaded into the $.el object.
How about a very similar, more jQuery-like syntax instead:
$.el('template', [
$.el('div', {'class' : 'foo'}, [
//other children here
//so basically, the last arg is always an array of children
]
]);Re: Laconic: A Sane Method of Generating DOM Content in JavaScript
#7Your API will explode violently in IE Using `Object.prototype.toString.call` is also a pretty dirty hack, especially to detect an "array". I think `typeof obj === "object" && obj.length` would suffice, even if certain false positives like string objects leak through. [0]: http://i.imgur.com/RNBYd.png [1]: http://msdn.microsoft.com/en-us/library/dd347148(v=VS.85).as...
Re: Laconic: A Sane Method of Generating DOM Content in JavaScript
#8This is really neat. The coolest part is being able to register your own "tags" which take any arguments you want. The problem I see is that this only works for "all known HTML tags." If you want to use custom tags, like (I believe that's what meteor uses), this won't cut it since it uses $.el.tagname syntax, every tag has to be loaded into the $.el object. How about a very similar, more jQuery-like syntax instead: $…
$.el.div({className : 'foo'});
$.el('div', {className : 'foo'});Re: Laconic: A Sane Method of Generating DOM Content in JavaScript
#9I simply generate global functions corresponding to tags, so my stuff looks like this: div(span('hello world')).inject(document.body); Very simple to do and even simpler to use.
Re: Laconic: A Sane Method of Generating DOM Content in JavaScript
#10How about a library like this to generate a string of HTML instead of dom elements?