Skip to content

Instantly share code, notes, and snippets.

@jordantomax
Last active December 16, 2015 13:18
Show Gist options
  • Save jordantomax/5440241 to your computer and use it in GitHub Desktop.
Save jordantomax/5440241 to your computer and use it in GitHub Desktop.

Revisions

  1. jordantomax revised this gist Apr 23, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Handlebars foreach helper
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ Handlebars.registerHelper("foreach",function(arr,options) {
    }

    return arr.map(function(item,index) {
    if (typeof item == 'string') {
    if (typeof item === 'string') {
    var item = new String(item);
    }

  2. jordantomax revised this gist Apr 23, 2013. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions Handlebars foreach helper
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,16 @@
    Handlebars.registerHelper("foreach",function(arr,options) {
    if (options.inverse && !arr.length) {
    return options.inverse(this);
    return options.inverse(this);
    }

    return arr.map(function(item,index) {
    return arr.map(function(item,index) {
    if (typeof item == 'string') {
    var item = new String(item);
    }

    item.$index = index;
    item.$first = index === 0;
    item.$last = index === arr.length-1;
    return options.fn(item);
    }).join('');
    item.$index = index;
    item.$first = index === 0;
    item.$last = index === arr.length-1;
    return options.fn(item);
    }).join('');
    });
  3. jordantomax revised this gist Apr 23, 2013. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions Handlebars foreach helper
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,12 @@
    Handlebars.registerHelper("foreach",function(arr,options) {
    if(options.inverse && !arr.length)
    if (options.inverse && !arr.length) {
    return options.inverse(this);
    }

    return arr.map(function(item,index) {
    if (typeof item == 'string') {
    var item = new String(item)
    }
    if (typeof item == 'string') {
    var item = new String(item);
    }

    item.$index = index;
    item.$first = index === 0;
  4. jordantomax revised this gist Apr 23, 2013. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions Handlebars foreach helper
    Original file line number Diff line number Diff line change
    @@ -3,9 +3,9 @@ Handlebars.registerHelper("foreach",function(arr,options) {
    return options.inverse(this);

    return arr.map(function(item,index) {
    if (typeof item == 'string') {
    var item = new String(item)
    }
    if (typeof item == 'string') {
    var item = new String(item)
    }

    item.$index = index;
    item.$first = index === 0;
  5. jordantomax created this gist Apr 23, 2013.
    15 changes: 15 additions & 0 deletions Handlebars foreach helper
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    Handlebars.registerHelper("foreach",function(arr,options) {
    if(options.inverse && !arr.length)
    return options.inverse(this);

    return arr.map(function(item,index) {
    if (typeof item == 'string') {
    var item = new String(item)
    }

    item.$index = index;
    item.$first = index === 0;
    item.$last = index === arr.length-1;
    return options.fn(item);
    }).join('');
    });