<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>once upon my code</title>
	<atom:link href="http://aefxx.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://aefxx.com</link>
	<description></description>
	<lastBuildDate>Thu, 19 Jan 2012 18:40:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>jQote2 &#8211; Javascript templating revamped</title>
		<link>http://aefxx.com/jquery-plugins/jqote2/</link>
		<comments>http://aefxx.com/jquery-plugins/jqote2/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 21:39:16 +0000</pubDate>
		<dc:creator>aefxx</dc:creator>
				<category><![CDATA[jQuery plugins]]></category>

		<guid isPermaLink="false">http://aefxx.com/?p=272</guid>
		<description><![CDATA[jQote2 is the second major release of jQuery&#8217;s most powerful and versatile client-side templating engine. Version 2 now incorporates a faster and more accurate parsing/conversion part that does away with its predecessor&#8217;s shortcomings in escaping quotes and multiline support.
If you haven&#8217;t used or never heard of jQote before you might want to check out this [...]]]></description>
			<content:encoded><![CDATA[<p><em>jQote2</em> is the second major release of jQuery&#8217;s most powerful and versatile client-side templating engine. Version 2 now incorporates a faster and more accurate parsing/conversion part that does away with its predecessor&#8217;s shortcomings in escaping quotes and multiline support.</p>
<p><span id="more-272"></span><span class="grey">If you haven&#8217;t used or never heard of jQote before you might want to check out <a href="http://aefxx.com/jquery-plugins/jqote">this post</a> first, as it provides a quick insight into jQote&#8217;s way of client-side templating.</span></p>
<p>I&#8217;ve set up a <a href="http://github.com/aefxx/jQote2">repository over at GitHub</a>. That&#8217;s where you will find the latest releases.</p>
<p>So, what&#8217;s new for v2 you ask? Quite a lot, actually. But let&#8217;s see one by one:</p>
<p><strong>1.  jQote2 breaks compatibility with its predecessor</strong></p>
<p>- <em>jQote2 now returns a flat string representation of the converted template whereas its predecessor would give you a jQuery object.</em></p>
<p>The reason behind this substantial change is mainly speed. Appending the converted string as a whole cuts back greatly on the time it takes to generate the corresponding DOM fragment. On top of that you&#8217;ll now gain full control over your template&#8217;s outcome, to whom and when you want it to be appended etc.</p>
<p><strong>2.  jQote2 improves on template handling</strong></p>
<p>- <em>jQote2 now provides an interface to precompile your templates to lambda functions.</em></p>
<p>This is probably the most exiting new feature as it lets you precompile templates during development and simply use them in production afterwards &#8211; without the need to dish out your template code to your customers.</p>
<p>- <em>jQote2 now supports on-the-fly template strings.</em></p>
<p>For quick and dirty templating jQote2 now enables you to process template strings. This will make it easy for you to realize minor templating tasks on-the-fly without added the overhead.</p>
<p><strong>3.  jQote2 is powered by a faster and more robust parsing engine</strong></p>
<p>- <em>jQote2 now offers full multiline and escaping quotes support.</em></p>
<p>The previous version had issues regarding line breaks within the scope of shorttags which are used to echo out the result of Javascript expressions. jQote2 now fully supports your way of coding style: what goes inbetween the tags (be it shorttags or standard notation) is pure Javascript and you decide how it is layed out.</p>
<p>Pure Javascript support implies proper escaping of quotes, though. And you will have to take care of that yourself. Outside the tags however the engine now correctly escapes qoutes within your markup, thus letting you concentrate on your work rather than the plugin&#8217;s internals.</p>
<p>- <em>Speed, speed and again &#8211; speed!</em></p>
<p><a href="http://www.viget.com/extend/benchmarking-javascript-templating-libraries/">Brian Landau</a> has set up a bunch of benchmarks comparing the runtime of Javascript templating libraries. jQote didn&#8217;t perform all that bad but in the end couldn&#8217;t gain the crown.</p>
<p>With the release of jQote2 though the picture has changed quite a bit: jQote2 is now on a par with <a href="http://github.com/documentcloud/underscore/">Underscore</a>, the former sole sovereign, making both the natural choice for heavy Ajax powered sites. Please note though: Since Underscore internally uses John Resig&#8217;s conversion engine it replicates its flawed multiline and escaping quotes handling, leaving you with runtime errors whenever you need to have single quotes (both escaped or unescaped) inside the Javascript parts.</p>
<p>To backup my claims I forked Brian Landau&#8217;s benchmarks and put together a single file benchmarking suite at github. To offer you some eye candy I&#8217;ve integrated the powerful <a href="http://code.google.com/p/flot/">flot plotting library</a>. Here&#8217;s an example of my findings running the benchmark 25 times with a 1000 conversions each in Firefox 3.5.7.</p>
<p><a title="jQote2 benchmarking suite" href="http://aefxx.com/wp-content/uploads/2010/03/jqote.benchmarks.png"><img style="border: 0pt none; margin: 0;" title="jqote.benchmarks" src="http://aefxx.com/wp-content/uploads/2010/03/jqote.benchmarks.png" alt="jqote2 benchmarking suite" width="480" height="212" /></a>
<p class="grey">From left to right: Srender, mustache.js, Underscore, jQote2, Tempest, nano.<br/>Less is better.  All times in ms.</p>
<p>As you see Underscore and jQote2 vastly outperform the other contestants and moreover are superior in their ability to embed pure Javascript within the templates.</p>
<p>Enough said! Try it for yourself. Due to repeated requests I have finally set up a <a href="http://github.com/aefxx/jQote2">repository over at github</a>. You may fetch the latest versions there. So long &#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://aefxx.com/jquery-plugins/jqote2/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>jQote2 API reference</title>
		<link>http://aefxx.com/api/jqote2-reference/</link>
		<comments>http://aefxx.com/api/jqote2-reference/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 21:17:13 +0000</pubDate>
		<dc:creator>aefxx</dc:creator>
				<category><![CDATA[API]]></category>

		<guid isPermaLink="false">http://aefxx.com/?p=359</guid>
		<description><![CDATA[jQote2’s internals are quite a bit different from its predecessor’s. Thus, please make sure to double-check the new API as it breaks backward compatibility!

The three biggest changes with jQote2’s API  are:

it now returns a “stringified” representation of your generated HTML  markup
it’s now possible to precompile your templates to closures (no need  to [...]]]></description>
			<content:encoded><![CDATA[<p>jQote2’s internals are quite a bit different from its predecessor’s. Thus, please make sure to double-check the new API as it breaks backward compatibility!</p>
<p><span id="more-359"></span></p>
<p>The three biggest changes with jQote2’s API  are:</p>
<ol>
<li>it now returns a “stringified” representation of your generated HTML  markup</li>
<li>it’s now possible to precompile your templates to closures (no need  to deliver template markup within  your documents anymore)</li>
<li>it now supports on-the-fly templating strings</li>
</ol>
<p>Here’s a quick overview of jQote2 ’s new interface:</p>
<ul>
<li><a href="#jqote">.jqote(data[, tag])</a></li>
<li><a href="#jqoteapp">.jqoteapp(template, data[, tag])</a></li>
<li><a href="#jqotepre">.jqotepre(template, data[, tag])</a></li>
<li><a href="#jqotesub">.jqotesub(template, data[, tag])</a></li>
</ul>
<ul>
<li style=""><a href="#$jqote">$.jqote(template, data[, tag])</a></li>
<li style=""><a href="#$jqotec">$.jqotec(template[, tag])</a></li>
<li style=""><a href="#$jqotefn">$.jqotefn(template)</a></li>
<li style=""><a href="#$jqotetag">$.jqotetag(string)</a></li>
</ul>
<p><a name="jqote"></a></p>
<h2>$(template).jqote(data[, tag]) <span class="grey small">: function</span></h2>
<p>jQote2 is able to operate on an arbitrary number of templates, each of which may process an arbitrary number of data objects, thus effectively allowing you to trigger n:m conversions with a single call.</p>
<p><a name="auxiliary"></a></p>
<p>
    Each time a template of yours is run, it is passed a couple of auxiliary variables:
</p>
<ul>
<li>
        <strong>two counting variables</strong> <code class="blue">i</code> and <code class="blue">j</code><br/>(the former iterating over the processed templates, the latter iterating over your data objects array)
    </li>
<li>
        the <strong>data objects array</strong> <code class="blue">data</code> itself
    </li>
<li>
        the current <strong>processed template’s compiled lambda</strong> <code class="blue">fn</code><br/><br />
        (which comes in handy with recursive calls)
    </li>
</ul>
<p>To not be forced to use <code class="blue">data[j]</code> to access a <strong>template’s current data object</strong>, its compiled lambda is fired in the context of the data object, so you may just as well use the <code class="blue">this</code> keyword to reference your data.</p>
<p>Additionally, during the process of conversion (the execution of the lambda, that is) you may access the by then converted output using the <code class="blue">out</code> variable. This gives you total control over the output even from within a template at any time.</p>
<p class="grey">
    By the way: all of the above is also true for any of the <code class="blue">jqoteXXX</code> convenience methods explained below.</p>
<h3>Returns</h3>
<pre class="code"><span class="blue">out</span> : string (the processed outcome)</pre>
<h3>Parameters</h3>
<pre class="code"><span class="blue">data</span> : object | array of object</pre>
<p class="grey">
    One or more objects that carry the template&#8217;s dynamic data. Each data object that&#8217;s passed in here will get merged with any of the templates you called the conversion upon.
</p>
<pre class="code"><span class="blue">tag</span> : string (optional, defaults to "%")</pre>
<p class="grey">
    You may use the optional tag parameter to specify different template tag character(s) for a single conversion. Keep in mind though that whatever char(s) <code class="blue">C</code> you opt for here will result in <code class="blue">&lt;C ... C&gt;</code>.</p>
<h3>Called upon</h3>
<pre class="code"><span class="blue">template</span> : jQuery object</pre>
<p class="grey">
    Every template within the jQuery collection will be merged with any of your data objects.
</p>
<h3>Example</h3>
<p class="grey">The infamous and obligatory “Hello World” … generated with a different start- and ending tag (the * star).</p>
<p>Note: <code class="blue">data[j]</code> is essentially the same as <code class="blue">this</code>!</p>
<pre class="code">&lt;p id="example"&gt;&lt;/p&gt;

&lt;script type="text/x-jqote-template" id="template"&gt;
    &lt;![CDATA[
    I said &lt;strong&gt;<span class="blue">&lt;*= this.greet + " " + data[j].who *&gt;</span>&lt;/strong&gt; !!!
    <span class="blue">&lt;* out = out.replace(/John/, 'World'); *&gt;</span>
    ]]&gt;
&lt;/script&gt;
</pre>
<pre class="code">&lt;script type="text/javascript"&gt;
    <span class="grey">// let's do some jQote magic</span>
    $('#example').append(
        <span class="blue">$('#template').jqote({greet: 'Hello', who: 'John'}, '*')</span>
    );
&lt;/script&gt;</pre>
<div class="result">
<p id="greet">I said <strong>Hello World</strong> !!!</p>
</div>
<p><br/><br />
<a name="jqoteapp"></a></p>
<h2>$(elem).jqoteapp(template, data[, tag]) <span class="grey small">: function</span></h2>
<p>
    This is one of three convenience methods jQote2 has to offer. It allows you to append the processed template&#8217;s outcome directly to any DOM element that is part of the jQuery object.
</p>
<h3>Returns</h3>
<pre class="code"><span class="blue">jQuery</span> : jQuery object</pre>
<p class="grey">
    The returned jQuery object keeps the method chain intact. It is the same object that you called the convenience method upon.
</p>
<h3>Parameters</h3>
<pre class="code"><span class="blue">template</span> : jQuery object | jQuery selector |
           DOM element | array of DOM element |
           lambda | array of lambda |
           template string</pre>
<p class="grey">
    This parameter can be passed as about anything you possibly could think of. It&#8217;ll work with a collection of template elements (either as jQuery object or array of DOM elements) as well as single template elements (again jQuery object or DOM element).
</p>
<p class="grey">
    Furthermore you could pass it a single or multiple (just wrap them up in an array) precompiled lambda which gets you the best performance as it will skip the compilation and execute right away.
</p>
<p class="grey">
    For quick and dirty on-the-fly templating you may also choose to supply a template string which won&#8217;t get cached but other than that behaves just as any other template.
</p>
<pre class="code"><span class="blue">data</span> : object | array of object</pre>
<pre class="code"><span class="blue">tag</span> : string (optional)</pre>
<h3>Called upon</h3>
<pre class="code"><span class="blue">elem</span> : jQuery object</pre>
<p class="grey">
    The outcome of the conversion will be appended to every single DOM element within the jQuery object.
</p>
<h3>Example</h3>
<p class="grey">The &#8220;Hello World&#8221; example from above rewritten.</p>
<pre class="code">&lt;p id="example"&gt;&lt;/p&gt;

&lt;script type="text/html" id="template"&gt;
    &lt;![CDATA[
    I said &lt;strong&gt;<span class="blue">&lt;%= this.greet + " " + this.who %&gt;</span>&lt;/strong&gt; !!!
    <span class="blue">&lt;% out = out.replace(/John/, 'World'); %&gt;</span>
    ]]&gt;
&lt;/script&gt;
</pre>
<pre class="code">&lt;script type="text/javascript"&gt;
    <span class="grey">// let's do some jQote magic</span>
    $('#example').<span class="blue">jqoteapp('#template', {greet: 'Hello', who: 'John'})</span>;
&lt;/script&gt;</pre>
<div class="result">
<p id="example">I said <strong>Hello World</strong> !!!</p>
</div>
<h3>Example</h3>
<p class="grey">
    This makes use of the on-the-fly templating support.
</p>
<pre class="code">&lt;ul id="example"&gt;&lt;/ul&gt;</pre>
<pre class="code">&lt;script type="text/javascript"&gt;
    $('#example').<span class="blue">jqoteapp(
        <span class="pink">'&lt;li><<%= this.tag %>>Styled!&lt;/<%= this.tag %>&lt;/li>'</span>,
        [ {tag: 'strong'}, {tag: 'em'} ]
    )</span>;
&lt;/script&gt;</pre>
<div class="result">
<ul id="example">
<li><strong>Styled!</strong></li>
<li><em>Styled!</em></li>
</ul>
</div>
<p><br/><br />
<a name="jqotepre"></a></p>
<h2>$(elem).jqotepre(template, data[, tag]) <span class="grey small">: function</span></h2>
<p>
    This is <code class="blue">jqoteapp</code>&#8217;s counterpart as it behaves just the same way with one major difference: it prepends the outcome rather than appends it.
</p>
<h3>Returns</h3>
<pre class="code"><span class="blue">jQuery</span> : jQuery object</pre>
<h3>Parameters</h3>
<pre class="code"><span class="blue">template</span> : jQuery object | jQuery selector |
           DOM element | array of DOM element |
           lambda | array of lambda |
           template string</pre>
<pre class="code"><span class="blue">data</span> : object | array of object</pre>
<pre class="code"><span class="blue">tag</span> : string (optional)</pre>
<h3>Called upon</h3>
<pre class="code"><span class="blue">elem</span> : jQuery object</pre>
<p><br/><br />
<a name="jqotesub"></a></p>
<h2>$(elem).jqotesub(template, data[, tag]) <span class="grey small">: function</span></h2>
<p>
    If you need to substitute an element&#8217;s &#8220;innerHTML&#8221; more than once, this function is for you. It replaces whatever resides within a DOM element with the outcome of your template&#8217;s processing.
</p>
<h3>Returns</h3>
<pre class="code"><span class="blue">jQuery</span> : jQuery object</pre>
<h3>Parameters</h3>
<pre class="code"><span class="blue">template</span> : jQuery object | jQuery selector |
           DOM element | array of DOM element |
           lambda | array of lambda |
           template string</pre>
<pre class="code"><span class="blue">data</span> : object | array of object</pre>
<pre class="code"><span class="blue">tag</span> : string (optional)</pre>
<h3>Called upon</h3>
<pre class="code"><span class="blue">elem</span> : jQuery object</pre>
<h3>Example</h3>
<p class="grey">
    Replace the target&#8217;s &#8220;innerHTML&#8221; with something more &#8220;up to date&#8221; &#8230;
</p>
<pre class="code">&lt;p id="up_to_date"&gt;&lt;/p&gt;</pre>
<pre class="code">&lt;script type="text/javascript"&gt;
    $(function() {
        var now = function() {
            return new Date().toString().replace(/ GMT.*$/, '');
        };

        $('#up_to_date').bind('uptodate', function() {
            var self = $(this);

            setTimeout(function() {
                self.<span class="blue">jqotesub(<span class="pink">'<%= this.date %>'</span>, {date: now()})</span>
                    .triggerHandler('uptodate');
            }, 1000);
        }).triggerHandler('uptodate');
    });
&lt;/script&gt;
</pre>
<div class="result">
<p id="up_to_date">
</div>
<p><script type="text/javascript">
    $(function() {var now = function() {return new Date().toString().replace(/ GMT.*$/, '');};        $('#up_to_date').bind('uptodate', function() {            var self = $(this);            setTimeout(function() {                self.jqotesub('<%= this.date %>', {date: now()})                    .triggerHandler('uptodate');            }, 1000);        }).triggerHandler('uptodate');    });
</script><br />
<br/><br />
<a name="$jqote"></a></p>
<h2>$.jqote(template, data[, tag]) <span class="grey small">: function</span></h2>
<p>
    This basically offers the same functionality as its object associated counterpart with the added possibility to have it process precompiled lambdas or on-the-fly template strings.
</p>
<h3>Returns</h3>
<pre class="code"><span class="blue">out</span> : string (the processed outcome)</pre>
<h3>Parameters</h3>
<pre class="code"><span class="blue">template</span> : jQuery object | jQuery selector |
           DOM element | array of DOM element |
           lambda | array of lambda |
           template string</pre>
<pre class="code"><span class="blue">data</span> : object | array of object</pre>
<pre class="code"><span class="blue">tag</span> : string (optional)</pre>
<h3>Example</h3>
<p class="grey">
    Calculating the famous Fibonacci sequence (using just a small n due to Javascript&#8217;s limited recursion stack).
</p>
<pre class="code">&lt;ul id="fibonacci"&gt;
    &lt;li&gt;&lt;/li&gt;
    &lt;li&gt;&lt;/li&gt;
    &lt;li&gt;&lt;/li&gt;
    &lt;li&gt;&lt;/li&gt;
    &lt;li&gt;&lt;/li&gt;
    &lt;li&gt;&lt;/li&gt;
    &lt;li&gt;&lt;/li&gt;
    &lt;li&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;script type="text/x-jqote-template" id="template"&gt;
    &lt;![CDATA[
    <span class="blue"><%= ( ( this.n == 0 ) ?
            0 : ( this.n == 1 || this.n == 2 ) ?
                1 : parseInt(<span class="pink">$.jqote(fn, {n: this.n-1})</span>) +
                        parseInt(<span class="pink">$.jqote(fn, {n: this.n-2})</span>) ) %></span>
    ]]&gt;
&lt;/script&gt;</pre>
<pre class="code">&lt;script type="text/javascript"&gt;
    $(function() {
        var lambda = <span class="pink">$.jqotec('#template')</span>;

        $('#fibonacci li').each(function(i) {
            $(this).text(<span class="blue">$.jqote(lambda, {n: i})</span>);
        });
    });
&lt;/script&gt;</pre>
<div class="result">
<ul id="fibonacci">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
<p><script type="text/x-jqote-template" id="template">
    <%= ( ( this.n == 0 ) ?
            0 : ( this.n == 1 || this.n == 2 ) ?
                1 : parseInt($.jqote(fn, {n: this.n-1})) +
                        parseInt($.jqote(fn, {n: this.n-2})) ) %>
</script><br />
<script type="text/javascript">
    $(function() {var lambda = $.jqotec($('#template'));$('#fibonacci li').each(function(i) {            $(this).text($.jqote(lambda, {n: i}));        });    });
</script><br />
<br/><br />
<a name="$jqotec"></a></p>
<h2>$.jqotec(template[, tag]) <span class="grey small">: function</span></h2>
<p>
    This is jQote2&#8217;s heart, its engine that powers the template parsing and lambda generation. It transforms a single template into a compiled function that &#8211; once processed &#8211; is cached internally to speed up successive usage.
</p>
<p>
    You may assign the returned lambda to a variable and/or pass it to any of the before mentioned functions or let jQote2 fetch it from its internal cache for you (just pass the associated DOM element in this case).
</p>
<p>
    Please note that on-the-fly template strings won&#8217;t get cached as there&#8217;s no element to associate the lambda to. Moreover, if for whatever reason you need to recompile a cached template, jQote2 makes sure to replace the cached lambda for you.
</p>
<h3>Returns</h3>
<pre class="code"><span class="blue">lambda</span> : function</pre>
<p class="grey">
    The compiled lambda is merely a Javascript function like any other. Once called and fired in the context of a data object the lambda returns a &#8220;stringified&#8221; representation of your template&#8217;s and data object&#8217;s merge. In most cases this will be an &#8220;HTML string&#8221;, though it could be anything that goes into a string (i.e. plain text or a JSON string etc.).
</p>
<p class="grey">
    The lambda&#8217;s signature is defined as: <code class="blue">?(i, j, data, fn)</code>, where <code class="blue">fn</code> is a reference to <code class="blue">?</code> (this is important when you need to have recursion within your templates).
</p>
<p class="grey">
    For an explanation of what each paramter stands for, see this <a href="#auxiliary">paragraph</a>.
</p>
<h3>Parameters</h3>
<pre class="code"><span class="blue">template</span> : jQuery object | jQuery selector |
           DOM element |
           template string</pre>
<p class="grey">
    Please note that only the very first template of a set of matched templates within a supplied jQuery object (or selected by means of a jQuery selector) is chosen for compilation.
</p>
<pre class="code"><span class="blue">tag</span> : string (optional)</pre>
<h3>Example</h3>
<p class="grey">
    See what the lambda of above&#8217;s &#8220;Hello World&#8221; example looks like once it&#8217;s been compiled.
</p>
<pre class="code">&lt;pre id="lambda"&gt;&lt;/pre&gt;

&lt;script type="text/x-jqote-template" id="template"&gt;
    &lt;![CDATA[
    I said &lt;strong&gt;<span class="blue">&lt;*= this.greet + " " + this.who *&gt;</span>&lt;/strong&gt; !!!
    <span class="blue">&lt;* out = out.replace(/John/, 'World'); *&gt;</span>
    ]]&gt;
&lt;/script&gt;</pre>
<pre class="code">&lt;script type="text/javascript"&gt;
    $(function() {
        $('#lambda').text(
            <span class="blue">$.jqotec('#template', '*')</span>.toString()
        );
    });
&lt;/script&gt;</pre>
<div class="result">
<pre id="lambda"></pre>
</div>
<p><script type="text/x-jqote-template" id="tmpl">
    I said <strong><*= this.greet + " " + this.who *></strong> !!!
    <* out = out.replace(/John/, 'World'); *>
</script><script type="text/javascript">$(function() {        $('#lambda').text(            $.jqotec('#tmpl', '*').toString()        );    });</script><br />
<br/><br />
<a name="$jqotefn"></a></p>
<h2>$.jqotefn(template) <span class="grey small">: function</span></h2>
<p>
    jQote2 exposes its internal cache <code class="blue">$.jqotecache</code> and gives access to a template&#8217;s compilate by means of the its DOM element&#8217;s internal cache ID (just a plain integer starting at zero and running up). This cache ID is assigned to the template&#8217;s DOM element and may be read with <code class="blue">elem.jqote</code> or <code class="blue">$(template selector)[0].jqote</code>.
</p>
<p>
    As it is a tedious task to type in <code class="blue">$.jqotecache[$('#mytmpl')[0].jqote]</code> over and over, you may as well just use the more convenient way: <code class="blue">$.jqotefn('#mytmpl')</code> !!!
</p>
<h3>Returns</h3>
<pre class="code"><span class="blue">lambda</span> : function (or false if nonexistent)</pre>
<h3>Parameters</h3>
<pre class="code"><span class="blue">template</span> : jQuery object | jQuery selector |
           DOM element</pre>
<p><br/><br />
<a name="$jqotetag"></a></p>
<h2>$.jqotetag(string) <span class="grey small">: function</span></h2>
<p>
    Calling this function you will be able to permanently alter jQote2&#8217;s default tag char from being <code class="blue">%</code> to something more suitable to your needs.
</p>
<h3>Returns</h3>
<pre class="code"><span class="blue">void</span></pre>
<h3>Parameters</h3>
<pre class="code"><span class="blue">tag</span> : string</pre>
<p class="grey">
    You aren&#8217;t forced to have a single tag char, at all. You might just as well use some crazy ass string like <code class="blue">^^</code>. Keep in mind though, that whatever char(s) you opt for you always have to prepend/append angle brackets within your templates!</p>
]]></content:encoded>
			<wfw:commentRss>http://aefxx.com/api/jqote2-reference/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>jQote API reference</title>
		<link>http://aefxx.com/api/jqote-reference/</link>
		<comments>http://aefxx.com/api/jqote-reference/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 15:02:03 +0000</pubDate>
		<dc:creator>aefxx</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[jQote]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://onceupon.com/?p=126</guid>
		<description><![CDATA[PLEASE NOTE:
jQote2 has been released. Please consider upgrading now!!! Click here for a quick summary of what&#8217;s new and what&#8217;s changed.
jQote allows you to operate on a single template as well as a collection of templates. Any template you call jQote upon will get converted using the data object you provide.
Note: Since objects are passed [...]]]></description>
			<content:encoded><![CDATA[<h3 class="pink">PLEASE NOTE:</h3>
<p class="pink"><strong>jQote2</strong> has been released. Please consider upgrading now!!! <a href="http://aefxx.com/jquery-plugins/jqote2/">Click here</a> for a quick summary of what&#8217;s new and what&#8217;s changed.</p>
<p>jQote allows you to operate on a single template as well as a collection of templates. Any template you call jQote upon will get converted using the data object you provide.</p>
<p><span id="more-126"></span>Note: Since objects are passed by reference you may easily alter the data object inside a template and have these changes carried over to the next iteration.</p>
<p>To make your life easier you may just as well pass an array of data objects to jQote to have your template(s) iterate over every data object provided, thus inducing n x m conversions.</p>
<h2>$.jqote_tag(tag) <span class="grey small">: method</span></h2>
<p><span class="grey">This may be used to change the default start- and ending tag character from <code>%</code> to anything you want to. Be aware that changing the tag&#8217;s char(s) this way every successive call to jQote expects the templates to be compliant to the newly set default.</span></p>
<h3>Returns</h3>
<pre class="code">void</pre>
<h3>Parameters</h3>
<pre class="code"><span class="blue">tag</span> : String</pre>
<p></p>
<h2>$().jqote(data[, tag]) <span class="grey small">: function</span></h2>
<p><span class="grey">Inside your templates you may use the <code>this</code> keyword to reference the data object&#8217;s properties. Additionally two counting variables <code>i</code> and <code>j</code> are defined (the former iterating over your templates, the latter iterating over your data objects).</span><br />
<br />
<span class="grey">You may use the optional second paramter to temporarily specify different start- and ending tag char(s). The change will overwrite the default tag char(s) just for the single call!</span></p>
<h3>Returns</h3>
<pre class="code"><span class="blue">jQuery</span> : object</pre>
<h3>Parameters</h3>
<pre class="code"><span class="blue">data</span> : object | array of object</pre>
<pre class="code"><span class="blue">tag</span> : String (optional)</pre>
<p></p>
<h3>Example</h3>
<p class="grey" style="margin: 0; padding: 0;">The infamous and obligatory &#8220;Hello World&#8221; &#8230;</p>
<p class="grey">Notice that this temporarily uses a different start- and ending tag char (the * star)!!!</p>
<pre class="code">&lt;p id="greet">&lt;/p>

&lt;script type="text/html" id="tmpl">
    &lt;![CDATA[
    I said &lt;strong><span class="blue">&lt;*= this.what *></span>&lt;/strong> !!!
    ]]&gt;
&lt;/script>
</pre>
<pre class="code">&lt;script type="text/javascript"&gt;
    <span class="grey">// let's do some jQote magic</span>
    <span class="blue">$('#tmpl').jQuote({what: 'Hello World'}, '*')</span>.appendTo($('#greet'));
&lt;/script&gt;</pre>
<div class="result">
<p id="greet">I said <strong>Hello World</strong> !!!
</div>
<p></p>
<h3>Example</h3>
<p class="grey" style="margin: 0; padding: 0;">This example will list some names of european capitals &#8230;</p>
<pre class="code">&lt;ul id="capitals"&gt;&lt;ul&gt;

<span class="grey">&lt;!-- let's define our city template --&gt;</span>
&lt;script type="text/html" id="city_tmpl"&gt;
    &lt;![CDATA[
    &lt;li class="city"&gt;
        <span class="blue">&lt;%= this.name %&gt;
        &lt;% if ( this.info ) { %&gt;</span>
        &lt;ul class="info"&gt;
            <span class="blue">&lt;% for ( key in this.info) %&gt;</span>
            &lt;li&gt;<span class="blue">&lt;%= key + ': ' +  this.info[key] %&gt;</span>&lt;/li&gt;
            <span class="blue">&lt;% ; %&gt;</span>
        &lt;/ul&gt;
        <span class="blue">&lt;% } %&gt;</span>
    &lt;/li&gt;
    ]]&gt;
&lt;/script&gt;</pre>
<pre class="code">&lt;script type="text/javascript"&gt;
    var cities = [{
        name: 'Paris',
        info: { language: 'french', sight: 'tour Eiffel' }
    }, {
        name: 'Berlin',
        info: { language: 'german', sight: 'Brandenburger Tor' }
    }];

    <span class="grey">// let's do some jQote magic</span>
    <span class="blue">$('#city_tmpl').jQuote(cities)</span>.appendTo($('#capitals'));
&lt;/script&gt;</pre>
<div class="result">
<ul>
<li>Paris
<ul>
<li>language: french</li>
<li>sight: tour Eiffel</li>
</ul>
</li>
<li>Berlin
<ul>
<li>language: german</li>
<li>sight: Brandenburger Tor</li>
</ul>
</li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://aefxx.com/api/jqote-reference/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>jQote &#8211; client-side templating</title>
		<link>http://aefxx.com/jquery-plugins/jqote/</link>
		<comments>http://aefxx.com/jquery-plugins/jqote/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 17:52:10 +0000</pubDate>
		<dc:creator>aefxx</dc:creator>
				<category><![CDATA[jQuery plugins]]></category>
		<category><![CDATA[jQote]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://onceupon.com/?p=47</guid>
		<description><![CDATA[PLEASE NOTE:
jQote2 has been released. Please consider upgrading now!!! Click here for a quick summary of what&#8217;s new and what&#8217;s changed.
jQote (pronounced like Star Trek&#8217;s Chakotey) is basically a rewrite of John Resig&#8217;s awesome JavaScript Micro-Templating utility. I took his code and ported it to jQuery, overhauled the parsing / conversion part and extended it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<h3 class="pink">PLEASE NOTE:</h3>
<p class="pink"><strong>jQote2</strong> has been released. Please consider upgrading now!!! <a href="http://aefxx.com/jquery-plugins/jqote2/">Click here</a> for a quick summary of what&#8217;s new and what&#8217;s changed.</p>
<p>jQote (pronounced like Star Trek&#8217;s Chakotey) is basically a rewrite of <strong>John Resig&#8217;s</strong> awesome <a href="http://ejohn.org/blog/javascript-micro-templating/">JavaScript Micro-Templating</a> utility. I took his code and ported it to <a href="http://www.jquery.com/">jQuery</a>, overhauled the parsing / conversion part and extended it&#8217;s functionality to minimize everyone&#8217;s coding efforts.</p>
<p><span id="more-47"></span></p>
<p>See the <a href="api/jqote-reference/">jQote API reference</a>.</p>
<p><strong>PLEASE NOTE:</strong><br />
Version 1.1.0 now gives you the <strong>possibility of changing the tag character</strong> to something else than <% and %>. Please referr to the <a href="api/jqote-reference/">jQote API reference</a> to see how to do it.</p>
<p>So, let&#8217;s get started writing down a basic template:</p>
<pre class="code"><span class="blue">&lt;script type="text/html" id="template">
&lt;![CDATA[</span>
    &lt;p class="greetings"&gt;
        Hello <span class="pink">&lt;%= this.name %&gt;</span>, how are you doing?
        May I offer you
        <span class="pink">&lt;% this.is_starving() ? %&gt;</span>
            some tasty peasant?
        <span class="pink">&lt;% : %&gt;</span>
            a refreshing Singha?
        <span class="pink">&lt;% ; %&gt;</span>
    &lt;/p&gt;
<span class="blue">]]&gt;
&lt;/script></span></pre>
<p></p>
<p>This well-mannered code snippet &#8211; though it may not seem like much &#8211; shows some very special markup, namely <code class="pink">&lt;%= expression %></code> and <code class="pink">&lt;% statement %></code>, respectively (please notice the extra &#8216;=&#8217; sign on the first one).</p>
<p>As you may have guessed already, the code in-between these tags is mere JavaScript. To simplify things you should use the <code class="pink"><%= %></code> tag whenever you want to directly echo a variable&#8217;s value (you may as well call a function or use any other expression, as long as it returns a string).</p>
<p>Pretty self-explanatory so far, hu? But what&#8217;s with all that <code class="blue">&lt;script type="text/html"></code> and <code class="blue">&lt;![CDATA[ ... ]]&gt;</code> shmoo, you ask? Well let&#8217;s cite <strong>John Resig</strong> here:<br />
<cite>&#8220;Embedding scripts in your page that have a unknown content-type (such is the case here &#8211; the browser doesn&#8217;t know how to execute a text/html script) are simply ignored by the browser &#8211; and by search engines and screenreaders. It&#8217;s a perfect cloaking device for sneaking templates into your page. [...]&#8220;</cite></p>
<p>Good news, that is we will be able to put our template code right into our HMTL source files and it won&#8217;t show up anywhere but in the sources (btw. thanks to the usage of CDATA it&#8217;s perfectly valid markup).</p>
<p>Now for the final part of our little example we&#8217;ll need some basic scripting to induce the conversion:</p>
<pre class="code">
&lt;script type="text/javascript">
    var obj= {
        name: 'Jabberwocky',
        is_starving: function() {
            return Math.random() > 0.5;
        }
    };
    <span class="pink">$('#template').jqote(obj)</span>.appendTo($('body'));
&lt;/script></pre>
<p></p>
<p>That&#8217;s it, there&#8217;s nothing more to it than calling jQote on our template and providing it with some data object to get things started. jQote really is fun to use and cuts down on the time spent trying to inject arbitrary data into your sites. You&#8217;ll learn to love it pretty fast, I promise! Give it a try.</p>
<p>One final word: I&#8217;d like to thank <strong>John Resig</strong> for bringing this up. You rock, dude.</p>
]]></content:encoded>
			<wfw:commentRss>http://aefxx.com/jquery-plugins/jqote/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
	</channel>
</rss>
