mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-10-03 12:10:34 +00:00
Add test for transform option of ConrefLoader
This commit is contained in:
@@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Hello World
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user