diff options
author | kpdecker <kpdecker@gmail.com> | 2014-12-26 00:31:57 -0600 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2014-12-26 00:31:57 -0600 |
commit | 396795c983273bb5ca4dc67ddc74eb12f00bf110 (patch) | |
tree | 8fa69873ed195fc7b0aa1c909373fa7ccac6785a /spec/helpers.js | |
parent | 9e907e67854ea1ae208fe061452a9c9e2ce9468b (diff) | |
download | handlebars.js-396795c983273bb5ca4dc67ddc74eb12f00bf110.zip handlebars.js-396795c983273bb5ca4dc67ddc74eb12f00bf110.tar.gz handlebars.js-396795c983273bb5ca4dc67ddc74eb12f00bf110.tar.bz2 |
Implement block parameters
Fixes #907
Diffstat (limited to 'spec/helpers.js')
-rw-r--r-- | spec/helpers.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/spec/helpers.js b/spec/helpers.js index f23ee14..712bb00 100644 --- a/spec/helpers.js +++ b/spec/helpers.js @@ -657,4 +657,64 @@ describe('helpers', function() { equals(result, "GOODBYE cruel WORLD goodbye", "Helper executed"); }); }); + + describe('block params', function() { + it('should take presedence over context values', function() { + var hash = {value: 'foo'}; + var helpers = { + goodbyes: function(options) { + equals(options.fn.blockParams, 1); + return options.fn({value: 'bar'}, {blockParams: [1, 2]}); + } + }; + shouldCompileTo('{{#goodbyes as |value|}}{{value}}{{/goodbyes}}{{value}}', [hash, helpers], '1foo'); + }); + it('should take presedence over helper values', function() { + var hash = {}; + var helpers = { + value: function() { + return 'foo'; + }, + goodbyes: function(options) { + equals(options.fn.blockParams, 1); + return options.fn({}, {blockParams: [1, 2]}); + } + }; + shouldCompileTo('{{#goodbyes as |value|}}{{value}}{{/goodbyes}}{{value}}', [hash, helpers], '1foo'); + }); + it('should not take presedence over pathed values', function() { + var hash = {value: 'bar'}; + var helpers = { + value: function() { + return 'foo'; + }, + goodbyes: function(options) { + equals(options.fn.blockParams, 1); + return options.fn(this, {blockParams: [1, 2]}); + } + }; + shouldCompileTo('{{#goodbyes as |value|}}{{./value}}{{/goodbyes}}{{value}}', [hash, helpers], 'barfoo'); + }); + it('should take presednece over parent block params', function() { + var hash = {value: 'foo'}, + value = 1; + var helpers = { + goodbyes: function(options) { + return options.fn({value: 'bar'}, {blockParams: options.fn.blockParams === 1 ? [value++, value++] : undefined}); + } + }; + shouldCompileTo('{{#goodbyes as |value|}}{{#goodbyes}}{{value}}{{#goodbyes as |value|}}{{value}}{{/goodbyes}}{{/goodbyes}}{{/goodbyes}}{{value}}', [hash, helpers], '13foo'); + }); + + it('should allow block params on chained helpers', function() { + var hash = {value: 'foo'}; + var helpers = { + goodbyes: function(options) { + equals(options.fn.blockParams, 1); + return options.fn({value: 'bar'}, {blockParams: [1, 2]}); + } + }; + shouldCompileTo('{{#if bar}}{{else goodbyes as |value|}}{{value}}{{/if}}{{value}}', [hash, helpers], '1foo'); + }); + }); }); |