Allow helperMissing to apply to simple mustaches (paves the way to support things like link_to in a Rails context)

This commit is contained in:
wycats
2010-12-11 18:43:58 -08:00
parent 62cea5b05e
commit 9fcd85bbac
3 changed files with 31 additions and 6 deletions
+16 -5
View File
@@ -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);
}