diff options
author | Raimonds Simanovskis <raimonds.simanovskis@gmail.com> | 2011-01-23 11:55:48 +0200 |
---|---|---|
committer | Raimonds Simanovskis <raimonds.simanovskis@gmail.com> | 2011-01-23 11:55:48 +0200 |
commit | ada5a95f9ce9af348e7f0fb223aa78b4762d97d8 (patch) | |
tree | 09d8053942b94efb83e9779400707e48eb52a1b6 /lib/handlebars/base.js | |
parent | 65b421ee4d3a10cbb365c82a4c2400b8aa4053f8 (diff) | |
download | handlebars.js-ada5a95f9ce9af348e7f0fb223aa78b4762d97d8.zip handlebars.js-ada5a95f9ce9af348e7f0fb223aa78b4762d97d8.tar.gz handlebars.js-ada5a95f9ce9af348e7f0fb223aa78b4762d97d8.tar.bz2 |
improved "with" and "each" helpers to support function as argument
Diffstat (limited to 'lib/handlebars/base.js')
-rw-r--r-- | lib/handlebars/base.js | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/handlebars/base.js b/lib/handlebars/base.js index 7d6c1ce..776ba50 100644 --- a/lib/handlebars/base.js +++ b/lib/handlebars/base.js @@ -72,7 +72,8 @@ Handlebars.registerHelper('blockHelperMissing', function(context, fn, inverse) { return fn(context); }); -Handlebars.registerHelper('each', function(context, fn, inverse) { +Handlebars.registerHelper('each', function(ctx, fn, inverse) { + var context = typeof ctx == "function" ? ctx.call(this) : ctx; var ret = ""; if(context && context.length > 0) { @@ -98,7 +99,8 @@ Handlebars.registerHelper('unless', function(context, fn, inverse) { Handlebars.helpers['if'].call(this, context, inverse, fn); }); -Handlebars.registerHelper('with', function(context, fn) { +Handlebars.registerHelper('with', function(ctx, fn) { + var context = typeof ctx == "function" ? ctx.call(this) : ctx; return fn(context); }); |