diff options
-rw-r--r-- | lib/handlebars.js | 3 | ||||
-rw-r--r-- | spec/builtins.js | 9 | ||||
-rw-r--r-- | spec/data.js | 4 | ||||
-rw-r--r-- | spec/helpers.js | 31 | ||||
-rw-r--r-- | spec/partials.js | 4 |
5 files changed, 24 insertions, 27 deletions
diff --git a/lib/handlebars.js b/lib/handlebars.js index 346d730..4b8674b 100644 --- a/lib/handlebars.js +++ b/lib/handlebars.js @@ -1,4 +1,4 @@ -import { HandlebarsEnvironment } from "./handlebars/base"; +import { HandlebarsEnvironment, createFrame } from "./handlebars/base"; // Each of these augment the Handlebars object. No need to setup here. // (This is done to easily share code between commonjs and browse envs) @@ -23,6 +23,7 @@ var create = function() { hb.compile = compile; hb.precompile = precompile; hb.template = template; + hb.createFrame = createFrame; return hb; }; diff --git a/spec/builtins.js b/spec/builtins.js index 4379725..bf77d1a 100644 --- a/spec/builtins.js +++ b/spec/builtins.js @@ -47,6 +47,12 @@ describe('builtin helpers', function() { }); describe('#each', function() { + beforeEach(function() { + handlebarsEnv.registerHelper('detectDataInsideEach', function(options) { + return options.data && options.data.exclaim; + }); + }); + it("each", function() { var string = "{{#each goodbyes}}{{text}}! {{/each}}cruel {{world}}!"; var hash = {goodbyes: [{text: "goodbye"}, {text: "Goodbye"}, {text: "GOODBYE"}], world: "world"}; @@ -104,9 +110,6 @@ describe('builtin helpers', function() { equal(result, 'a!b!c!', 'should output data'); }); - Handlebars.registerHelper('detectDataInsideEach', function(options) { - return options.data && options.data.exclaim; - }); }); it("#log", function() { diff --git a/spec/data.js b/spec/data.js index 5af35b7..092c1df 100644 --- a/spec/data.js +++ b/spec/data.js @@ -19,12 +19,10 @@ describe('data', function() { equals("hello", result, "@foo retrieves template data"); }); - var objectCreate = Handlebars.createFrame; - it("deep @foo triggers automatic top-level data", function() { var template = CompilerContext.compile('{{#let world="world"}}{{#if foo}}{{#if foo}}Hello {{@world}}{{/if}}{{/if}}{{/let}}'); - var helpers = objectCreate(Handlebars.helpers); + var helpers = Handlebars.createFrame(handlebarsEnv.helpers); helpers.let = function(options) { var frame = Handlebars.createFrame(options.data); diff --git a/spec/helpers.js b/spec/helpers.js index 71f09d3..c5ea574 100644 --- a/spec/helpers.js +++ b/spec/helpers.js @@ -161,7 +161,7 @@ describe('helpers', function() { }); it("the helper hash should augment the global hash", function() { - Handlebars.registerHelper('test_helper', function() { return 'found it!'; }); + handlebarsEnv.registerHelper('test_helper', function() { return 'found it!'; }); shouldCompileTo( "{{test_helper}} {{#if cruel}}Goodbye {{cruel}} {{world}}!{{/if}}", [ @@ -173,26 +173,21 @@ describe('helpers', function() { }); it("Multiple global helper registration", function() { - var helpers = Handlebars.helpers; - try { - Handlebars.helpers = {}; + var helpers = handlebarsEnv.helpers; + handlebarsEnv.helpers = {}; - Handlebars.registerHelper({ - 'if': helpers['if'], - world: function() { return "world!"; }, - test_helper: function() { return 'found it!'; } - }); + handlebarsEnv.registerHelper({ + 'if': helpers['if'], + world: function() { return "world!"; }, + test_helper: function() { return 'found it!'; } + }); - shouldCompileTo( - "{{test_helper}} {{#if cruel}}Goodbye {{cruel}} {{world}}!{{/if}}", - [{cruel: "cruel"}], - "found it! Goodbye cruel world!!"); - } finally { - if (helpers) { - Handlebars.helpers = helpers; - } - } + shouldCompileTo( + "{{test_helper}} {{#if cruel}}Goodbye {{cruel}} {{world}}!{{/if}}", + [{cruel: "cruel"}], + "found it! Goodbye cruel world!!"); }); + it("negative number literals work", function() { var string = 'Message: {{hello -12}}'; var hash = {}; diff --git a/spec/partials.js b/spec/partials.js index d919eed..fa2fa56 100644 --- a/spec/partials.js +++ b/spec/partials.js @@ -70,7 +70,7 @@ describe('partials', function() { }); it("Global Partials", function() { - Handlebars.registerPartial('global_test', '{{another_dude}}'); + handlebarsEnv.registerPartial('global_test', '{{another_dude}}'); var string = "Dudes: {{> shared/dude}} {{> global_test}}"; var dude = "{{name}}"; @@ -79,7 +79,7 @@ describe('partials', function() { }); it("Multiple partial registration", function() { - Handlebars.registerPartial({ + handlebarsEnv.registerPartial({ 'shared/dude': '{{name}}', global_test: '{{another_dude}}' }); |