summaryrefslogtreecommitdiffstats
path: root/lib/book.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-23 15:05:32 +0100
committerSamy Pessé <samypesse@gmail.com>2016-02-23 15:05:32 +0100
commitf052aacee1140f211ebb9454157fa7a3604005cf (patch)
treef784d8b9fd70bd94b754e13d26e6f6dd548b9908 /lib/book.js
parent13e2ff8035d9a93e4ee8eb79ec71ac92e6f2bf7e (diff)
downloadgitbook-f052aacee1140f211ebb9454157fa7a3604005cf.zip
gitbook-f052aacee1140f211ebb9454157fa7a3604005cf.tar.gz
gitbook-f052aacee1140f211ebb9454157fa7a3604005cf.tar.bz2
Add .gitbook to locate book inside repository
Diffstat (limited to 'lib/book.js')
-rw-r--r--lib/book.js26
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;