summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/runtime.js
diff options
context:
space:
mode:
authorwycats <wycats@gmail.com>2010-12-11 18:43:58 -0800
committerwycats <wycats@gmail.com>2010-12-11 18:43:58 -0800
commit9fcd85bbac33c643efa02c3a144c0a50e25d13cc (patch)
tree04706f8f3fba30cf016dfdf99d6fdd8c01d76829 /lib/handlebars/runtime.js
parent62cea5b05e4b4f60b6d27b5b0e1f1724c104702a (diff)
downloadhandlebars.js-9fcd85bbac33c643efa02c3a144c0a50e25d13cc.zip
handlebars.js-9fcd85bbac33c643efa02c3a144c0a50e25d13cc.tar.gz
handlebars.js-9fcd85bbac33c643efa02c3a144c0a50e25d13cc.tar.bz2
Allow helperMissing to apply to simple mustaches (paves the way to support things like link_to in a Rails context)
Diffstat (limited to 'lib/handlebars/runtime.js')
-rw-r--r--lib/handlebars/runtime.js21
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/handlebars/runtime.js b/lib/handlebars/runtime.js
index b58ba24..e091b99 100644
--- a/lib/handlebars/runtime.js
+++ b/lib/handlebars/runtime.js
@@ -113,11 +113,22 @@ Handlebars.Runtime.prototype = {
params[i] = this[param.type](param).data;
}
- if(toString.call(idObj.data) === "[object Function]") {
- buf = idObj.data.apply(this.wrapContext(), params);
+ var data = idObj.data;
+
+ var type = toString.call(data);
+ var functionType = (type === "[object Function]");
+
+ if(!functionType && params.length) {
+ params = params.slice(0);
+ params.unshift(data || mustache.id.original);
+ data = this.context.helpers.helperMissing;
+ functionType = true;
+ }
+
+ if(functionType) {
+ buf = data.apply(this.wrapContext(), params);
} else {
- if(params.length) { throw new Error(mustache.id.parts.join("/") + " is not a Function, so you cannot have Function parameters"); }
- buf = idObj.data;
+ buf = data;
}
if(buf && mustache.escaped) { buf = Handlebars.Utils.escapeExpression(buf); }
@@ -136,7 +147,7 @@ Handlebars.Runtime.prototype = {
if(toString.call(data) !== "[object Function]") {
params = [data];
- data = this.context.helpers.helperMissing;
+ data = this.context.helpers.blockHelperMissing;
} else {
params = this.evaluateParams(mustache.params);
}