summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/runtime.js
diff options
context:
space:
mode:
authorwycats <wycats@gmail.com>2010-12-03 01:39:00 -0500
committerwycats <wycats@gmail.com>2010-12-03 01:39:00 -0500
commit9a6f77af568d387d66d7cf1dcf6e4ea186d05506 (patch)
tree98997529fdcb426d3331f1f096aa854a0a90ed40 /lib/handlebars/runtime.js
parentc89ecf80a5dbc6f231ce9c74ff860bd1c6f3b478 (diff)
downloadhandlebars.js-9a6f77af568d387d66d7cf1dcf6e4ea186d05506.zip
handlebars.js-9a6f77af568d387d66d7cf1dcf6e4ea186d05506.tar.gz
handlebars.js-9a6f77af568d387d66d7cf1dcf6e4ea186d05506.tar.bz2
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
Diffstat (limited to 'lib/handlebars/runtime.js')
-rw-r--r--lib/handlebars/runtime.js37
1 files changed, 36 insertions, 1 deletions
diff --git a/lib/handlebars/runtime.js b/lib/handlebars/runtime.js
index fe6523e..a5c4843 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<l; i++) {
params[i] = this.accept(params[i]).data;
}
+
+ if(params.length === 0) { params = [undefined]; }
return params;
},
@@ -160,6 +194,7 @@ Handlebars.Runtime.prototype = {
var stack = proxy.__stack__ = this.stack.slice(0);
proxy.__get__ = function(path) {
+ path = new Handlebars.AST.IdNode(path.split("/"));
return context.evaluate(path, stack).data
};
@@ -175,7 +210,7 @@ Handlebars.Runtime.prototype = {
var fallback = this.context.fallback;
return function(context) {
- if(context.isWrappedContext) { context = context.__data__; }
+ if(context && context.isWrappedContext) { context = context.__data__; }
var runtime = new Handlebars.Runtime(context, fallback, stack);
runtime.accept(program);
return runtime.buffer;