From 00abfd3164d76eb618caa1e167c66e2d69faee57 Mon Sep 17 00:00:00 2001 From: Alan Johnson Date: Tue, 14 Sep 2010 20:37:03 -0400 Subject: [PATCH] Got handleExpression written up. --- lib/handlebars.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/handlebars.js b/lib/handlebars.js index 246043cd..e386f05c 100644 --- a/lib/handlebars.js +++ b/lib/handlebars.js @@ -166,17 +166,28 @@ var Handlebars = { } }, - handleBlock: function(lookup, context, proxy, fn, notFn) { + handleBlock: function(lookup, context, arg, fn, notFn) { var out = ""; if (Handlebars.isFunction(lookup)) { - out = out + lookup.call(context, proxy, fn); + out = out + lookup.call(context, arg, fn); } else if (typeof lookup != 'undefined') { - out = out + Handlebars.helperMissing.call(proxy, lookup, fn); + out = out + Handlebars.helperMissing.call(arg, lookup, fn); } if (notFn != null && Handlebars.isFunction(lookup.not)) { - out = out + lookup.not.call(context, proxy, notFn); + out = out + lookup.not.call(context, arg, notFn); + } + + return out; + }, + + handleExpression: function(lookup, context, arg, isEscaped) { + var out = ""; + if (Handlebars.isFunction(lookup)) { + out = out + Handlebars.filterOutput(lookup.call(context, arg), isEscaped); + } else if(!Handlebars.isEmpty(lookup)) { + out = out + Handlebars.filterOutput(lookup, isEscaped); } return out; @@ -282,9 +293,10 @@ Handlebars.Compiler.prototype = { }, addExpression: function(mustache, param) { + param = param || null; var expr = this.lookupFor(mustache); - 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 + "); "; + this.fn += "var proxy = Handlebars.buildContext(context, stack);" + this.fn += "out = out + Handlebars.handleExpression(" + expr + ", proxy, " + param + ", " + this.escaped + ");"; }, addInvertedSection: function(mustache) {