summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2013-05-30 15:46:00 -0400
committerkpdecker <kpdecker@gmail.com>2013-05-30 15:47:30 -0400
commitd7b345b2da5436cd3199d9b9fcf51f0af49da77c (patch)
tree46e38000c1556eb4d3394f6685837e4f43f8af32
parent17659b972070ee081987c410f1dbbf569a41f2e1 (diff)
downloadhandlebars.js-d7b345b2da5436cd3199d9b9fcf51f0af49da77c.zip
handlebars.js-d7b345b2da5436cd3199d9b9fcf51f0af49da77c.tar.gz
handlebars.js-d7b345b2da5436cd3199d9b9fcf51f0af49da77c.tar.bz2
Allow execution of helpers on the context
Fixes #285
-rw-r--r--dist/handlebars.js3
-rw-r--r--lib/handlebars/compiler/compiler.js3
-rw-r--r--spec/qunit_spec.js8
3 files changed, 12 insertions, 2 deletions
diff --git a/dist/handlebars.js b/dist/handlebars.js
index a5f0bf7..418b804 100644
--- a/dist/handlebars.js
+++ b/dist/handlebars.js
@@ -1743,8 +1743,9 @@ JavaScriptCompiler.prototype = {
this.context.aliases.helperMissing = 'helpers.helperMissing';
var helper = this.lastHelper = this.setupHelper(paramSize, name, true);
+ var nonHelper = this.nameLookup('depth' + this.lastContext, name, 'context');
- this.push(helper.name);
+ this.push(helper.name + ' || ' + nonHelper);
this.replaceStack(function(name) {
return name + ' ? ' + name + '.call(' +
helper.callParams + ") " + ": helperMissing.call(" +
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js
index 7777456..c003ce6 100644
--- a/lib/handlebars/compiler/compiler.js
+++ b/lib/handlebars/compiler/compiler.js
@@ -866,8 +866,9 @@ JavaScriptCompiler.prototype = {
this.context.aliases.helperMissing = 'helpers.helperMissing';
var helper = this.lastHelper = this.setupHelper(paramSize, name, true);
+ var nonHelper = this.nameLookup('depth' + this.lastContext, name, 'context');
- this.push(helper.name);
+ this.push(helper.name + ' || ' + nonHelper);
this.replaceStack(function(name) {
return name + ' ? ' + name + '.call(' +
helper.callParams + ") " + ": helperMissing.call(" +
diff --git a/spec/qunit_spec.js b/spec/qunit_spec.js
index 317841f..14dbee7 100644
--- a/spec/qunit_spec.js
+++ b/spec/qunit_spec.js
@@ -165,6 +165,14 @@ test("functions", function() {
"functions are bound to the context");
});
+test("functions with context argument", function() {
+ shouldCompileTo("{{awesome frank}}",
+ {awesome: function(context) { return context; },
+ frank: "Frank"},
+ "Frank", "functions are called with context arguments");
+});
+
+
test("paths with hyphens", function() {
shouldCompileTo("{{foo-bar}}", {"foo-bar": "baz"}, "baz", "Paths can contain hyphens (-)");
shouldCompileTo("{{foo.foo-bar}}", {foo: {"foo-bar": "baz"}}, "baz", "Paths can contain hyphens (-)");