diff options
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 8 | ||||
-rw-r--r-- | lib/handlebars/vm.js | 8 | ||||
-rw-r--r-- | spec/qunit_spec.js | 17 |
3 files changed, 29 insertions, 4 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index 427e0a5..4bc1f82 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -638,7 +638,13 @@ Handlebars.JavaScriptCompiler = function() {}; }, invokePartial: function(context) { - this.pushStack("self.invokePartial(" + this.nameLookup('partials', context, 'partial') + ", '" + context + "', " + this.popStack() + ", helpers, partials);"); + params = [this.nameLookup('partials', context, 'partial'), "'" + context + "'", this.popStack(), "helpers", "partials"]; + + if (this.options.data) { + params.push("data"); + } + + this.pushStack("self.invokePartial(" + params.join(", ") + ");"); }, assignToHash: function(key) { diff --git a/lib/handlebars/vm.js b/lib/handlebars/vm.js index 7f9a42e..ecb4ce3 100644 --- a/lib/handlebars/vm.js +++ b/lib/handlebars/vm.js @@ -46,16 +46,18 @@ Handlebars.VM = { }; }, noop: function() { return ""; }, - invokePartial: function(partial, name, context, helpers, partials) { + invokePartial: function(partial, name, context, helpers, partials, data) { + options = { helpers: helpers, partials: partials, data: data }; + if(partial === undefined) { throw new Handlebars.Exception("The partial " + name + " could not be found"); } else if(partial instanceof Function) { - return partial(context, {helpers: helpers, partials: partials}); + return partial(context, options); } else if (!Handlebars.compile) { throw new Handlebars.Exception("The partial " + name + " could not be compiled when running in vm mode"); } else { partials[name] = Handlebars.compile(partial); - return partials[name](context, {helpers: helpers, partials: partials}); + return partials[name](context, options); } } }; diff --git a/spec/qunit_spec.js b/spec/qunit_spec.js index 3f9218d..6f5a192 100644 --- a/spec/qunit_spec.js +++ b/spec/qunit_spec.js @@ -650,6 +650,23 @@ test("passing in data to a compiled function that expects data - works with help equals("happy cat", result, "Data output by helper"); }); +test("passing in data to a compiled function that expects data - works with helpers in partials", function() { + var template = CompilerContext.compile("{{>my_partial}}", {data: true}); + + var partials = { + my_partial: CompilerContext.compile("{{hello}}", {data: true}) + }; + + var helpers = { + hello: function(options) { + return options.data.adjective + " " + this.noun; + } + }; + + var result = template({noun: "cat"}, {helpers: helpers, partials: partials, data: {adjective: "happy"}}); + equals("happy cat", result, "Data output by helper inside partial"); +}); + test("passing in data to a compiled function that expects data - works with helpers and parameters", function() { var template = CompilerContext.compile("{{hello world}}", {data: true}); |