Make each helper data uniform

Provide @key and @last value for all forms of iteration.

Fixes #910
This commit is contained in:
kpdecker
2014-11-26 08:02:55 -06:00
parent e4c874d1af
commit 3a9440f954
2 changed files with 36 additions and 19 deletions
+10
View File
@@ -173,6 +173,16 @@ describe('builtin helpers', function() {
equal(result, "GOODBYE! cruel world!", "The @last variable is used");
});
it("each object with @last", function() {
var string = "{{#each goodbyes}}{{#if @last}}{{text}}! {{/if}}{{/each}}cruel {{world}}!";
var hash = {goodbyes: {'foo': {text: "goodbye"}, bar: {text: "Goodbye"}}, world: "world"};
var template = CompilerContext.compile(string);
var result = template(hash);
equal(result, "Goodbye! cruel world!", "The @last variable is used");
});
it("each with nested @last", function() {
var string = "{{#each goodbyes}}({{#if @last}}{{text}}! {{/if}}{{#each ../goodbyes}}{{#if @last}}{{text}}!{{/if}}{{/each}}{{#if @last}} {{text}}!{{/if}}) {{/each}}cruel {{world}}!";
var hash = {goodbyes: [{text: "goodbye"}, {text: "Goodbye"}, {text: "GOODBYE"}], world: "world"};