Got expressions that are helpers with arguments working.
This commit is contained in:
+3
-4
@@ -1,7 +1,6 @@
|
||||
Handlebars = {
|
||||
compile: function(string) {
|
||||
var fnBody = Handlebars.compileFunctionBody(string);
|
||||
console.log(fnBody);
|
||||
return new Function("context", "fallback", fnBody);
|
||||
},
|
||||
|
||||
@@ -258,10 +257,10 @@ Handlebars.Compiler.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
addExpression: function(mustache) {
|
||||
addExpression: function(mustache, param) {
|
||||
var expr = this.lookupFor(mustache);
|
||||
|
||||
this.fn += "if (Handlebars.isFunction(" + expr + ")) out = out + Handlebars.filterOutput(" + expr + ".call(Handlebars.buildContext(context, stack)), " + this.escaped + "); ";
|
||||
this.fn += "if (Handlebars.isFunction(" + expr + ")) out = out + Handlebars.filterOutput(" + expr + ".call(Handlebars.buildContext(context, stack), " + param + "), " + this.escaped + "); ";
|
||||
this.fn += "else if(typeof " + expr + "!== 'undefined') out = out + Handlebars.filterOutput(" + expr + ", " + this.escaped + ");";
|
||||
},
|
||||
|
||||
@@ -403,7 +402,7 @@ Handlebars.Compiler.prototype = {
|
||||
this.addBlock(mustache, param, parts)
|
||||
return;
|
||||
} else {
|
||||
return this.addExpression(mustache);
|
||||
return this.addExpression(mustache, param);
|
||||
}
|
||||
|
||||
this.escaped = true;
|
||||
|
||||
@@ -54,6 +54,13 @@ test("functions", function() {
|
||||
"functions are called and render their output");
|
||||
});
|
||||
|
||||
test("functions with context argument", function() {
|
||||
shouldCompileTo("{{awesome frank}}",
|
||||
{awesome: function(context) { return context; },
|
||||
frank: "Frank"},
|
||||
"Frank", "functions are called with context arguments");
|
||||
});
|
||||
|
||||
test("nested paths", function() {
|
||||
shouldCompileTo("Goodbye {{alan/expression}} world!", {alan: {expression: "beautiful"}},
|
||||
"Goodbye beautiful world!", "Nested paths access nested objects");
|
||||
|
||||
Reference in New Issue
Block a user