data is passed to block helpers

This commit is contained in:
tomhuda
2011-02-11 20:11:23 -08:00
parent e719f79259
commit 299a0e81e3
2 changed files with 22 additions and 0 deletions
+5
View File
@@ -499,6 +499,11 @@ Handlebars.JavaScriptCompiler = function() {};
params.push(mainProgram, inverse); params.push(mainProgram, inverse);
blockMissingParams.push(mainProgram, inverse); blockMissingParams.push(mainProgram, inverse);
if(this.data) {
params.push("data");
blockMissingParams.push("data");
}
var nextStack = this.nextStack(); var nextStack = this.nextStack();
this.source.push("if(typeof " + id + " === 'function') { " + nextStack + " = " + id + ".call(" + params.join(", ") + "); }"); this.source.push("if(typeof " + id + " === 'function') { " + nextStack + " = " + id + ".call(" + params.join(", ") + "); }");
+17
View File
@@ -583,4 +583,21 @@ test("passing in data to a compiled function that expects data - works with bloc
equals("happy world?", result); equals("happy world?", result);
}); });
test("passing in data to a compiled function that expects data - works with block helpers that use ..", function() {
var template = Handlebars.compile("{{#hello}}{{world ../zomg}}{{/hello}}", true);
var helpers = {
hello: function(fn, inverse, data) {
return data.accessData + " " + fn({exclaim: "?"});
},
world: function(thing, data) {
return data.adjective + " " + thing + (this.exclaim || "");
}
};
var result = template({exclaim: true, zomg: "world"}, helpers, null, {adjective: "happy", accessData: "#win"});
equals("#win happy world?", result);
});