diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-05-11 12:59:16 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-05-11 13:02:24 +0200 |
commit | d5c4af337795ca5c3d4e6f516aeaef15d51c4e8c (patch) | |
tree | 3c140ee30aadb820e07003ef4ab6f89d42323ae1 /lib/models | |
parent | 0b4df4cdf2dc9ed18805358216439b595997fdc7 (diff) | |
download | gitbook-d5c4af337795ca5c3d4e6f516aeaef15d51c4e8c.zip gitbook-d5c4af337795ca5c3d4e6f516aeaef15d51c4e8c.tar.gz gitbook-d5c4af337795ca5c3d4e6f516aeaef15d51c4e8c.tar.bz2 |
Add immutable ignore instance for book
Diffstat (limited to 'lib/models')
-rw-r--r-- | lib/models/book.js | 16 | ||||
-rw-r--r-- | lib/models/ignore.js | 42 |
2 files changed, 54 insertions, 4 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; |