Add tests for conrefs loader

This commit is contained in:
Samy Pesse
2016-04-30 20:06:43 +02:00
parent a5f4596f8d
commit b51470db39
3 changed files with 36 additions and 3 deletions
-1
View File
@@ -4,7 +4,6 @@ var Promise = require('../../utils/promise');
describe('TemplateBlock', function() {
var TemplateBlock = require('../templateBlock');
var TemplateEngine = require('../templateEngine');
describe('create', function() {
pit('must initialize a simple TemplateBlock from a function', function() {
+34
View File
@@ -0,0 +1,34 @@
var TemplateEngine = require('../../models/templateEngine');
var renderTemplate = require('../render');
describe('ConrefsLoader', function() {
var ConrefsLoader = require('../conrefsLoader');
var engine = TemplateEngine({
loader: new ConrefsLoader(__dirname)
});
describe('Git', function() {
pit('should include content from git', function() {
return renderTemplate(engine, 'test.md', '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md" %}')
.then(function(str) {
expect(str).toBe('Hello from git');
});
});
pit('should handle deep inclusion (1)', function() {
return renderTemplate(engine, 'test.md', '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test2.md" %}')
.then(function(str) {
expect(str).toBe('First Hello. Hello from git');
});
});
pit('should handle deep inclusion (2)', function() {
return renderTemplate(engine, 'test.md', '{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test3.md" %}')
.then(function(str) {
expect(str).toBe('First Hello. Hello from git');
});
});
});
});
+2 -2
View File
@@ -48,9 +48,9 @@ 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.root, from)) {
if (PathUtils.isInRoot(this.rootFolder, from)) {
var href = LocationUtils.toAbsolute(to, path.dirname(from), '');
return PathUtils.resolveInRoot(this.root, href);
return PathUtils.resolveInRoot(this.rootFolder, href);
}
// If origin is in a git repository, we resolve file in the git repository