mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-23 19:06:31 +00:00
Add immutable ignore instance for book
This commit is contained in:
+12
-4
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user