Complete conrefs in parsing

This commit is contained in:
Samy Pesse
2016-02-11 18:18:33 +01:00
parent 98a13cf487
commit e7eed2abbe
9 changed files with 82 additions and 26 deletions
-1
View File
@@ -5,7 +5,6 @@ var tmp = require('tmp');
var path = require('path');
var should = require('should');
require('should-promised');
var Book = require('../').Book;
var Output = require('../lib/output');
+40 -9
View File
@@ -1,32 +1,63 @@
var mock = require('./mock');
var TemplateEngine = require('../lib/template');
var pkg = require('../package.json');
describe('Template', function() {
var book, tpl;
var book;
before(function() {
return mock.setupDefaultBook()
return mock.setupDefaultBook({
'test.md': 'World'
})
.then(function(_book) {
book = _book;
return book.parse();
})
.then(function() {
tpl = new TemplateEngine(book);
});
});
describe('.renderString', function() {
it('should render a simple string', function() {
return tpl.renderString('Hello World')
return book.template.renderString('Hello World')
.should.be.fulfilledWith('Hello World');
});
it('should render with variable', function() {
return tpl.renderString('Version is {{ gitbook.version }}')
return book.template.renderString('Version is {{ gitbook.version }}')
.should.be.fulfilledWith('Version is '+pkg.version);
});
});
describe('Conrefs Loader', function() {
it('should include a local file', function() {
return book.template.renderString('Hello {% include "./test.md" %}')
.should.be.fulfilledWith('Hello World');
});
it('should include a git url', function() {
return book.template.renderString('Hello {% include "./test.md" %}')
.should.be.fulfilledWith('Hello World');
});
it('should reject file out of scope', function() {
return book.template.renderString('Hello {% include "../test.md" %}')
.should.be.rejected();
});
describe('Git Urls', function() {
it('should include a file from a git repo', function() {
return book.template.renderString('{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md" %}')
.should.be.fulfilledWith('Hello from git');
});
it('should handle deep inclusion (1)', function() {
return book.template.renderString('{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test2.md" %}')
.should.be.fulfilledWith('First Hello. Hello from git');
});
it('should handle deep inclusion (2)', function() {
return book.template.renderString('{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test3.md" %}')
.should.be.fulfilledWith('First Hello. Hello from git');
});
});
});
});