diff options
Diffstat (limited to 'lib/book.js')
-rw-r--r-- | lib/book.js | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/book.js b/lib/book.js index c81d255..86b1d67 100644 --- a/lib/book.js +++ b/lib/book.js @@ -328,4 +328,30 @@ Book.prototype.isInLanguageBook = function(filename) { }); }; +// Locate a book in a folder +// - Read the ".gitbook" is exists +// - Try the folder itself +// - Try a "docs" folder +Book.locate = function(fs, root) { + return fs.readAsString(path.join(root, '.gitbook')) + .then(function(content) { + return path.join(root, content); + }, function() { + // .gitbook doesn't exists, fall back to the root folder + return Promise(root); + }); +}; + +// Locate and setup a book +Book.setup = function(fs, root, opts) { + return Book.locate(fs, root) + .then(function(_root) { + return new Book(_.extend(opts || {}, { + root: _root, + fs: fs + })); + }); +}; + + module.exports = Book; |