From 88d0ea90fcd838d61ada5b2115b72803c8088a6f Mon Sep 17 00:00:00 2001 From: Alan Johnson Date: Sat, 25 Sep 2010 16:42:59 -0400 Subject: [PATCH] Switched empty block handling for expression blocks to use helperMissing.not. --- lib/handlebars.js | 20 +++++++++++++++----- test/handlebars.js | 5 +++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/handlebars.js b/lib/handlebars.js index f2d87ae3..7df35481 100644 --- a/lib/handlebars.js +++ b/lib/handlebars.js @@ -178,14 +178,21 @@ var Handlebars = { var out = ""; if (Handlebars.isFunction(lookup)) { out = out + lookup.call(context, arg, fn); + if (notFn != null && Handlebars.isFunction(lookup.not)) { + out = out + lookup.not.call(context, arg, notFn); + } } - else if (typeof lookup != 'undefined') { - out = out + Handlebars.helperMissing.call(arg, lookup, fn); + else { + if (!Handlebars.isEmpty(lookup)) { + out = out + Handlebars.helperMissing.call(arg, lookup, fn); + } + + if (notFn != null) { + out = out + Handlebars.helperMissing.not.call(arg, lookup, notFn); + } } - if (notFn != null && Handlebars.isFunction(lookup.not)) { - out = out + lookup.not.call(context, arg, notFn); - } + return out; }, @@ -256,6 +263,9 @@ Handlebars.helperMissing = function(object, fn) { return fn(object); } }; +Handlebars.helperMissing.not = function(context, fn) { + return fn(context); +} Handlebars.Compiler.prototype = { getChar: function(n) { diff --git a/test/handlebars.js b/test/handlebars.js index 0fc09c03..f7c870b4 100644 --- a/test/handlebars.js +++ b/test/handlebars.js @@ -267,6 +267,11 @@ test("nested block helpers", function() { }); test("block inverted sections", function() { + shouldCompileTo("{{#people}}{{name}}{{^}}{{../none}}{{/people}}", {none: "No people"}, + "No people"); +}); + +test("block helper inverted sections", function() { var string = "{{#list people}}{{name}}{{^}}Nobody's here{{/list}}" var list = function(context, fn) { if (context.length > 0) {