Add test for transform option of ConrefLoader

This commit is contained in:
Samy Pesse
2016-05-11 15:08:10 +02:00
parent 961d43f085
commit 9013f02850
3 changed files with 31 additions and 9 deletions
+29 -8
View File
@@ -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');
});
});
});
});
+1
View File
@@ -0,0 +1 @@
Hello World
+1 -1
View File
@@ -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);
}