From bc389ab4a1ea9013a869c0b33162fb67bb0d0708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Tue, 27 Jan 2015 21:47:14 +0100 Subject: [PATCH] Improve tests on blocks extensions --- lib/template.js | 1 + test/plugins.js | 10 ++++++++++ test/plugins/blocks/index.js | 13 +++++++++++++ 3 files changed, 24 insertions(+) diff --git a/lib/template.js b/lib/template.js index ac7bc3e97..ec1b39149 100644 --- a/lib/template.js +++ b/lib/template.js @@ -169,6 +169,7 @@ TemplateEngine.prototype.addBlock = function(name, block) { body: args.pop()() }; }) + .reverse() .value(); var body = args.pop(); diff --git a/test/plugins.js b/test/plugins.js index 0f826d299..3c60a2008 100644 --- a/test/plugins.js +++ b/test/plugins.js @@ -117,5 +117,15 @@ describe('Plugins', function () { done ); }); + + it('should correctly extend template blocks with different sub-blocks', function(done) { + qdone( + books[0].template.renderString('{% test4join separator=";" %}hello{% also %}the{% finally %}world{% endtest4join %}') + .then(function(content) { + assert.equal(content, "hello;the;world"); + }), + done + ); + }); }); }); diff --git a/test/plugins/blocks/index.js b/test/plugins/blocks/index.js index f2c588a10..b8f72fea3 100644 --- a/test/plugins/blocks/index.js +++ b/test/plugins/blocks/index.js @@ -1,3 +1,5 @@ +var assert = require("assert"); + module.exports = { blocks: { "test": { @@ -18,6 +20,17 @@ module.exports = { process: function(blk) { return [blk.body, blk.blocks[0].body].join(blk.kwargs.separator); } + }, + "test4join": { + blocks: [ + "also", "finally" + ], + process: function(blk) { + assert(blk.blocks.length, 2); + assert(blk.blocks[0].name, "also"); + assert(blk.blocks[1].name, "finally"); + return [blk.body, blk.blocks[0].body, blk.blocks[1].body].join(blk.kwargs.separator); + } } } }; \ No newline at end of file