summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/handlebars/compiler/compiler.js8
-rw-r--r--spec/qunit_spec.js17
2 files changed, 23 insertions, 2 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js
index 1481098..57516a5 100644
--- a/lib/handlebars/compiler/compiler.js
+++ b/lib/handlebars/compiler/compiler.js
@@ -1040,7 +1040,9 @@ Handlebars.precompile = function(string, options) {
}
options = options || {};
-
+ if (!('data' in options)) {
+ options.data = true;
+ }
var ast = Handlebars.parse(string);
var environment = new Handlebars.Compiler().compile(ast, options);
return new Handlebars.JavaScriptCompiler().compile(environment, options);
@@ -1052,7 +1054,9 @@ Handlebars.compile = function(string, options) {
}
options = options || {};
-
+ if (!('data' in options)) {
+ options.data = true;
+ }
var compiled;
function compile() {
var ast = Handlebars.parse(string);
diff --git a/spec/qunit_spec.js b/spec/qunit_spec.js
index 07dde10..dcb7150 100644
--- a/spec/qunit_spec.js
+++ b/spec/qunit_spec.js
@@ -730,6 +730,23 @@ test("each with @index", function() {
equal(result, "0. goodbye! 1. Goodbye! 2. GOODBYE! cruel world!", "The @index variable is used");
});
+test("data passed to helpers", function() {
+ var string = "{{#each letters}}{{this}}{{detectDataInsideEach}}{{/each}}";
+ var hash = {letters: ['a', 'b', 'c']};
+
+ var template = CompilerContext.compile(string);
+ var result = template(hash, {
+ data: {
+ exclaim: '!'
+ }
+ });
+ equal(result, 'a!b!c!');
+});
+
+Handlebars.registerHelper('detectDataInsideEach', function(options) {
+ return options.data && options.data.exclaim;
+});
+
test("log", function() {
var string = "{{log blah}}";
var hash = { blah: "whee" };