summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-29 17:35:12 +0100
committerSamy Pessé <samypesse@gmail.com>2016-02-29 17:35:12 +0100
commitec353e179dedf1ebf1ab6e54f6217a88d087ea75 (patch)
tree4a6e90f89a56ea571c0a090e6a524f760da8aa3b
parent496f253e698f1224fa9f9cf88670648ff3930d7a (diff)
downloadgitbook-ec353e179dedf1ebf1ab6e54f6217a88d087ea75.zip
gitbook-ec353e179dedf1ebf1ab6e54f6217a88d087ea75.tar.gz
gitbook-ec353e179dedf1ebf1ab6e54f6217a88d087ea75.tar.bz2
Remove .gitbook and add "root" option
-rw-r--r--.gitbook1
-rw-r--r--book.js (renamed from docs/book.js)1
-rw-r--r--docs/config.md1
-rw-r--r--docs/structure.md10
-rw-r--r--lib/book.js44
-rw-r--r--lib/cli/helper.js9
-rw-r--r--lib/cli/index.js41
-rw-r--r--lib/config/schema.js4
-rw-r--r--test/config.js6
-rw-r--r--test/glossary.js4
-rw-r--r--test/langs.js2
-rw-r--r--test/locate.js27
-rw-r--r--test/plugins.js4
-rw-r--r--test/readme.js2
14 files changed, 80 insertions, 76 deletions
diff --git a/.gitbook b/.gitbook
deleted file mode 100644
index ffcee85..0000000
--- a/.gitbook
+++ /dev/null
@@ -1 +0,0 @@
-./docs \ No newline at end of file
diff --git a/docs/book.js b/book.js
index 988abb2..796f79d 100644
--- a/docs/book.js
+++ b/book.js
@@ -1,6 +1,7 @@
var pkg = require('../package.json');
module.exports = {
+ root: './docs',
title: 'GitBook Documentation',
plugins: ['theme-official'],
diff --git a/docs/config.md b/docs/config.md
index 060a9d0..41dab1d 100644
--- a/docs/config.md
+++ b/docs/config.md
@@ -6,6 +6,7 @@ GitBook allows you to customize your book using a flexible configuration. These
| Variable | Description |
| -------- | ----------- |
+| `root` | Path to the root folder containing the content |
| `title` | Title of your book, default value is extracted from the README. On GitBook.com this field is pre-filled. |
| `description` | Description of your book, default value is extracted from the README. On GitBook.com this field is pre-filled. |
| `author` | Name of the author. On GitBook.com this field is pre-filled. |
diff --git a/docs/structure.md b/docs/structure.md
index 31b00f6..ca35c01 100644
--- a/docs/structure.md
+++ b/docs/structure.md
@@ -45,18 +45,20 @@ bin/*
### Project documentation / Sub-directory {#subdirectory}
-For project documentaiton, it sometimes better to use a diretcory (like `docs/`) to store the prject's documentation. You can use a `.gitbook` file to indicate to GitBook in which folder the book is stored:
+For software project, it sometimes better to use a diretcory (like `docs/`) to store the project's documentation. You can use the [`root` option](config.md) to indicate to GitBook in which folder the book is stored:
```
.
-├── .gitbook
+├── book.json
└── docs/
├── README.md
└── SUMMARY.md
```
-With `.gitbook` containing:
+With `book.json` containing:
```
-./docs/
+{
+ "root": "./docs"
+}
```
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'
diff --git a/test/config.js b/test/config.js
index be28fc9..d997c46 100644
--- a/test/config.js
+++ b/test/config.js
@@ -46,7 +46,7 @@ describe('Configuration', function() {
return mock.setupDefaultBook()
.then(function(_book) {
book = _book;
- return book.config.load();
+ return book.prepareConfig();
});
});
@@ -64,7 +64,7 @@ describe('Configuration', function() {
})
.then(function(_book) {
book = _book;
- return book.config.load();
+ return book.prepareConfig();
});
});
@@ -82,7 +82,7 @@ describe('Configuration', function() {
})
.then(function(_book) {
book = _book;
- return book.config.load();
+ return book.prepareConfig();
});
});
diff --git a/test/glossary.js b/test/glossary.js
index d6d1af6..e1ba82a 100644
--- a/test/glossary.js
+++ b/test/glossary.js
@@ -7,7 +7,7 @@ describe('Glossary', function() {
'GLOSSARY.md': ''
})
.then(function(book) {
- return book.config.load()
+ return book.prepareConfig()
.then(function() {
return book.glossary.load();
@@ -27,7 +27,7 @@ describe('Glossary', function() {
})
.then(function(_book) {
book = _book;
- return book.config.load();
+ return book.prepareConfig();
})
.then(function() {
return book.glossary.load();
diff --git a/test/langs.js b/test/langs.js
index 91dbd5a..dbde992 100644
--- a/test/langs.js
+++ b/test/langs.js
@@ -6,7 +6,7 @@ describe('Langs', function() {
'LANGS.md': ''
})
.then(function(book) {
- return book.config.load()
+ return book.prepareConfig()
.then(function() {
return book.langs.load();
diff --git a/test/locate.js b/test/locate.js
index 609f2da..2b6a574 100644
--- a/test/locate.js
+++ b/test/locate.js
@@ -1,27 +1,34 @@
var path = require('path');
+var should = require('should');
var Book = require('../').Book;
var mock = require('./mock');
describe('Locate', function() {
it('should use root folder if no .gitbook', function() {
- return mock.setupFS({
+ return mock.setupBook({
'README.md': '# Hello'
})
- .then(function(root) {
- return Book.locate(mock.fs, root)
- .should.be.fulfilledWith(root);
+ .then(function(book) {
+ return book.prepareConfig()
+ .then(function() {
+ should(book.originalRoot).not.be.ok();
+ });
});
});
- it('should use resolve using .gitbook', function() {
- return mock.setupFS({
+ it('should use resolve using book.js root property', function() {
+ return mock.setupBook({
'README.md': '# Hello',
- '.gitbook': './docs'
+ 'docs/README.md': '# Hello Book',
+ 'book.json': { root: './docs' }
})
- .then(function(root) {
- return Book.locate(mock.fs, root)
- .should.be.fulfilledWith(path.resolve(root, 'docs'));
+ .then(function(book) {
+ return book.prepareConfig()
+ .then(function() {
+ should(book.originalRoot).be.ok();
+ book.root.should.equal(path.resolve(book.originalRoot, 'docs'));
+ });
});
});
diff --git a/test/plugins.js b/test/plugins.js
index 4d9cdf1..b85e507 100644
--- a/test/plugins.js
+++ b/test/plugins.js
@@ -53,7 +53,7 @@ describe('Plugins', function() {
}
})
.then(function(book) {
- return book.config.load()
+ return book.prepareConfig()
.then(function() {
var plugins = new PluginsManager(book);
return plugins.install();
@@ -90,7 +90,7 @@ describe('Plugins', function() {
}
})
.then(function(book2) {
- return book2.config.load()
+ return book2.prepareConfig()
.then(function() {
var plugin = new BookPlugin(book2, 'test-config');
return plugin.load(PLUGINS_ROOT);
diff --git a/test/readme.js b/test/readme.js
index 0cf66ff..16aa81a 100644
--- a/test/readme.js
+++ b/test/readme.js
@@ -6,7 +6,7 @@ describe('Readme', function() {
'README.md': ''
})
.then(function(book) {
- return book.config.load()
+ return book.prepareConfig()
.then(function() {
return book.readme.load();