Add immutable ignore instance for book

This commit is contained in:
Samy Pesse
2016-05-11 12:59:16 +02:00
parent 0b4df4cdf2
commit d5c4af3377
4 changed files with 60 additions and 8 deletions
+12 -4
View File
@@ -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);
};
/**
@@ -221,6 +219,16 @@ Book.prototype.setConfig = function(config) {
return this.set('config', 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
+42
View File
@@ -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;
+1 -1
View File
@@ -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);
+5 -3
View File
@@ -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;