Skip to content

Commit

Permalink
page nesting / level support
Browse files Browse the repository at this point in the history
  • Loading branch information
todvora committed Apr 28, 2016
1 parent 2a26deb commit b5219ae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -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')
Expand All @@ -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,
Expand Down
12 changes: 8 additions & 4 deletions lib/tester.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
};

Expand Down

0 comments on commit b5219ae

Please sign in to comment.