diff options
-rw-r--r-- | lib/backbone/summary.js | 8 | ||||
-rw-r--r-- | lib/page/index.js | 6 | ||||
-rw-r--r-- | test/page.js | 24 |
3 files changed, 35 insertions, 3 deletions
diff --git a/lib/backbone/summary.js b/lib/backbone/summary.js index f4b9288..cef3ae9 100644 --- a/lib/backbone/summary.js +++ b/lib/backbone/summary.js @@ -41,6 +41,14 @@ TOCArticle.prototype.walk = function(iter) { }); }; +// Return templating context for an article +TOCArticle.prototype.getContext = function() { + return { + title: this.title, + path: this.path + }; +}; + // Return true if is pointing to a file TOCArticle.prototype.hasLocation = function() { return Boolean(this.path); diff --git a/lib/page/index.js b/lib/page/index.js index 54255dd..b3ff00f 100644 --- a/lib/page/index.js +++ b/lib/page/index.js @@ -107,6 +107,8 @@ Page.prototype.read = function() { // This is used both for themes and page parsing Page.prototype.getContext = function() { var article = this.book.summary.getArticle(this); + var next = article? article.next() : null; + var prev = article? article.prev() : null; return { file: { @@ -115,8 +117,8 @@ Page.prototype.getContext = function() { }, page: { title: article? article.title : null, - next: article? article.next() : null, - previous: article? article.prev() : null + next: next? next.getContext() : null, + previous: prev? prev.getContext() : null } }; }; diff --git a/test/page.js b/test/page.js index a9b7985..fb3e3e5 100644 --- a/test/page.js +++ b/test/page.js @@ -11,11 +11,21 @@ describe('Page', function() { 'folder/paths.md': '', 'variables/file/mtime.md': '{{ file.mtime }}', 'variables/file/path.md': '{{ file.path }}', - 'variables/page/title.md': '{{ page.title }}' + 'variables/page/title.md': '{{ page.title }}', + 'variables/page/previous.md': '{{ page.previous.title }} {{ page.previous.path }}', + 'variables/page/next.md': '{{ page.next.title }} {{ page.next.path }}' }, [ { + title: 'Test page.next', + path: 'variables/page/next.md' + }, + { title: 'Test Variables', path: 'variables/page/title.md' + }, + { + title: 'Test page.previous', + path: 'variables/page/previous.md' } ]) .then(function(_book) { @@ -121,5 +131,17 @@ describe('Page', function() { return page.toHTML(output) .should.be.fulfilledWith('<p>Test Variables</p>\n'); }); + + it('should set page.previous when possible', function() { + var page = book.getPage('variables/page/previous.md'); + return page.toHTML(output) + .should.be.fulfilledWith('<p>Test Variables variables/page/title.md</p>\n'); + }); + + it('should set page.next when possible', function() { + var page = book.getPage('variables/page/next.md'); + return page.toHTML(output) + .should.be.fulfilledWith('<p>Test Variables variables/page/title.md</p>\n'); + }); }); }); |