From 9a6f77af568d387d66d7cf1dcf6e4ea186d05506 Mon Sep 17 00:00:00 2001 From: wycats Date: Fri, 3 Dec 2010 01:39:00 -0500 Subject: [PATCH] A few more lingering bugs: * add helperMissing.not to the specs * add Handlebars.Utils.isEmpty * add runtime handling for inverse sections * fix __get__ to pass an IdNode to evaluate * handle case in wrapProgram where context is undefined --- lib/handlebars/runtime.js | 37 ++++++++++++++++++++++++++++++++++++- lib/handlebars/utils.js | 13 +++++++++++++ spec/qunit_spec.js | 4 ++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/lib/handlebars/runtime.js b/lib/handlebars/runtime.js index fe6523e9..a5c48430 100644 --- a/lib/handlebars/runtime.js +++ b/lib/handlebars/runtime.js @@ -140,6 +140,38 @@ Handlebars.Runtime.prototype = { this.buffer = this.buffer + data.apply(this.wrapContext(), params); }, + // TODO: Block and Inverse can share code + inverse: function(block) { + var mustache = block.mustache, + id = mustache.id; + + var idObj = this.accept(id), + data = idObj.data, + isInverse = Handlebars.Utils.isEmpty(data); + + if(toString.call(data) !== "[object Function]") { + params = [data]; + data = this.context.evaluate({depth: 0, parts: ["helperMissing"]}, this.stack).data; + id = "helperMissing"; + } else { + params = this.evaluateParams(mustache.params); + id = id.parts.join("/"); + } + + if(isInverse) { + var not = data.not; + + if(not) { + var context = this.wrapContext(); + params.push(this.wrapProgram(block.program)); + + this.buffer = this.buffer + not.apply(this.wrapContext(), params); + } else { + throw new Handlebars.Exception("Not .not property found on " + id); + } + } + }, + content: function(content) { this.buffer += content.string; }, @@ -150,6 +182,8 @@ Handlebars.Runtime.prototype = { for(var i=0, l=params.length; i