blob: d09f29de94344d7e3cf43084e0d159b422df22ff (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
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);
}
// Write a file to the output folder
Output.prototype.writeFile = function(filename, buf) {
};
// Start the generation, for a parsed book
Output.prototype.generate = function() {
var that = this;
var isMultilingual = this.isMultilingual();
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) {
// Ignore file present in a language book
if (isMultilingual && that.book.isInLanguageBook(filename)) return;
// Process file as page or asset
if (that.book.hasPage(filename)) {
return that.generator.writePage(that.book.getPage(filename));
} else {
return that.generator.writeAsset(filename);
}
});
})
// Finish the generation
.then(function() {
return that.generator.finish();
});
};
module.exports = Output;
|