Skip to content

Commit

Permalink
Provide clear throw on {{#each}}
Browse files Browse the repository at this point in the history
Fixes #773
  • Loading branch information
kpdecker committed May 27, 2014
1 parent 3cdf14d commit 7172d16
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 1 addition & 3 deletions lib/handlebars/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,8 @@ function registerDefaultHelpers(instance) {
});

instance.registerHelper('each', function(context, options) {
// Allow for {{#each}}
if (!options) {
options = context;
context = this;
throw new Exception('Must pass iterator to #each');
}

var fn = options.fn, inverse = options.inverse;
Expand Down
9 changes: 5 additions & 4 deletions spec/builtins.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*global CompilerContext, shouldCompileTo, compileWithPartials, handlebarsEnv */
/*global CompilerContext, shouldCompileTo, shouldThrow, compileWithPartials, handlebarsEnv */
describe('builtin helpers', function() {
describe('#if', function() {
it("if", function() {
Expand Down Expand Up @@ -182,9 +182,10 @@ describe('builtin helpers', function() {
});

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!");
shouldThrow(function() {
var template = CompilerContext.compile("{{#each}}{{text}}! {{/each}}cruel world!");
template({});
}, handlebarsEnv.Exception, 'Must pass iterator to #each');
});
});

Expand Down

0 comments on commit 7172d16

Please sign in to comment.