Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save usctrojan/3798990 to your computer and use it in GitHub Desktop.

Select an option

Save usctrojan/3798990 to your computer and use it in GitHub Desktop.

Revisions

  1. @strathmeyer strathmeyer revised this gist Dec 16, 2011. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions handlebars.object_helpers.js
    Original 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) {
  2. @strathmeyer strathmeyer revised this gist Dec 16, 2011. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion handlebars.object_helpers.js
    Original 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 pair
    // Iterate over an object, setting 'key' and 'value' for each property in
    // the object.
    Handlebars.registerHelper("key_value", function(obj, fn) {
    var buffer = "",
    key;
  3. @strathmeyer strathmeyer revised this gist Dec 16, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion handlebars.object_helpers.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    // HELPER: #key_value
    //
    // Usage: {{#key_value}} Key: {{key}} // Value: {{value}} {{/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) {
  4. @strathmeyer strathmeyer revised this gist Dec 16, 2011. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions handlebars.object_helpers.js
    Original 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_id
    // HELPER: #each_with_key
    //
    // Usage: {{#each_with_id key="myKey"}}...{{/each}}
    // 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")
  5. @strathmeyer strathmeyer revised this gist Dec 16, 2011. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions handlebars.object_helpers.js
    Original 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}}
    //
    // 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.
    // 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 = "",
  6. @strathmeyer strathmeyer revised this gist Dec 16, 2011. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions handlebars.object_helpers.js
    Original 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 = "",
  7. @strathmeyer strathmeyer revised this gist Dec 16, 2011. 2 changed files with 42 additions and 21 deletions.
    21 changes: 0 additions & 21 deletions Handlebars.key_value.js
    Original file line number Diff line number Diff line change
    @@ -1,21 +0,0 @@
    // 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;
    });
    42 changes: 42 additions & 0 deletions handlebars.object_helpers.js
    Original 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;
    });
  8. @strathmeyer strathmeyer revised this gist Nov 16, 2011. 1 changed file with 17 additions and 7 deletions.
    24 changes: 17 additions & 7 deletions Handlebars.key_value.js
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,21 @@
    // requires jQuery for jQuery.each
    // 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 = "";
    $.each(obj, function(key, value) {
    var context = {key: key, value: value}
    buffer += fn(context);
    });
    var buffer = "",
    key;

    return buffer;
    for (key in obj) {
    if (obj.hasOwnProperty(key)) {
    buffer += fn({key: key, value: obj[key]});
    }
    }

    return buffer;
    });
  9. @strathmeyer strathmeyer revised this gist Nov 16, 2011. 1 changed file with 8 additions and 9 deletions.
    17 changes: 8 additions & 9 deletions Handlebars.key_value.js
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,11 @@
    Handlebars.registerHelper("key_value", function(obj, fn) {
    var buffer = "";
    $.each(obj, function(key, value) {
    var context = {key: key, value: value}
    buffer += fn(context);
    });

    // requires jQuery for jQuery.each

    // return the finished buffer
    return buffer;
    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;
    });
  10. @strathmeyer strathmeyer created this gist Nov 16, 2011.
    12 changes: 12 additions & 0 deletions Handlebars.key_value.js
    Original 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;

    });