diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-06-18 11:16:32 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-06-18 11:16:32 +0200 |
commit | 50c902c4e481e8d1321e734d8912d1b285fc4f3c (patch) | |
tree | 8be7e07101270c48b0fef236974af8ea8a978e56 | |
parent | 78ff2687b4fe1dc7ba2817caa9e4a8426b5ebde2 (diff) | |
parent | 84b6e0bde6547421b3b42bb9a1754ae980c8aea1 (diff) | |
download | gitbook-50c902c4e481e8d1321e734d8912d1b285fc4f3c.zip gitbook-50c902c4e481e8d1321e734d8912d1b285fc4f3c.tar.gz gitbook-50c902c4e481e8d1321e734d8912d1b285fc4f3c.tar.bz2 |
Merge pull request #805 from GitbookIO/fix/804
Fix #804
-rw-r--r-- | lib/template.js | 2 | ||||
-rw-r--r-- | test/plugins.js | 14 | ||||
-rw-r--r-- | test/plugins/blocks/index.js | 17 |
3 files changed, 31 insertions, 2 deletions
diff --git a/lib/template.js b/lib/template.js index 3e6364d..3a4985c 100644 --- a/lib/template.js +++ b/lib/template.js @@ -250,7 +250,7 @@ TemplateEngine.prototype.addBlock = function(name, block) { // Extract main body and kwargs var body = args.pop(); - var kwargs = args.pop() || {}; + var kwargs = _.isObject(_.last(args))? args.pop() : {}; // Extract blocks body var _blocks = _.map(block.blocks, function(blockName, i){ diff --git a/test/plugins.js b/test/plugins.js index 14f4a2f..e3d0c49 100644 --- a/test/plugins.js +++ b/test/plugins.js @@ -185,6 +185,20 @@ describe('Plugins', function () { content.should.equal("hello;the;world"); }); }); + + it('should correctly extend template blocks with arguments', function() { + return testTpl('{% test5args "a", "b", "c" %}{% endtest5args %}') + .then(function(content) { + content.should.equal("test5a,b,ctest5"); + }); + }); + + it('should correctly extend template blocks with args and kwargs', function() { + return testTpl('{% test5kwargs "a", "b", "c", d="test", e="test2" %}{% endtest5kwargs %}') + .then(function(content) { + content.should.equal("test5a,b,c,d:test,e:test2,__keywords:truetest5"); + }); + }); }); }); diff --git a/test/plugins/blocks/index.js b/test/plugins/blocks/index.js index 32f1910..0848238 100644 --- a/test/plugins/blocks/index.js +++ b/test/plugins/blocks/index.js @@ -36,6 +36,21 @@ module.exports = { assert(blk.blocks[1].name, "finally"); return [blk.body, blk.blocks[0].body, blk.blocks[1].body].join(blk.kwargs.separator); } - } + }, + "test5args": { + process: function(blk) { + return "test5"+blk.args.join(',')+"test5"; + } + }, + "test5kwargs": { + process: function(blk) { + var s = blk.args.join(','); + for (var key in blk.kwargs) { + s = s + ','+key+':'+blk.kwargs[key]; + } + + return "test5"+s+"test5"; + } + }, } };
\ No newline at end of file |