<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.1.3" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Html generation in JavaScript</title>
	<link>http://www.stifflog.com/2007/06/10/html-generation-in-javascript/</link>
	<description>Just another WordPress weblog</description>
	<pubDate>Fri, 05 Sep 2008 19:19:11 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.1.3</generator>

	<item>
		<title>By: Riddle</title>
		<link>http://www.stifflog.com/2007/06/10/html-generation-in-javascript/#comment-1893</link>
		<author>Riddle</author>
		<pubDate>Sun, 10 Jun 2007 22:48:39 +0000</pubDate>
		<guid>http://www.stifflog.com/2007/06/10/html-generation-in-javascript/#comment-1893</guid>
					<description>Great post and approach, thanks.

But as a matter of fact, there are existing solutions for issue you've raised. I browsed through jQuery's plugins repository and found few examples:

&lt;a href="http://mg.to/2006/02/27/easy-dom-creation-for-jquery-and-prototype" rel="nofollow"&gt;Easy DOM creation&lt;/a&gt;
&lt;a href="http://www.talrasha.com/jquery/jquery.easydom.html" rel="nofollow"&gt;LISP-style DOM creation&lt;/a&gt;
&lt;a href="http://www.pinkblack.org/itblog/?page_id=22" rel="nofollow"&gt;And another one&lt;/a&gt;

I haven't had a chance to use them in projects, but I will surely do - this creation looks amazingly easy. I'm also going to download yours and give it a try - it's nice to have simple standalone script sometimes.</description>
		<content:encoded><![CDATA[<p>Great post and approach, thanks.</p>
<p>But as a matter of fact, there are existing solutions for issue you&#8217;ve raised. I browsed through jQuery&#8217;s plugins repository and found few examples:</p>
<p><a href="http://mg.to/2006/02/27/easy-dom-creation-for-jquery-and-prototype" rel="nofollow">Easy DOM creation</a><br />
<a href="http://www.talrasha.com/jquery/jquery.easydom.html" rel="nofollow">LISP-style DOM creation</a><br />
<a href="http://www.pinkblack.org/itblog/?page_id=22" rel="nofollow">And another one</a></p>
<p>I haven&#8217;t had a chance to use them in projects, but I will surely do - this creation looks amazingly easy. I&#8217;m also going to download yours and give it a try - it&#8217;s nice to have simple standalone script sometimes.</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: medyk</title>
		<link>http://www.stifflog.com/2007/06/10/html-generation-in-javascript/#comment-1894</link>
		<author>medyk</author>
		<pubDate>Sun, 10 Jun 2007 23:29:56 +0000</pubDate>
		<guid>http://www.stifflog.com/2007/06/10/html-generation-in-javascript/#comment-1894</guid>
					<description>Ha!.. I'm working on template engine for php which use very similar syntax :)
Generally I prefer to work on DOM objects than on text.. all is so much clearer and easier to manage</description>
		<content:encoded><![CDATA[<p>Ha!.. I&#8217;m working on template engine for php which use very similar syntax :)<br />
Generally I prefer to work on DOM objects than on text.. all is so much clearer and easier to manage</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: stiff</title>
		<link>http://www.stifflog.com/2007/06/10/html-generation-in-javascript/#comment-1902</link>
		<author>stiff</author>
		<pubDate>Mon, 11 Jun 2007 04:25:32 +0000</pubDate>
		<guid>http://www.stifflog.com/2007/06/10/html-generation-in-javascript/#comment-1902</guid>
					<description>Riddle: I thought that someone already did that, thanks for the links :) But after looking at the sources, I'm also happy to admit that my library is better than the ones you pasted - it implements the whole HTML specification, while the other libraries either allow you to use only a subset of HTML tags or don't do any validation of the stuff you create at all. I also like my syntax better...

medyk: Working on DOM objects is often a better approach, but when you have bigger amounts of  stuff to generate it's nice to have a "tighter" syntax for this task.</description>
		<content:encoded><![CDATA[<p>Riddle: I thought that someone already did that, thanks for the links :) But after looking at the sources, I&#8217;m also happy to admit that my library is better than the ones you pasted - it implements the whole HTML specification, while the other libraries either allow you to use only a subset of HTML tags or don&#8217;t do any validation of the stuff you create at all. I also like my syntax better&#8230;</p>
<p>medyk: Working on DOM objects is often a better approach, but when you have bigger amounts of  stuff to generate it&#8217;s nice to have a &#8220;tighter&#8221; syntax for this task.</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: medyk</title>
		<link>http://www.stifflog.com/2007/06/10/html-generation-in-javascript/#comment-1910</link>
		<author>medyk</author>
		<pubDate>Mon, 11 Jun 2007 15:27:20 +0000</pubDate>
		<guid>http://www.stifflog.com/2007/06/10/html-generation-in-javascript/#comment-1910</guid>
					<description>yeah stiff.. all I meant by my comment is that I prefer to work on DOM objects and to make things easier I'm working on template engine that uses syntax very similar to what you've proposed above</description>
		<content:encoded><![CDATA[<p>yeah stiff.. all I meant by my comment is that I prefer to work on DOM objects and to make things easier I&#8217;m working on template engine that uses syntax very similar to what you&#8217;ve proposed above</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Vinyanov</title>
		<link>http://www.stifflog.com/2007/06/10/html-generation-in-javascript/#comment-2438</link>
		<author>Vinyanov</author>
		<pubDate>Fri, 24 Aug 2007 08:45:43 +0000</pubDate>
		<guid>http://www.stifflog.com/2007/06/10/html-generation-in-javascript/#comment-2438</guid>
					<description>But your code clutters the window namespace. Some of the Riddle's examples try to represent all markup in a single structure. I also wondered what it could look like. I thought that we could exploit the case-sensitiveness of properties, so that a name-value pair with an upper-case key would represent name of the structure and its value and lower-case properties would describe attributes. You know: {TITLE : 'Contents', title : 'Attribute'}. Values may contain arrays of other values, objects, strings, whatever. It doesn't seem that wrong, I guess:

{TABLE:{TR:{TD:[
        {H1     : 'Title'},
        {H2     : 'Subtitle'},
        {DIV    : [     {P: ['One', {STRONG: 'and a half'}]},
                        {P: 'Two'}, 'Three', 4
                ],
                'id'    : 'content',
                'class' : 'content',
                'style' : {
                        padding : 10,
                        border  : 'solid 30px red',
                        margin  : 0.2
                }
        }
        ]
}}}

Single toHTML implemented in the Object prototype would then suffice to generate all code. By the way, if you have any properties heteronymous with JavaScript keywords, you can enclose them with string delimiters and use them safely in object literals: {'for' : 'example'} :)

And style attribute represented through an object would be a nice extra. Integers could represent pixels, floats - percents etc. Oh no, wait, JavaScript doesn't see the difference, does it?</description>
		<content:encoded><![CDATA[<p>But your code clutters the window namespace. Some of the Riddle&#8217;s examples try to represent all markup in a single structure. I also wondered what it could look like. I thought that we could exploit the case-sensitiveness of properties, so that a name-value pair with an upper-case key would represent name of the structure and its value and lower-case properties would describe attributes. You know: {TITLE : &#8216;Contents&#8217;, title : &#8216;Attribute&#8217;}. Values may contain arrays of other values, objects, strings, whatever. It doesn&#8217;t seem that wrong, I guess:</p>
<p>{TABLE:{TR:{TD:[<br />
        {H1     : &#8216;Title&#8217;},<br />
        {H2     : &#8216;Subtitle&#8217;},<br />
        {DIV    : [     {P: [&#8217;One&#8217;, {STRONG: &#8216;and a half&#8217;}]},<br />
                        {P: &#8216;Two&#8217;}, &#8216;Three&#8217;, 4<br />
                ],<br />
                &#8216;id&#8217;    : &#8216;content&#8217;,<br />
                &#8216;class&#8217; : &#8216;content&#8217;,<br />
                &#8217;style&#8217; : {<br />
                        padding : 10,<br />
                        border  : &#8217;solid 30px red&#8217;,<br />
                        margin  : 0.2<br />
                }<br />
        }<br />
        ]<br />
}}}</p>
<p>Single toHTML implemented in the Object prototype would then suffice to generate all code. By the way, if you have any properties heteronymous with JavaScript keywords, you can enclose them with string delimiters and use them safely in object literals: {&#8217;for&#8217; : &#8216;example&#8217;} :)</p>
<p>And style attribute represented through an object would be a nice extra. Integers could represent pixels, floats - percents etc. Oh no, wait, JavaScript doesn&#8217;t see the difference, does it?</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: stiff</title>
		<link>http://www.stifflog.com/2007/06/10/html-generation-in-javascript/#comment-2443</link>
		<author>stiff</author>
		<pubDate>Sat, 25 Aug 2007 07:41:02 +0000</pubDate>
		<guid>http://www.stifflog.com/2007/06/10/html-generation-in-javascript/#comment-2443</guid>
					<description>Yes, I had some remorse about cluttering the global namespace, but I didn't found a better way to implement things  with a syntax I would like, and the whole idea was to make it s-expish ala Lisp, which implies using functions. This is also the reason I used the "$" prefix, to avoid any name clashes, because I don't use it in normal code, nor my libraries do.

One thing I found really lacking in this solution is the inability to manipulate the template after it was created. Things get messy when there is some more complicated logic behind setting up various parts of the template.</description>
		<content:encoded><![CDATA[<p>Yes, I had some remorse about cluttering the global namespace, but I didn&#8217;t found a better way to implement things  with a syntax I would like, and the whole idea was to make it s-expish ala Lisp, which implies using functions. This is also the reason I used the &#8220;$&#8221; prefix, to avoid any name clashes, because I don&#8217;t use it in normal code, nor my libraries do.</p>
<p>One thing I found really lacking in this solution is the inability to manipulate the template after it was created. Things get messy when there is some more complicated logic behind setting up various parts of the template.</p>
]]></content:encoded>
				</item>
</channel>
</rss>
