summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/book.js27
-rw-r--r--lib/generator.js12
-rw-r--r--lib/generators/json.js11
3 files changed, 30 insertions, 20 deletions
diff --git a/lib/book.js b/lib/book.js
index 73f3847..435e05c 100644
--- a/lib/book.js
+++ b/lib/book.js
@@ -107,27 +107,34 @@ Book.prototype.parse = function() {
};
// Generate the output
-Book.prototype.generate = function() {
+Book.prototype.generate = function(generator) {
var that = this, generator;
- if (that.isMultilingual()) return that.generateMultiLingual();
-
return Q()
// Clean output folder
.then(function() {
return fs.remove(that.options.output);
})
+ .then(function() {
+ return fs.mkdirp(that.options.output);
+ })
// Create generator
.then(function() {
- Generator = generators[that.options.generator];
- if (!Generator) throw "Generator '"+that.options.generator+"' doesn't exist";
+ generator = generator || that.options.generator;
+ var Generator = generators[generator];
+ if (!Generator) throw "Generator '"+generator+"' doesn't exist";
+ generator = new Generator(that);
+ })
+
+ .then(function() {
+ if (that.isMultilingual()) return that.generateMultiLingual(generator);
});
};
// Generate the output for a multilingual book
-Book.prototype.generateMultiLingual = function() {
+Book.prototype.generateMultiLingual = function(generator) {
var that = this;
return Q()
@@ -287,9 +294,15 @@ Book.prototype.listAllFiles = function() {
});
};
-// Retrun true if the book is a multilingual book
+// Return true if the book is a multilingual book
Book.prototype.isMultilingual = function(filename) {
return this.books.length > 0;
};
+// Return root of the parent
+Book.prototype.parentRoot = function() {
+ if (this.parent) return this.parent.parentRoot();
+ return this.root;
+};
+
module.exports= Book;
diff --git a/lib/generator.js b/lib/generator.js
index d0db3b6..32ce3b5 100644
--- a/lib/generator.js
+++ b/lib/generator.js
@@ -46,16 +46,16 @@ BaseGenerator.prototype.copyCover = function() {
var that = this;
return Q.all([
- fs.copy(path.join(this.options.input, "cover.jpg"), path.join(this.options.output, "cover.jpg")),
- fs.copy(path.join(this.options.input, "cover_small.jpg"), path.join(this.options.output, "cover_small.jpg"))
+ fs.copy(path.join(this.book.root, "cover.jpg"), path.join(this.options.output, "cover.jpg")),
+ fs.copy(path.join(this.book.root, "cover_small.jpg"), path.join(this.options.output, "cover_small.jpg"))
])
.fail(function() {
- // If orignally from multi-lang, try copy from originalInput
- if (!that.options.originalInput) return;
+ // If orignaly from multi-lang, try copy from parent
+ if (!that.isMultilingual()) return;
return Q.all([
- fs.copy(path.join(that.options.originalInput, "cover.jpg"), path.join(that.options.output, "cover.jpg")),
- fs.copy(path.join(that.options.originalInput, "cover_small.jpg"), path.join(that.options.output, "cover_small.jpg"))
+ fs.copy(path.join(that.book.parentRoot(), "cover.jpg"), path.join(that.options.output, "cover.jpg")),
+ fs.copy(path.join(that.book.parentRoot(), "cover_small.jpg"), path.join(that.options.output, "cover_small.jpg"))
]);
})
.fail(function(err) {
diff --git a/lib/generators/json.js b/lib/generators/json.js
index 4632a17..661e587 100644
--- a/lib/generators/json.js
+++ b/lib/generators/json.js
@@ -12,10 +12,11 @@ var Generator = function() {
};
util.inherits(Generator, BaseGenerator);
-Generator.prototype.transferFile = function(input) {
- // ignore
-};
+// Ignore soem methods
+Generator.prototype.transferFile = function(input) { };
+Generator.prototype.finish = function() { };
+// Convert an input file
Generator.prototype.convertFile = function(content, input) {
var that = this;
var json = {
@@ -69,8 +70,4 @@ Generator.prototype.langsIndex = function(langs) {
});
};
-Generator.prototype.finish = function() {
- // ignore
-};
-
module.exports = Generator;