<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: ERB for JavaScript</title>
	<link>http://lucumr.pocoo.org/cogitations/2007/06/14/erb-for-javascript/</link>
	<description>Armin Ronacher thinking</description>
	<pubDate>Mon, 07 Jul 2008 10:24:55 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2</generator>

	<item>
		<title>By: Charles Cooke</title>
		<link>http://lucumr.pocoo.org/cogitations/2007/06/14/erb-for-javascript/#comment-72</link>
		<author>Charles Cooke</author>
		<pubDate>Sun, 22 Jul 2007 22:58:32 +0000</pubDate>
		<guid>http://lucumr.pocoo.org/cogitations/2007/06/14/erb-for-javascript/#comment-72</guid>
		<description>Hiya, wanted this working in IE6 and found a couple things that made it work:
-the split function doesn't behave properly with regexp captures (used http://blog.stevenlevithan.com/archives/cross-browser-split to fix)
-indexing strings in IE doesn't work, so replaced all string indexes (part[0], etc.) w/ part.charAt(0)
-eval function in IE doesn't work, fix is at http://arrix.blogspot.com/2007/04/eval-bug-in-ie.html</description>
		<content:encoded><![CDATA[<p>Hiya, wanted this working in IE6 and found a couple things that made it work:<br />
-the split function doesn&#8217;t behave properly with regexp captures (used <a href="http://blog.stevenlevithan.com/archives/cross-browser-split" rel="nofollow">http://blog.stevenlevithan.com/archives/cross-browser-split</a> to fix)<br />
-indexing strings in IE doesn&#8217;t work, so replaced all string indexes (part[0], etc.) w/ part.charAt(0)<br />
-eval function in IE doesn&#8217;t work, fix is at <a href="http://arrix.blogspot.com/2007/04/eval-bug-in-ie.html" rel="nofollow">http://arrix.blogspot.com/2007/04/eval-bug-in-ie.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Edelstein</title>
		<link>http://lucumr.pocoo.org/cogitations/2007/06/14/erb-for-javascript/#comment-47</link>
		<author>David Edelstein</author>
		<pubDate>Thu, 12 Jul 2007 14:12:22 +0000</pubDate>
		<guid>http://lucumr.pocoo.org/cogitations/2007/06/14/erb-for-javascript/#comment-47</guid>
		<description>Hrm, your comment system cut off half my comment, I think that it didn't like that those &#62; &#60; in H4&#62;&#60;or (so im going to use html-entities)....Anyways, It was word for word from your example code and you caught my drift anyways.  

I'm using firefox, but maybe I should see how IE does it, but I doubt that it would work as expected either.

More interestingly though, your script does some pretty neat stuff that you didn't include in your example.  check this example template out and you'll see that it works too!

&lt;pre&gt;&#60;% this.fcn=function(){%&#62;&#60;p&#62;P function called&#60;/p&#62;&#60;%} ;%&#62;\\
    &#60;%# This is a nice little comment %&#62;\\
    &#60;p&#62;Total number of users: &#60;%= this.users.length %&#62;&#60;/p&#62;\\
    &#60;ul&#62;\\
    &#60;% each(this.users, function(user, idx) { %&#62;\\
      &#60;li&#62;#&#60;%= idx + 1 %&#62; &#60;%= escape(user) %&#62;&#60;/li&#62;\\n\\
    &#60;% }) %&#62;\\
    &#60;/ul&#62;\\
    &#60;%this.fcn();%&#62;\\
    &#60;p&#62;Last updated on: &#60;%= this.lastUpdate %&#62;\\
');&lt;/pre&gt;

I also made an iif function to include along with each and escape (can leave out the else function and this still works):

&lt;pre&gt;  function iif(cond, t_stmt, f_stmt) {
    if(cond){
	return t_stmt();
    }else if(f_stmt){
	return f_stmt();
    }
  }&lt;/pre&gt;

example:

&lt;pre&gt; &#60;% iif(true,function(){%&#62;&#60;br&#62;is true&#60;%}, function(){%&#62;&#60;br&#62;is false&#60;%}) %&#62;\\&lt;/pre&gt;

you can even use the iif function using a template function as a parameter and it works too!

very nice.

- Dave</description>
		<content:encoded><![CDATA[<p>Hrm, your comment system cut off half my comment, I think that it didn&#8217;t like that those &gt; &lt; in H4&gt;&lt;or (so im going to use html-entities)&#8230;.Anyways, It was word for word from your example code and you caught my drift anyways.  </p>
<p>I&#8217;m using firefox, but maybe I should see how IE does it, but I doubt that it would work as expected either.</p>
<p>More interestingly though, your script does some pretty neat stuff that you didn&#8217;t include in your example.  check this example template out and you&#8217;ll see that it works too!</p>
<pre>&lt;% this.fcn=function(){%&gt;&lt;p&gt;P function called&lt;/p&gt;&lt;%} ;%&gt;\
    &lt;%# This is a nice little comment %&gt;\
    &lt;p&gt;Total number of users: &lt;%= this.users.length %&gt;&lt;/p&gt;\
    &lt;ul&gt;\
    &lt;% each(this.users, function(user, idx) { %&gt;\
      &lt;li&gt;#&lt;%= idx + 1 %&gt; &lt;%= escape(user) %&gt;&lt;/li&gt;\n\
    &lt;% }) %&gt;\
    &lt;/ul&gt;\
    &lt;%this.fcn();%&gt;\
    &lt;p&gt;Last updated on: &lt;%= this.lastUpdate %&gt;\
');</pre>
<p>I also made an iif function to include along with each and escape (can leave out the else function and this still works):</p>
<pre>  function iif(cond, t_stmt, f_stmt) {
    if(cond){
	return t_stmt();
    }else if(f_stmt){
	return f_stmt();
    }
  }</pre>
<p>example:</p>
<pre> &lt;% iif(true,function(){%&gt;&lt;br&gt;is true&lt;%}, function(){%&gt;&lt;br&gt;is false&lt;%}) %&gt;\</pre>
<p>you can even use the iif function using a template function as a parameter and it works too!</p>
<p>very nice.</p>
<p>- Dave</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Armin Ronacher</title>
		<link>http://lucumr.pocoo.org/cogitations/2007/06/14/erb-for-javascript/#comment-40</link>
		<author>Armin Ronacher</author>
		<pubDate>Wed, 11 Jul 2007 22:05:18 +0000</pubDate>
		<guid>http://lucumr.pocoo.org/cogitations/2007/06/14/erb-for-javascript/#comment-40</guid>
		<description>In theory the newline replacement shouldn't be necessary. I wonder which browser you're using, probably the parser has to cope with the carriage return character too.</description>
		<content:encoded><![CDATA[<p>In theory the newline replacement shouldn&#8217;t be necessary. I wonder which browser you&#8217;re using, probably the parser has to cope with the carriage return character too.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Edelstein</title>
		<link>http://lucumr.pocoo.org/cogitations/2007/06/14/erb-for-javascript/#comment-24</link>
		<author>David Edelstein</author>
		<pubDate>Tue, 10 Jul 2007 01:36:57 +0000</pubDate>
		<guid>http://lucumr.pocoo.org/cogitations/2007/06/14/erb-for-javascript/#comment-24</guid>
		<description>Very cool bit of code.  I was fooling with it, trying to load the template text using an XMLHttpRequest, with the target document just a plain text document containing the markup, but I was having issues with preparing the template string to instantiate JSTemplate.  To make it work for me I had to prepare the responseText as follows:

&lt;pre&gt;
		var req=new XMLHttpRequest();
		req.open("GET", "sample.jst",false);
		req.send(null);
		var txt=req.responseText;
		txt=txt.replace(/[\\n\\r]/g,""); //!!!!IMPORTANT
		var template=new JSTemplate(txt);
		document.getElementById('output').innerHTML=
			template.render({
			    users:        ['H4&#62;
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Very cool bit of code.  I was fooling with it, trying to load the template text using an XMLHttpRequest, with the target document just a plain text document containing the markup, but I was having issues with preparing the template string to instantiate JSTemplate.  To make it work for me I had to prepare the responseText as follows:</p>
<pre>
		var req=new XMLHttpRequest();
		req.open("GET", "sample.jst",false);
		req.send(null);
		var txt=req.responseText;
		txt=txt.replace(/[\n\r]/g,""); //!!!!IMPORTANT
		var template=new JSTemplate(txt);
		document.getElementById('output').innerHTML=
			template.render({
			    users:        ['H4&gt;
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>
