diff options
author | kpdecker <kpdecker@gmail.com> | 2015-08-14 15:18:52 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2015-08-22 10:59:08 -0700 |
commit | 91ffd32cad32b2d1cd310ff94f65b28c428206ac (patch) | |
tree | 13cb346dfb0e6dc72dc6dddbcdf3ed8e61ebaeff /spec/partials.js | |
parent | 2571dd8e8e43fd320672763564b16a5b3ae33966 (diff) | |
download | handlebars.js-91ffd32cad32b2d1cd310ff94f65b28c428206ac.zip handlebars.js-91ffd32cad32b2d1cd310ff94f65b28c428206ac.tar.gz handlebars.js-91ffd32cad32b2d1cd310ff94f65b28c428206ac.tar.bz2 |
Implement partial blocks
This allows for failover for missing partials as well as limited templating ability through the `{{> @partial-block }}` partial special case.
Partial fix for #1018
Diffstat (limited to 'spec/partials.js')
-rw-r--r-- | spec/partials.js | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/spec/partials.js b/spec/partials.js index a9cd3dd..314cca2 100644 --- a/spec/partials.js +++ b/spec/partials.js @@ -196,6 +196,67 @@ describe('partials', function() { handlebarsEnv.compile = compile; }); + describe('partial blocks', function() { + it('should render partial block as default', function() { + shouldCompileToWithPartials( + '{{#> dude}}success{{/dude}}', + [{}, {}, {}], + true, + 'success'); + }); + it('should execute default block with proper context', function() { + shouldCompileToWithPartials( + '{{#> dude context}}{{value}}{{/dude}}', + [{context: {value: 'success'}}, {}, {}], + true, + 'success'); + }); + it('should propagate block parameters to default block', function() { + shouldCompileToWithPartials( + '{{#with context as |me|}}{{#> dude}}{{me.value}}{{/dude}}{{/with}}', + [{context: {value: 'success'}}, {}, {}], + true, + 'success'); + }); + + it('should not use partial block if partial exists', function() { + shouldCompileToWithPartials( + '{{#> dude}}fail{{/dude}}', + [{}, {}, {dude: 'success'}], + true, + 'success'); + }); + + it('should render block from partial', function() { + shouldCompileToWithPartials( + '{{#> dude}}success{{/dude}}', + [{}, {}, {dude: '{{> @partial-block }}'}], + true, + 'success'); + }); + it('should render block from partial with context', function() { + shouldCompileToWithPartials( + '{{#> dude}}{{value}}{{/dude}}', + [{context: {value: 'success'}}, {}, {dude: '{{#with context}}{{> @partial-block }}{{/with}}'}], + true, + 'success'); + }); + it('should render block from partial with context', function() { + shouldCompileToWithPartials( + '{{#> dude}}{{../context/value}}{{/dude}}', + [{context: {value: 'success'}}, {}, {dude: '{{#with context}}{{> @partial-block }}{{/with}}'}], + true, + 'success'); + }); + it('should render block from partial with block params', function() { + shouldCompileToWithPartials( + '{{#with context as |me|}}{{#> dude}}{{me.value}}{{/dude}}{{/with}}', + [{context: {value: 'success'}}, {}, {dude: '{{> @partial-block }}'}], + true, + 'success'); + }); + }); + it('should pass compiler flags', function() { if (Handlebars.compile) { var env = Handlebars.create(); |