summaryrefslogtreecommitdiffstats
path: root/lib/book.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/book.js')
-rw-r--r--lib/book.js55
1 files changed, 51 insertions, 4 deletions
diff --git a/lib/book.js b/lib/book.js
index 3bb5bf1..91dfa02 100644
--- a/lib/book.js
+++ b/lib/book.js
@@ -10,7 +10,7 @@ var Readme = require('./backbone/readme');
var Glossary = require('./backbone/glossary');
var Summary = require('./backbone/summary');
var Langs = require('./backbone/langs');
-var Page = require('./page');
+var Page = require('./backbone/page');
var pathUtil = require('./utils/path');
function Book(opts) {
@@ -47,7 +47,28 @@ function Book(opts) {
// Rules to ignore some files
this.ignore = Ignore();
- this.ignore.addPattern(['.git', '.svn', '.DS_Store']);
+ this.ignore.addPattern([
+ // Skip Git stuff
+ '.git/',
+ '.gitignore',
+
+ // Skip OS X meta data
+ '.DS_Store',
+
+ // Skip stuff installed by plugins
+ 'node_modules',
+
+ // Skip book outputs
+ '_book',
+ '*.pdf',
+ '*.epub',
+ '*.mobi',
+
+ // Skip config files
+ '.ignore',
+ '.bookignore',
+ 'book.json'
+ ]);
// Create a logger for the book
this.log = new Logger(opts.log, opts.logLevel);
@@ -59,9 +80,12 @@ function Book(opts) {
this.readme = new Readme(this);
this.summary = new Summary(this);
this.glossary = new Glossary(this);
+
+ // Multilinguals book
this.langs = new Langs(this);
+ this.books = [];
- // Map of pages in the bok
+ // List of page in the book
this.pages = {};
_.bindAll(this);
@@ -110,7 +134,10 @@ Book.prototype.parse = function() {
})
.then(function() {
- if (that.isMultilingual()) return;
+ if (that.isMultilingual()) {
+ that.log.info.ln('Parsing multilingual book, with', that.langs.count(), 'languages');
+ return;
+ }
return Q()
.then(that.readme.load)
@@ -131,6 +158,26 @@ Book.prototype.parse = function() {
});
};
+// Mark a filename as being parsable
+Book.prototype.addPage = function(filename) {
+ filename = pathUtil.normalize(filename);
+
+ if (this.pages[filename]) return;
+ this.pages[filename] = new Page(this, filename);
+};
+
+// Return a page by its filename (or undefined)
+Book.prototype.getPage = function(filename) {
+ filename = pathUtil.normalize(filename);
+ return this.pages[filename];
+};
+
+
+// Return true, if has a specific page
+Book.prototype.hasPage = function(filename) {
+ return Boolean(this.getPage(filename));
+};
+
// Test if a file is ignored, return true if it is
Book.prototype.isFileIgnored = function(filename) {
return this.ignore.filter([filename]).length == 0;