From d6bd4a0d67dd2f61e667aefebf96e279f607ce54 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Samy=20Pess=C3=A9?=
Date: Sun, 14 Feb 2016 23:05:37 +0100
Subject: [PATCH] Add test for file variables in templating
---
lib/page/index.js | 5 +++++
test/all.js | 4 +++-
test/page.js | 20 +++++++++++++++++++-
3 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/lib/page/index.js b/lib/page/index.js
index 51416f0bd..54255ddf9 100644
--- a/lib/page/index.js
+++ b/lib/page/index.js
@@ -173,6 +173,11 @@ Page.prototype.toHTML = function(output) {
return pipeline.output()
.then(that.update);
+ })
+
+ // Return content itself
+ .then(function() {
+ return that.content;
});
};
diff --git a/test/all.js b/test/all.js
index 2c871559a..fed3f61a4 100644
--- a/test/all.js
+++ b/test/all.js
@@ -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');
diff --git a/test/page.js b/test/page.js
index 8dbfe8bd5..9932e3884 100644
--- a/test/page.js
+++ b/test/page.js
@@ -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)
\n');
+ });
+ });
+
+ it('should set file.[path]', function() {
+ var page = book.addPage('variables/file/path.md');
+ return page.toHTML(output)
+ .should.be.fulfilledWith('variables/file/path.md
\n');
+ });
+ });
});
\ No newline at end of file