Added support for expressions that reference functions.

This commit is contained in:
Alan Johnson
2010-08-05 23:59:59 -04:00
parent 03d06fa70a
commit 28d699233a
+3 -1
View File
@@ -2,6 +2,7 @@ Handlebars = {
compile: function(string) {
var compiler = new Handlebars.Compiler(string);
var result = compiler.compile();
console.log(result);
return new Function("context", "fallback", "fallback = fallback || {}; var stack = [];" + result);
},
@@ -118,7 +119,8 @@ Handlebars.Compiler.prototype = {
},
addExpression: function(mustache) {
this.fn += "out = out + " + this.lookupFor(mustache) + "; ";
var expr = this.lookupFor(mustache);
this.fn += "out = out + (Handlebars.isFunction(" + expr + ") ? " + expr + "() : " + expr + "); ";
},
lookupFor: function(param) {