summaryrefslogtreecommitdiffstats
path: root/test/template.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-26 09:41:26 +0100
committerSamy Pessé <samypesse@gmail.com>2016-02-26 09:41:26 +0100
commitd3d64f636c859f7f01a64f7774cf70bd8ccdc562 (patch)
tree4f7731f37c3a793d187b0ab1cd77680e69534c6c /test/template.js
parent4cb9cbb5ae3aa8f9211ffa3ac5e3d34232c0ca4f (diff)
parenteef072693b17526347c37b66078a5059c71caa31 (diff)
downloadgitbook-d3d64f636c859f7f01a64f7774cf70bd8ccdc562.zip
gitbook-d3d64f636c859f7f01a64f7774cf70bd8ccdc562.tar.gz
gitbook-d3d64f636c859f7f01a64f7774cf70bd8ccdc562.tar.bz2
Merge pull request #1109 from GitbookIO/3.0.0
Version 3.0.0
Diffstat (limited to 'test/template.js')
-rw-r--r--test/template.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/template.js b/test/template.js
new file mode 100644
index 0000000..6eb2278
--- /dev/null
+++ b/test/template.js
@@ -0,0 +1,54 @@
+var mock = require('./mock');
+var Output = require('../lib/output/base');
+
+describe('Template', function() {
+ var output;
+
+ before(function() {
+ return mock.outputDefaultBook(Output, {})
+ .then(function(_output) {
+ output = _output;
+ });
+ });
+
+ describe('.renderString', function() {
+ it('should render a simple string', function() {
+ return output.template.renderString('Hello World')
+ .should.be.fulfilledWith('Hello World');
+ });
+
+ it('should render with variable', function() {
+ return output.template.renderString('Hello {{ world }}', { world: 'World'})
+ .should.be.fulfilledWith('Hello World');
+ });
+ });
+
+ describe('Blocks', function() {
+ it('should correctly add a block', function() {
+ output.template.addBlock('sayhello', function(blk) {
+ return 'Hello ' + blk.body + '!';
+ });
+
+ return output.template.renderString('{% sayhello %}World{% endsayhello %}')
+ .should.be.fulfilledWith('Hello World!');
+ });
+
+ it('should correctly add a block with args', function() {
+ output.template.addBlock('sayhello_args', function(blk) {
+ return 'Hello ' + blk.args[0] + '!';
+ });
+
+ return output.template.renderString('{% sayhello_args "World" %}{% endsayhello_args %}')
+ .should.be.fulfilledWith('Hello World!');
+ });
+
+ it('should correctly add a block with kwargs', function() {
+ output.template.addBlock('sayhello_kwargs', function(blk) {
+ return 'Hello ' + blk.kwargs.name + '!';
+ });
+
+ return output.template.renderString('{% sayhello_kwargs name="World" %}{% endsayhello_kwargs %}')
+ .should.be.fulfilledWith('Hello World!');
+ });
+ });
+});