summaryrefslogtreecommitdiffstats
path: root/lib/book.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/book.js')
-rw-r--r--lib/book.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/lib/book.js b/lib/book.js
index bde30da..a2bd40b 100644
--- a/lib/book.js
+++ b/lib/book.js
@@ -237,6 +237,59 @@ Book.prototype.generateMultiLingual = function(generator) {
});
};
+// Extract files from ebook generated
+Book.prototype.generateFile = function(output, options) {
+ var book = this;
+
+ options = _.defaults(options || {}, {
+ ebookFormat: path.extname(output).slice(1)
+ });
+ output = output || path.resolve(book.root, "book."+options.ebookFormat);
+
+ return fs.tmp.dir()
+ .then(function(tmpDir) {
+ book.config.extend({
+ output: tmpDir
+ });
+
+ return book.generate(options.ebookFormat)
+ .then(function(_options) {
+ var copyFile = function(lang) {
+ var _outputFile = output;
+ var _tmpDir = tmpDir;
+
+ if (lang) {
+ _outputFile = _outputFile.slice(0, -path.extname(_outputFile).length)+"_"+lang+path.extname(_outputFile);
+ _tmpDir = path.join(_tmpDir, lang);
+ }
+
+ book.logInfo("copy ebook to", output);
+ return fs.copy(
+ path.join(_tmpDir, "index."+options.ebookFormat),
+ _outputFile
+ );
+ };
+
+ // Multi-langs book
+ return Q()
+ .then(function() {
+ if (book.isMultilingual()) {
+ return Q.all(
+ _.map(book.langs, function(lang) {
+ return copyFile(lang.lang);
+ })
+ );
+ } else {
+ return copyFile();
+ }
+ })
+ .then(function() {
+ return fs.remove(tmpDir);
+ });
+ });
+ });
+};
+
// Parse list of plugins
Book.prototype.parsePlugins = function() {
var that = this;