Add test for file variables in templating

This commit is contained in:
Samy Pessé
2016-02-14 23:05:37 +01:00
parent 8628c87be4
commit d6bd4a0d67
3 changed files with 27 additions and 2 deletions
+5
View File
@@ -173,6 +173,11 @@ Page.prototype.toHTML = function(output) {
return pipeline.output()
.then(that.update);
})
// Return content itself
.then(function() {
return that.content;
});
};
+3 -1
View File
@@ -5,13 +5,15 @@ require('./readme');
require('./summary');
require('./glossary');
require('./langs');
require('./page');
require('./parse');
require('./git');
require('./template');
require('./conrefs');
// Page and HTML generation
require('./page');
// Output
require('./output-json');
require('./assets-inliner');
+19 -1
View File
@@ -8,7 +8,9 @@ describe('Page', function() {
return mock.setupDefaultBook({
'heading.md': '# Hello\n\n## World',
'links.md': '[link](hello.md) [readme](README.md)',
'folder/paths.md': ''
'folder/paths.md': '',
'variables/file/mtime.md': '{{ file.mtime }}',
'variables/file/path.md': '{{ file.path }}'
})
.then(function(_book) {
book = _book;
@@ -93,4 +95,20 @@ describe('Page', function() {
});
});
describe('Templating Context', function() {
it('should set file.mtime', function() {
var page = book.addPage('variables/file/mtime.md');
return page.toHTML(output)
.then(function(content) {
content.should.endWith('(CET)</p>\n');
});
});
it('should set file.[path]', function() {
var page = book.addPage('variables/file/path.md');
return page.toHTML(output)
.should.be.fulfilledWith('<p>variables/file/path.md</p>\n');
});
});
});