Forked from strathmeyer/handlebars.object_helpers.js
Created
September 28, 2012 10:06
-
-
Save usctrojan/3798990 to your computer and use it in GitHub Desktop.
Revisions
-
strathmeyer revised this gist
Dec 16, 2011 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,6 +27,7 @@ Handlebars.registerHelper("key_value", function(obj, fn) { Handlebars.registerHelper("each_with_key", function(obj, fn) { var context, buffer = "", key, keyName = fn.hash.key; for (key in obj) { -
strathmeyer revised this gist
Dec 16, 2011 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,8 @@ // // Usage: {{#key_value obj}} Key: {{key}} // Value: {{value}} {{/key_value}} // // Iterate over an object, setting 'key' and 'value' for each property in // the object. Handlebars.registerHelper("key_value", function(obj, fn) { var buffer = "", key; -
strathmeyer revised this gist
Dec 16, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ // HELPER: #key_value // // Usage: {{#key_value obj}} Key: {{key}} // Value: {{value}} {{/key_value}} // // Iterate over an object, setting 'key' and 'value' for each pair Handlebars.registerHelper("key_value", function(obj, fn) { -
strathmeyer revised this gist
Dec 16, 2011 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,9 +16,9 @@ Handlebars.registerHelper("key_value", function(obj, fn) { return buffer; }); // HELPER: #each_with_key // // Usage: {{#each_with_key container key="myKey"}}...{{/each_with_key}} // // Iterate over an object containing other objects. Each // inner object will be used in turn, with an added key ("myKey") -
strathmeyer revised this gist
Dec 16, 2011 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,9 +20,9 @@ Handlebars.registerHelper("key_value", function(obj, fn) { // // Usage: {{#each_with_id key="myKey"}}...{{/each}} // // Iterate over an object containing other objects. Each // inner object will be used in turn, with an added key ("myKey") // set to the value of the inner object's key in the container. Handlebars.registerHelper("each_with_key", function(obj, fn) { var context, buffer = "", -
strathmeyer revised this gist
Dec 16, 2011 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,7 @@ // HELPER: #key_value // // Usage: {{#key_value}} Key: {{key}} // Value: {{value}} {{/key_value}} // // Iterate over an object, setting 'key' and 'value' for each pair Handlebars.registerHelper("key_value", function(obj, fn) { var buffer = "", -
strathmeyer revised this gist
Dec 16, 2011 . 2 changed files with 42 additions and 21 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,21 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ // HELPER: #key_value // // Iterate over an object, setting 'key' and 'value' for each pair Handlebars.registerHelper("key_value", function(obj, fn) { var buffer = "", key; for (key in obj) { if (obj.hasOwnProperty(key)) { buffer += fn({key: key, value: obj[key]}); } } return buffer; }); // HELPER: #each_with_id // // Usage: {{#each_with_id key="myKey"}}...{{/each}} // // Iterates over an object containing other objects. Each // inner object will be used in turn, with an added key ("myKey") set // to the value of the inner object's key in the container. Handlebars.registerHelper("each_with_key", function(obj, fn) { var context, buffer = "", keyName = fn.hash.key; for (key in obj) { if (obj.hasOwnProperty(key)) { context = obj[key]; if (keyName) { context[keyName] = key; } buffer += fn(context); } } return buffer; }); -
strathmeyer revised this gist
Nov 16, 2011 . 1 changed file with 17 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,21 @@ // Iterate through an object, passing each as 'key' and 'value' // // Usage: // var t = Handlebars.compile('<ul>{{#key_value foo}}<li>{{key}}: {{value}}</li>{{/key_value}}</ul>'); // t({foo: {a:1, b:2}}) // // Output: // "<ul><li>a: 1</li><li>b: 2</li></ul>" Handlebars.registerHelper("key_value", function(obj, fn) { var buffer = "", key; for (key in obj) { if (obj.hasOwnProperty(key)) { buffer += fn({key: key, value: obj[key]}); } } return buffer; }); -
strathmeyer revised this gist
Nov 16, 2011 . 1 changed file with 8 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,11 @@ // requires jQuery for jQuery.each Handlebars.registerHelper("key_value", function(obj, fn) { var buffer = ""; $.each(obj, function(key, value) { var context = {key: key, value: value} buffer += fn(context); }); return buffer; }); -
strathmeyer created this gist
Nov 16, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ Handlebars.registerHelper("key_value", function(obj, fn) { var buffer = ""; $.each(obj, function(key, value) { var context = {key: key, value: value} buffer += fn(context); }); // return the finished buffer return buffer; });