diff options
author | kpdecker <kpdecker@gmail.com> | 2014-01-17 20:13:00 -0600 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2014-01-17 20:13:00 -0600 |
commit | fe4880feaabb6107e39e9af6d4d0f68ff3736653 (patch) | |
tree | 18dcbdb0adb5fda8d03c6ba786abeefe326aa157 | |
parent | 363cb4b0fb56ad98d19c94b0da797cc52fbbfafd (diff) | |
download | handlebars.js-fe4880feaabb6107e39e9af6d4d0f68ff3736653.zip handlebars.js-fe4880feaabb6107e39e9af6d4d0f68ff3736653.tar.gz handlebars.js-fe4880feaabb6107e39e9af6d4d0f68ff3736653.tar.bz2 |
Allow implicit context iteration with each
Fixes #671
-rw-r--r-- | lib/handlebars/base.js | 6 | ||||
-rw-r--r-- | spec/builtins.js | 5 |
2 files changed, 11 insertions, 0 deletions
diff --git a/lib/handlebars/base.js b/lib/handlebars/base.js index ff9736c..790228c 100644 --- a/lib/handlebars/base.js +++ b/lib/handlebars/base.js @@ -80,6 +80,12 @@ function registerDefaultHelpers(instance) { }); instance.registerHelper('each', function(context, options) { + // Allow for {{#each}} + if (!options) { + options = context; + context = this; + } + var fn = options.fn, inverse = options.inverse; var i = 0, ret = "", data; diff --git a/spec/builtins.js b/spec/builtins.js index 766541a..6d9fa0b 100644 --- a/spec/builtins.js +++ b/spec/builtins.js @@ -181,6 +181,11 @@ describe('builtin helpers', function() { equal(result, 'a!b!c!', 'should output data'); }); + it("each on implicit context", function() { + var string = "{{#each}}{{text}}! {{/each}}cruel world!"; + var hash = [{text: "goodbye"}, {text: "Goodbye"}, {text: "GOODBYE"}]; + shouldCompileTo(string, [hash], "goodbye! Goodbye! GOODBYE! cruel world!"); + }); }); it("#log", function() { |