summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-05-11 12:59:16 +0200
committerSamy Pesse <samypesse@gmail.com>2016-05-11 13:02:24 +0200
commitd5c4af337795ca5c3d4e6f516aeaef15d51c4e8c (patch)
tree3c140ee30aadb820e07003ef4ab6f89d42323ae1
parent0b4df4cdf2dc9ed18805358216439b595997fdc7 (diff)
downloadgitbook-d5c4af337795ca5c3d4e6f516aeaef15d51c4e8c.zip
gitbook-d5c4af337795ca5c3d4e6f516aeaef15d51c4e8c.tar.gz
gitbook-d5c4af337795ca5c3d4e6f516aeaef15d51c4e8c.tar.bz2
Add immutable ignore instance for book
-rw-r--r--lib/models/book.js16
-rw-r--r--lib/models/ignore.js42
-rw-r--r--lib/parse/parseBook.js2
-rw-r--r--lib/parse/parseIgnore.js8
4 files changed, 60 insertions, 8 deletions
diff --git a/lib/models/book.js b/lib/models/book.js
index e39897b..b36f77f 100644
--- a/lib/models/book.js
+++ b/lib/models/book.js
@@ -1,6 +1,5 @@
var path = require('path');
var Immutable = require('immutable');
-var Ignore = require('ignore');
var Logger = require('../utils/logger');
@@ -10,7 +9,7 @@ var Readme = require('./readme');
var Summary = require('./summary');
var Glossary = require('./glossary');
var Languages = require('./languages');
-
+var Ignore = require('./ignore');
var Book = Immutable.Record({
// Logger for outptu message
@@ -128,8 +127,7 @@ Book.prototype.isFileIgnored = function(filename) {
filename = path.join(language, filename);
}
-
- return ignore.filter([filename]).length == 0;
+ return ignore.isFileIgnored(filename);
};
/**
@@ -222,6 +220,16 @@ Book.prototype.setConfig = function(config) {
};
/**
+ Set the ignore instance for this book
+
+ @param {Ignore}
+ @return {Book}
+*/
+Book.prototype.setIgnore = function(ignore) {
+ return this.set('ignore', ignore);
+};
+
+/**
Change log level
@param {String} level
diff --git a/lib/models/ignore.js b/lib/models/ignore.js
new file mode 100644
index 0000000..499195e
--- /dev/null
+++ b/lib/models/ignore.js
@@ -0,0 +1,42 @@
+var Immutable = require('immutable');
+var IgnoreMutable = require('ignore');
+
+/*
+ Immutable version of node-ignore
+*/
+var Ignore = Immutable.Record({
+ ignore: new IgnoreMutable()
+}, 'Ignore');
+
+Ignore.prototype.getIgnore = function() {
+ return this.get('ignore');
+};
+
+/**
+ Test if a file is ignored by these rules
+
+ @param {String} filePath
+ @return {Boolean}
+*/
+Ignore.prototype.isFileIgnored = function(filename) {
+ var ignore = this.getIgnore();
+ return ignore.filter([filename]).length == 0;
+};
+
+/**
+ Add rules
+
+ @param {String}
+ @return {Ignore}
+*/
+Ignore.prototype.add = function(rule) {
+ var ignore = this.getIgnore();
+ var newIgnore = new IgnoreMutable();
+
+ newIgnore.add(ignore);
+ newIgnore.add(rule);
+
+ return this.set('ignore', newIgnore);
+};
+
+module.exports = Ignore;
diff --git a/lib/parse/parseBook.js b/lib/parse/parseBook.js
index 84a4038..a92f39e 100644
--- a/lib/parse/parseBook.js
+++ b/lib/parse/parseBook.js
@@ -42,7 +42,7 @@ function parseMultilingualBook(book) {
.then(parseBookContent)
.then(function(result) {
// Ignore content of this book when generating parent book
- ignore.add(langID + '/**');
+ ignore = ignore.add(langID + '/**');
currentBook = currentBook.set('ignore', ignore);
return currentBook.addLanguageBook(langID, result);
diff --git a/lib/parse/parseIgnore.js b/lib/parse/parseIgnore.js
index fafcc6f..d13663d 100644
--- a/lib/parse/parseIgnore.js
+++ b/lib/parse/parseIgnore.js
@@ -15,7 +15,7 @@ function parseIgnore(book) {
var fs = book.getFS();
var ignore = book.getIgnore();
- ignore.addPattern([
+ ignore = ignore.add([
// Skip Git stuff
'.git/',
@@ -35,13 +35,15 @@ function parseIgnore(book) {
return Promise.serie(IGNORE_FILES, function(filename) {
return fs.readAsString(filename)
.then(function(content) {
- ignore.addPattern(content.toString().split(/\r?\n/));
+ ignore = ignore.add(content.toString().split(/\r?\n/));
}, function(err) {
return Promise();
});
})
- .thenResolve(book);
+ .then(function() {
+ return book.setIgnore(ignore);
+ });
}
module.exports = parseIgnore;