diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-05-11 15:08:10 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-05-11 15:08:10 +0200 |
commit | 9013f02850d7e4cc934eb75967b5f976030e2f0d (patch) | |
tree | 5b17b82bd519d5b4250df09bc3f881cb6b3d5d5c | |
parent | 961d43f085036263edfe064c2107ab27ad62d8fa (diff) | |
download | gitbook-9013f02850d7e4cc934eb75967b5f976030e2f0d.zip gitbook-9013f02850d7e4cc934eb75967b5f976030e2f0d.tar.gz gitbook-9013f02850d7e4cc934eb75967b5f976030e2f0d.tar.bz2 |
Add test for transform option of ConrefLoader
-rw-r--r-- | lib/templating/__tests__/conrefsLoader.js | 37 | ||||
-rw-r--r-- | lib/templating/__tests__/include.md | 1 | ||||
-rw-r--r-- | lib/templating/conrefsLoader.js | 2 |
3 files changed, 31 insertions, 9 deletions
diff --git a/lib/templating/__tests__/conrefsLoader.js b/lib/templating/__tests__/conrefsLoader.js index d430a4f..a6a89ba 100644 --- a/lib/templating/__tests__/conrefsLoader.js +++ b/lib/templating/__tests__/conrefsLoader.js @@ -1,34 +1,55 @@ +var path = require('path'); + var TemplateEngine = require('../../models/templateEngine'); var renderTemplate = require('../render'); +var ConrefsLoader = require('../conrefsLoader'); describe('ConrefsLoader', function() { - var ConrefsLoader = require('../conrefsLoader'); - - var engine = TemplateEngine({ - loader: new ConrefsLoader(__dirname) - }); + var dirName = __dirname + '/'; + var fileName = path.join(dirName, 'test.md'); + console.log(dirName); describe('Git', function() { + var engine = TemplateEngine({ + loader: new ConrefsLoader(dirName) + }); + it('should include content from git', function() { - return renderTemplate(engine, 'test.md', '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md" %}') + return renderTemplate(engine, fileName, '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md" %}') .then(function(out) { expect(out.getContent()).toBe('Hello from git'); }); }); it('should handle deep inclusion (1)', function() { - return renderTemplate(engine, 'test.md', '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test2.md" %}') + return renderTemplate(engine, fileName, '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test2.md" %}') .then(function(out) { expect(out.getContent()).toBe('First Hello. Hello from git'); }); }); it('should handle deep inclusion (2)', function() { - return renderTemplate(engine, 'test.md', '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test3.md" %}') + return renderTemplate(engine, fileName, '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test3.md" %}') .then(function(out) { expect(out.getContent()).toBe('First Hello. Hello from git'); }); }); }); + + describe('transform', function() { + function transform(filePath, source) { + return 'test-' + source + '-endtest'; + } + var engine = TemplateEngine({ + loader: new ConrefsLoader(dirName, transform) + }); + + it('should transform included content', function() { + return renderTemplate(engine, fileName, '{% include "include.md" %}') + .then(function(out) { + expect(out.getContent()).toBe('test-Hello World-endtest'); + }); + }); + }); }); diff --git a/lib/templating/__tests__/include.md b/lib/templating/__tests__/include.md new file mode 100644 index 0000000..5e1c309 --- /dev/null +++ b/lib/templating/__tests__/include.md @@ -0,0 +1 @@ +Hello World
\ No newline at end of file diff --git a/lib/templating/conrefsLoader.js b/lib/templating/conrefsLoader.js index cdf0c30..52d2a95 100644 --- a/lib/templating/conrefsLoader.js +++ b/lib/templating/conrefsLoader.js @@ -62,7 +62,7 @@ var ConrefsLoader = nunjucks.Loader.extend({ resolve: function(from, to) { // If origin is in the book, we enforce result file to be in the book if (PathUtils.isInRoot(this.rootFolder, from)) { - var href = LocationUtils.toAbsolute(to, path.dirname(from), ''); + var href = LocationUtils.toAbsolute(to, path.dirname(from), this.rootFolder); return PathUtils.resolveInRoot(this.rootFolder, href); } |