summaryrefslogtreecommitdiffstats
path: root/lib/book.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-01-27 22:48:23 +0100
committerSamy Pessé <samypesse@gmail.com>2016-01-27 22:48:23 +0100
commitddc99104d4394cc21eaa615b01d73ec001ac7a16 (patch)
tree9855406d0a162cf744576c91501480f0450324c7 /lib/book.js
parent8d277e9108afa6a027c61feb581a2150958f8571 (diff)
downloadgitbook-ddc99104d4394cc21eaa615b01d73ec001ac7a16.zip
gitbook-ddc99104d4394cc21eaa615b01d73ec001ac7a16.tar.gz
gitbook-ddc99104d4394cc21eaa615b01d73ec001ac7a16.tar.bz2
Add unit tests for glossary parsing
Diffstat (limited to 'lib/book.js')
-rw-r--r--lib/book.js20
1 files changed, 9 insertions, 11 deletions
diff --git a/lib/book.js b/lib/book.js
index 91dfa02..77539ce 100644
--- a/lib/book.js
+++ b/lib/book.js
@@ -1,5 +1,4 @@
var _ = require('lodash');
-var Q = require('q');
var path = require('path');
var Ignore = require('ignore');
var parsers = require('gitbook-parsers');
@@ -12,6 +11,7 @@ var Summary = require('./backbone/summary');
var Langs = require('./backbone/langs');
var Page = require('./backbone/page');
var pathUtil = require('./utils/path');
+var Promise = require('./utils/promise');
function Book(opts) {
if (!(this instanceof Book)) return new Book(opts);
@@ -106,25 +106,23 @@ Book.prototype.resolve = function() {
Book.prototype.parseIgnoreRules = function() {
var that = this;
- return _.reduce([
+ return Promise.series([
'.ignore',
'.gitignore',
'.bookignore'
- ], function(prev, filename) {
- return prev.then(function() {
- return that.readFile(filename);
- })
+ ], function(filename) {
+ return that.readFile(filename)
.then(function(content) {
that.ignore.addPattern(content.toString().split(/\r?\n/));
});
- }, Q());
+ });
};
// Parse the whole book
Book.prototype.parse = function() {
var that = this;
- return Q()
+ return Promise()
.then(this.prepareConfig)
.then(this.parseIgnoreRules)
@@ -139,7 +137,7 @@ Book.prototype.parse = function() {
return;
}
- return Q()
+ return Promise()
.then(that.readme.load)
.then(function() {
if (that.readme.exists()) return;
@@ -185,7 +183,7 @@ Book.prototype.isFileIgnored = function(filename) {
// Read a file in the book, throw error if ignored
Book.prototype.readFile = function(filename) {
- if (this.isFileIgnored(filename)) return Q.reject(new Error('File "'+filename+'" is ignored'));
+ if (this.isFileIgnored(filename)) return Promise.reject(new Error('File "'+filename+'" is ignored'));
return this.fs.readAsString(this.resolve(filename));
};
@@ -217,7 +215,7 @@ Book.prototype.findParsableFile = function(filename) {
};
});
});
- }, Q(null));
+ }, Promise(null));
};
// Return true if book is associated to a language