diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-02-29 17:35:12 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-02-29 17:35:12 +0100 |
commit | ec353e179dedf1ebf1ab6e54f6217a88d087ea75 (patch) | |
tree | 4a6e90f89a56ea571c0a090e6a524f760da8aa3b /lib | |
parent | 496f253e698f1224fa9f9cf88670648ff3930d7a (diff) | |
download | gitbook-ec353e179dedf1ebf1ab6e54f6217a88d087ea75.zip gitbook-ec353e179dedf1ebf1ab6e54f6217a88d087ea75.tar.gz gitbook-ec353e179dedf1ebf1ab6e54f6217a88d087ea75.tar.bz2 |
Remove .gitbook and add "root" option
Diffstat (limited to 'lib')
-rw-r--r-- | lib/book.js | 44 | ||||
-rw-r--r-- | lib/cli/helper.js | 9 | ||||
-rw-r--r-- | lib/cli/index.js | 41 | ||||
-rw-r--r-- | lib/config/schema.js | 4 |
4 files changed, 46 insertions, 52 deletions
diff --git a/lib/book.js b/lib/book.js index 09bd59f..ca8c0c0 100644 --- a/lib/book.js +++ b/lib/book.js @@ -123,7 +123,16 @@ Book.prototype.getContext = function() { // Parse and prepare the configuration, fail if invalid Book.prototype.prepareConfig = function() { - return this.config.load(); + var that = this; + + return this.config.load() + .then(function() { + var root = that.config.get('root'); + if (!root) return; + + that.originalRoot = that.root; + that.root = path.resolve(that.root, root); + }) }; // Resolve a path in the book source @@ -344,35 +353,14 @@ 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 - })); - }); -}; - // Initialize a book Book.init = function(fs, root, opts) { - return Book.setup(fs, root, opts) - .then(initBook); + var book = new Book(_.extend(opts || {}, { + root: root, + fs: fs + })); + + return initBook(book); }; diff --git a/lib/cli/helper.js b/lib/cli/helper.js index e4dc8da..818fd0c 100644 --- a/lib/cli/helper.js +++ b/lib/cli/helper.js @@ -42,12 +42,13 @@ var FORMATS = { function bookCmd(fn) { return function(args, kwargs) { var input = path.resolve(args[0] || process.cwd()); - return Book.setup(nodeFS, input, { + var book = new Book({ + fs: nodeFS, + root: input, logLevel: kwargs.log - }) - .then(function(book) { - return fn(book, args.slice(1), kwargs); }); + + return fn(book, args.slice(1), kwargs); }; } diff --git a/lib/cli/index.js b/lib/cli/index.js index f1aca5e..cf0f73f 100644 --- a/lib/cli/index.js +++ b/lib/cli/index.js @@ -131,26 +131,27 @@ module.exports = { // Generate the book .then(function() { - return Book.setup(helper.nodeFS, input, { - 'logLevel': kwargs.log - }) - .then(function(book) { - return book.parse() - .then(function() { - // Add livereload plugin - book.config.set('plugins', - book.config.get('plugins') - .concat([ - { name: 'livereload' } - ]) - ); - - var Out = helper.FORMATS[kwargs.format]; - var output = new Out(book); - - return output.generate() - .thenResolve(output); - }); + var book = new Book({ + fs: helper.nodeFS, + root: input, + logLevel: kwargs.log + }); + + return book.parse() + .then(function() { + // Add livereload plugin + book.config.set('plugins', + book.config.get('plugins') + .concat([ + { name: 'livereload' } + ]) + ); + + var Out = helper.FORMATS[kwargs.format]; + var output = new Out(book); + + return output.generate() + .thenResolve(output); }); }) diff --git a/lib/config/schema.js b/lib/config/schema.js index 34a6c76..d3088f5 100644 --- a/lib/config/schema.js +++ b/lib/config/schema.js @@ -4,6 +4,10 @@ module.exports = { 'title': 'GitBook Configuration', 'type': 'object', 'properties': { + 'root': { + 'type': 'string', + 'title': 'Path fro the root folder containing the book\'s content' + }, 'title': { 'type': 'string', 'title': 'Title of the book, default is extracted from README' |