From 299a0e81e321b5b2cee2ee3a03c258699c8f895c Mon Sep 17 00:00:00 2001 From: tomhuda Date: Fri, 11 Feb 2011 20:11:23 -0800 Subject: [PATCH] data is passed to block helpers --- lib/handlebars/vm.js | 5 +++++ spec/qunit_spec.js | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/handlebars/vm.js b/lib/handlebars/vm.js index fee59534..2a1d4e97 100644 --- a/lib/handlebars/vm.js +++ b/lib/handlebars/vm.js @@ -499,6 +499,11 @@ Handlebars.JavaScriptCompiler = function() {}; params.push(mainProgram, inverse); blockMissingParams.push(mainProgram, inverse); + if(this.data) { + params.push("data"); + blockMissingParams.push("data"); + } + var nextStack = this.nextStack(); this.source.push("if(typeof " + id + " === 'function') { " + nextStack + " = " + id + ".call(" + params.join(", ") + "); }"); diff --git a/spec/qunit_spec.js b/spec/qunit_spec.js index 3e5fe8bd..7dcac84e 100644 --- a/spec/qunit_spec.js +++ b/spec/qunit_spec.js @@ -583,4 +583,21 @@ test("passing in data to a compiled function that expects data - works with bloc 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); +}); + +