From b5219aecf7643c4b03616492166ea14be9bab70e Mon Sep 17 00:00:00 2001 From: Tomas Dvorak Date: Thu, 28 Apr 2016 16:06:01 +0200 Subject: [PATCH] page nesting / level support --- README.md | 3 ++- lib/tester.js | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 84a982e..b97000a 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ On the builder following methods can be called: ### .withContent(markdownString) Put some **Markdown** content to the generated books README.md (initial/intro page). -### .withPage(pageName, pageContent) +### .withPage(pageName, pageContent[, level]) Add another book page. Usage like ```js .withPage('second', 'Second page content') @@ -64,6 +64,7 @@ it('should add second book page', function(testDone) { }); ``` +**Level**: how nested should be this page, optional parameter. ```0``` for top level page, ```1``` for second, ```2``` for third... ### .withBookJson(jsObject) Put your own ```book.json``` content as a JS object. May contain plugins, diff --git a/lib/tester.js b/lib/tester.js index 22e654f..7b39dad 100644 --- a/lib/tester.js +++ b/lib/tester.js @@ -26,7 +26,8 @@ var createBook = function(content, children) { .then(function(dirPath) { var summaryPages = children.map(function(page){ - return '* ['+page.name+']('+page.name+'.md)'; + var padding = Array(page.level * 4).join(' '); + return padding + '* ['+page.name+']('+page.name+'.md)'; }); var pagesPromises = children.map(function(page) { @@ -246,9 +247,12 @@ Builder.prototype.withContent = function(content) { return this; }; -// attach Markdown content to book (currently only to README.md - single page book) -Builder.prototype.withPage = function(name, content) { - this._pages.push({name:name, content:content}); +// attach Markdown content to book +Builder.prototype.withPage = function(name, content, level) { + if(isNaN(level)) { + level = 0; + } + this._pages.push({name:name, content:content, level:level}); return this; };