mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 01:53:26 +00:00
Add tests for conrefs loader
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user