diff --git a/demos/resources/demos.css b/demos/resources/demos.css index 2492570..abdda77 100644 --- a/demos/resources/demos.css +++ b/demos/resources/demos.css @@ -5,3 +5,4 @@ h4 { font-size: inherit`; font-variant: small-caps; } body > button { float: left; clear: right; margin: 3px } .subhead { margin: 15px 0 4px 0; font-weight:bolder; color:#116; font-family:Arial; font-size:10pt } a { color: #55b} +pre { font-size:10pt; font-weight:bold; } \ No newline at end of file diff --git a/demos/resources/movielist.css b/demos/resources/movielist.css index 0e0543c..03ed5c0 100644 --- a/demos/resources/movielist.css +++ b/demos/resources/movielist.css @@ -3,5 +3,5 @@ table tr { color: blue; height: 25px; } .header { color: #009; border-bottom: solid #77c 2px; background-color: #E8E8F7; } .header th { padding:5px; border: 1px solid #77c; } #movieList tr td:first-child { width: 130px; } -table { border: 2px solid blue; width: 480px; margin: 4px 0 4px 4px; padding: 2px; background-color: #f8f8f8; } +table { border: 2px solid blue; width: 480px; margin: 4px 0 24px 4px; padding: 2px; background-color: #f8f8f8; } table td { padding: 3px; margin: 3px; border: solid #77c 1px; } diff --git a/demos/step-by-step/07_paths.html b/demos/step-by-step/07_paths.html index 58bae55..883083c 100644 --- a/demos/step-by-step/07_paths.html +++ b/demos/step-by-step/07_paths.html @@ -20,7 +20,7 @@

Accessing paths

{{#if phones cells}}
Phones: - {{#each phones cells}} {{=$data!}} ({{=$view.parent.parent.data.firstName!}}'s){{#notLast}}, {{/notLast}} {{/each}} + {{#each phones cells}} {{=$data!}} ({{=$view.parent.parent.data.firstName!}}'s){{/each}}
{{/if}}
diff --git a/demos/step-by-step/10_named-params.html b/demos/step-by-step/08_custom-tags.html similarity index 75% rename from demos/step-by-step/10_named-params.html rename to demos/step-by-step/08_custom-tags.html index 19fb9e9..0b4d1ea 100644 --- a/demos/step-by-step/10_named-params.html +++ b/demos/step-by-step/08_custom-tags.html @@ -10,7 +10,29 @@ Home
-

Providing a named parameter to a custom tag: {{sort array reverse=true}}

+

Providing a custom tag

+ +
+{{#sort Languages reverse="true"}}
+
+$.views.registerTags({
+
+    sort: function( array, hash, content ){
+        var ret = "";
+        if ( hash.reverse === "true" ) {
+            // Render in reverse order
+            for ( var l = array.length, i = l; i; i-- ) {
+                ret += $.render( content, array[ i - 1 ]);
+            }
+        } else {
+            // Render in original order
+            ret += $.render( content, array );
+        }
+        return ret;
+    }
+
+});
+
+ + + + + + + +Home
+ +

Registering 'helper' tags.

+ +
+$.views.registerTags({
+
+    get: function( value, hash ){
+        return value  || hash[ "default" ];
+    },
+
+    yesNo: function( value, hash ){
+        return value ? hash.yes : hash.no;
+    }
+
+});
+
+ + + + + + + + + +
Title{{=path}}
+ + + +
Title{{get path default="..."}}
+ + + +
Title{{yesNo path yes="..." no="..."}}
+ + + + + diff --git a/demos/step-by-step/08_nested-tags.html b/demos/step-by-step/10_chained-tags.html similarity index 53% rename from demos/step-by-step/08_nested-tags.html rename to demos/step-by-step/10_chained-tags.html index 66e751b..5ef40a3 100644 --- a/demos/step-by-step/08_nested-tags.html +++ b/demos/step-by-step/10_chained-tags.html @@ -12,26 +12,74 @@

Nesting of tags, to pass computed parameters

- + +
+{{#if {{not Languages}} }}...{{/if}}
+
+$.views.registerTags({
+    not: function( value ){
+        return !value;
+    }
+});
+
+ + + +
TitleLanguages
+ + + +
+{{#nextToLast}}
+	and 
+{{else {{notLast}} }}
+	,
+{{/nextToLast}}
+
+$.views.registerTags({
+    notLast: function( content ) {
+        return this.itemNumber !== this.parent.data.length;
+    }
+});
+
+ - +
TitleLanguages
diff --git a/demos/step-by-step/09_allow-code.html b/demos/step-by-step/11_allow-code.html similarity index 100% rename from demos/step-by-step/09_allow-code.html rename to demos/step-by-step/11_allow-code.html diff --git a/demos/step-by-step/09b_allow-code.html b/demos/step-by-step/11b_allow-code.html similarity index 100% rename from demos/step-by-step/09b_allow-code.html rename to demos/step-by-step/11b_allow-code.html diff --git a/demos/step-by-step/11_without-jquery.html b/demos/step-by-step/12_without-jquery.html similarity index 100% rename from demos/step-by-step/11_without-jquery.html rename to demos/step-by-step/12_without-jquery.html diff --git a/demos/step-by-step/index.html b/demos/step-by-step/index.html index f249138..7e8e1e1 100644 --- a/demos/step-by-step/index.html +++ b/demos/step-by-step/index.html @@ -15,11 +15,12 @@

JsRender: Step by Step - (current version - "codeless" with no jQuery depend {{each}}
Template composition
Accessing paths
- Nested tags
- Allowing code - program flow
- Allowing code - returning content
- Passing named parameters to tags
- JsRender without jQuery
+ Custom tags
+ Registering 'helper' tags
+ Chained tags
+ Allowing code - program flow
+ Allowing code - returning content
+ JsRender without jQuery
Perf tests
Perf comparison
diff --git a/jsrender.js b/jsrender.js index e5d1662..ef618de 100644 --- a/jsrender.js +++ b/jsrender.js @@ -481,8 +481,8 @@ function buildTmplFunction( nodes ) { params = node[ 1 ], encoding = node[ 3 ]; if ( tag === "=" ) { - // TODO test for chainingDepth: using {{= }} at depth>0 is an error. if ( chainingDepth > 0 || params.length !== 1 ) { + // Using {{= }} at depth>0 is an error. return ""; // Could throw... } params = params[ 0 ]; @@ -515,7 +515,11 @@ function buildTmplFunction( nodes ) { nested.push( buildTmplFunction( content )); } codeFrag += '$view,"' - + encoding + '"' + + ( encoding + ? encoding + : chainingDepth + ? "string" // Default encoding for chained tags is "string" + : "" ) + '"' + (hash ? ",{ json:'{" + out[ 1 ] + "}'," + hash + "}" : "") + (content ? "," + nested.length : ""); // For block tags, pass in the key to the nested content template codeFrag += ')'; diff --git a/previous-version-of-jsrender/demos/resources/demos.css b/previous-version-of-jsrender/demos/resources/demos.css index 2492570..abdda77 100644 --- a/previous-version-of-jsrender/demos/resources/demos.css +++ b/previous-version-of-jsrender/demos/resources/demos.css @@ -5,3 +5,4 @@ h4 { font-size: inherit`; font-variant: small-caps; } body > button { float: left; clear: right; margin: 3px } .subhead { margin: 15px 0 4px 0; font-weight:bolder; color:#116; font-family:Arial; font-size:10pt } a { color: #55b} +pre { font-size:10pt; font-weight:bold; } \ No newline at end of file diff --git a/previous-version-of-jsrender/demos/resources/movielist.css b/previous-version-of-jsrender/demos/resources/movielist.css index 0e0543c..03ed5c0 100644 --- a/previous-version-of-jsrender/demos/resources/movielist.css +++ b/previous-version-of-jsrender/demos/resources/movielist.css @@ -3,5 +3,5 @@ table tr { color: blue; height: 25px; } .header { color: #009; border-bottom: solid #77c 2px; background-color: #E8E8F7; } .header th { padding:5px; border: 1px solid #77c; } #movieList tr td:first-child { width: 130px; } -table { border: 2px solid blue; width: 480px; margin: 4px 0 4px 4px; padding: 2px; background-color: #f8f8f8; } +table { border: 2px solid blue; width: 480px; margin: 4px 0 24px 4px; padding: 2px; background-color: #f8f8f8; } table td { padding: 3px; margin: 3px; border: solid #77c 1px; }