Skip to content

Commit

Permalink
Perf optimizations and improvements to compiled templates. New perf c…
Browse files Browse the repository at this point in the history
…omparison

test page.
  • Loading branch information
BorisMoore committed Sep 20, 2011
1 parent 0a81255 commit cd6c191
Show file tree
Hide file tree
Showing 8 changed files with 865 additions and 156 deletions.
2 changes: 1 addition & 1 deletion demos/index-codeless.html
Expand Up @@ -21,6 +21,6 @@ <h2>Step by Step Examples - Codeless syntax (jsrender-codeless.js)</h2>
<div class="subhead">Other versions</div>
<a href="index.html">jQuery plugin version: jquery.render.js</a><br />
<a href="index-nojquery.html">Non-jQuery version: jsrender.js</a><br />

<a href="../test/perf-compare.html">Perf comparison</a><br />
</body>
</html>
2 changes: 1 addition & 1 deletion demos/step-by-step-codeless/1_inserting-data.html
Expand Up @@ -12,7 +12,7 @@ <h3>Render template against local data</h3>

<script id="movieTemplate" type="text/x-jquery-tmpl">
<li>
<b>{{=Name}}</b> ({{=ReleaseYear}})
{{=$itemNumber!}}: <b>{{=Name!}}</b> ({{=ReleaseYear!}})
</li>
</script>

Expand Down
11 changes: 4 additions & 7 deletions demos/step-by-step-codeless/6_paths.html
Expand Up @@ -11,22 +11,22 @@
<h3>Accessing paths</h3>
<script id="peopleTemplate" type="text/x-jquery-tmpl">

{{add $view.index "1"}}: {{=firstName}} {{=lastName}}:
{{=$itemNumber!}}: {{=firstName!}} {{=lastName!}}:

<br/>
{{each address "#addressTemplate"}}

{{#if phones cells}}
<div>
Phones:
{{#each phones cells}} <b>{{=$data}}</b> ({{=$view.parent.parent.data.firstName}}'s){{#notLast}}, {{/notLast}} {{/each}}
{{#each phones cells}} <b>{{=$data!}}</b> ({{=$view.parent.parent.data.firstName!}}'s){{#notLast}}, {{/notLast}} {{/each}}
</div>
{{/if}}
<br/>

<i>
{{#if address.street}}
{{=firstName}} lives in {{=address.street}}.
{{=firstName!}} lives in {{=address.street!}}.
{{else}}
No street address...
{{/if}}
Expand All @@ -37,7 +37,7 @@ <h3>Accessing paths</h3>

<script id="addressTemplate" type="text/x-jquery-tmpl">
<div>
{{=street}} {{=city}}
{{=street!}} {{=city!}}
</div>
</script>

Expand Down Expand Up @@ -77,9 +77,6 @@ <h3>Accessing paths</h3>
notLast: function( content ) {
var array = this.parent.data;
return array[ array.length - 1 ] === this.data ? "" : content( this );
},
add: function( val1, val2 ) {
return +val1 + +val2;
}
});

Expand Down
27 changes: 18 additions & 9 deletions demos/step-by-step-codeless/7_nested-tags.html
Expand Up @@ -14,11 +14,11 @@ <h3>Nesting of tags, to pass computed parameters</h3>

<script id="movieTemplate" type="text/x-jquery-tmpl">
<tr>
<td>{{=Title}}</td>
<td>{{=Title!}}</td>
<td><b>Languages:</b>
<em>
{{#each Languages}}
{{upper Name}}{{#nextToLast}} and{{else {{notLast}} }}, {{/nextToLast}}
{{format Name "upper"!}}{{#nextToLast}} and {{else {{notLast}} }}, {{/nextToLast}}
{{/each}}
</em><br/><br/>
</td>
Expand All @@ -32,28 +32,37 @@ <h3>Nesting of tags, to pass computed parameters</h3>
<script type="text/javascript">

$.registerTags({
upper: function( val ){
return val.toUpperCase();
format: function( val, format, content, params, encoding ){
var ret;
switch( format ) {
case "upper":
ret = val.toUpperCase();
break;
case "lower":
ret = val.toLowerCase();
break;
}
return $.tmplEncode[ encoding || "html" ]( ret );
},
nextToLast: function( content ) {
if ( this.index === this.parent.data.length - 2 ) {
return content( this );
if ( this.itemNumber === this.parent.data.length - 1 ) {
return $.renderTmpl( content, this.data );
}
this.onElse = function( val, content ) {
return val === "true" ? content( this ) : "";
return val === "true" ? $.renderTmpl( content, this.data ) : "";
};
return "";
},
notLast: function( content ) {
return (this.index !== this.parent.data.length - 1).toString();
return (this.itemNumber !== this.parent.data.length).toString();
}
});

var movies = [
{
Title: "Meet Joe Black",
Languages: [
{ Name: "English" },
{ Name: "English( <b>US</b>)" },
{ Name: "French" }
]
},
Expand Down

0 comments on commit cd6c191

Please sign in to comment.