summaryrefslogtreecommitdiffstats
path: root/lib/output.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-01-27 10:24:06 +0100
committerSamy Pessé <samypesse@gmail.com>2016-01-27 10:24:06 +0100
commitf305d57ab7702c3ca10fd6e32366d19e524ee1f0 (patch)
tree381ccb09c7cedc72cdf8ad6c98b681b72f4d1bc0 /lib/output.js
parent877f2e477b010f9f37a9044606f110a90f077680 (diff)
downloadgitbook-f305d57ab7702c3ca10fd6e32366d19e524ee1f0.zip
gitbook-f305d57ab7702c3ca10fd6e32366d19e524ee1f0.tar.gz
gitbook-f305d57ab7702c3ca10fd6e32366d19e524ee1f0.tar.bz2
Add more classes structures
Diffstat (limited to 'lib/output.js')
-rw-r--r--lib/output.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/output.js b/lib/output.js
new file mode 100644
index 0000000..2f40fb6
--- /dev/null
+++ b/lib/output.js
@@ -0,0 +1,47 @@
+var Promise = require('utils/promise');
+var generators = require('./generators');
+var PluginsManager = require('./plugins');
+
+function Output(book, type) {
+ if (!generators[type]) throw new Error('Generator not found"' + type + '"');
+
+ this.book = book;
+ this.type = type;
+ this.plugins = new PluginsManager(book);
+ this.generator = new generators[type](this, type);
+}
+
+// Start the generation, for a parsed book
+Output.prototype.generate = function() {
+ var that = this;
+
+ return Promise()
+
+ // Initialize the generation
+ .then(function() {
+ return that.generator.prepare();
+ })
+
+ // Process all files
+ .then(function() {
+ return that.book.fs.listAllFiles(that.book.root);
+ })
+ .then(function(files) {
+ return Promise.serie(files, function(filename) {
+ var isPage = that.book.hasPage(filename);
+
+ if (isPage) {
+ return that.generator.writePage(that.book.getPage(filename));
+ } else {
+ return that.generator.writeFile(filename);
+ }
+ });
+ })
+
+ // Finish the generation
+ .then(function() {
+ return that.generator.finish();
+ });
+};
+
+module.exports = Output;