summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-01-19 16:00:12 +0100
committerSamy Pessé <samypesse@gmail.com>2015-01-19 16:00:12 +0100
commit5ed584449007d9c6c816e765ce3e999e14abbf97 (patch)
treef8db5ec4357bd93a541412748997056dc83165bc /lib
parent777963c97c41094555b1ea94b351adf380637922 (diff)
downloadgitbook-5ed584449007d9c6c816e765ce3e999e14abbf97.zip
gitbook-5ed584449007d9c6c816e765ce3e999e14abbf97.tar.gz
gitbook-5ed584449007d9c6c816e765ce3e999e14abbf97.tar.bz2
Parse list of files and add test for it
Diffstat (limited to 'lib')
-rw-r--r--lib/book.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/book.js b/lib/book.js
index df19f74..8fbac81 100644
--- a/lib/book.js
+++ b/lib/book.js
@@ -36,6 +36,9 @@ var Book = function(root, options, parent) {
// Sub-books
this.books = [];
+
+ // Files in the book
+ this.files = [];
};
// Initialize and parse the book: config, summary, glossary
@@ -76,6 +79,10 @@ Book.prototype.parse = function() {
if (multilingal) return;
return that.parseGlossary();
})
+ .then(function() {
+ if (multilingal) return;
+ return that.listAllFiles();
+ })
.then(function() {
// Init sub-books
@@ -92,10 +99,28 @@ Book.prototype.parse = function() {
// Generate the output
Book.prototype.generate = function() {
var that = this;
+ if (that.isMultilingual()) return that.generateMultiLingual();
return Q()
+
+ // Clean output folder
.then(function() {
+ return fs.clean(that.options.output);
+ });
+};
+// Generate the output for a multilingual book
+Book.prototype.generateMultiLingual = function() {
+ var that = this;
+
+ return Q()
+ .then(function() {
+ // Generate sub-books
+ return _.reduce(that.books, function(prev, book) {
+ return prev.then(function() {
+ return book.generate();
+ });
+ }, Q());
});
};
@@ -219,6 +244,16 @@ Book.prototype.statFile = function(filename) {
return fs.stat(path.join(this.root, filename));
};
+// List all files in the book
+Book.prototype.listAllFiles = function() {
+ var that = this;
+
+ return fs.list(this.root)
+ .then(function(_files) {
+ that.files = _files;
+ });
+};
+
// Retrun true if the book is a multilingual book
Book.prototype.isMultilingual = function(filename) {
return this.books.length > 0;