Load plugins once

This commit is contained in:
Samy Pessé
2016-02-24 16:53:33 +01:00
parent c223f970ec
commit 40cc20e06e
+9 -4
View File
@@ -15,8 +15,9 @@ to output "something".
The process is mostly on the behavior of "onPage" and "onAsset"
*/
function Output(book, opts) {
function Output(book, opts, parent) {
_.bindAll(this);
this.parent = parent;
this.opts = _.defaults(opts || {}, {
directoryIndex: true
@@ -26,7 +27,11 @@ function Output(book, opts) {
this.log = this.book.log;
// Create plugins manager
this.plugins = new PluginsManager(this.book);
if (this.parent) {
this.plugins = this.parent.plugins;
} else {
this.plugins = new PluginsManager(this.book);
}
// Create template engine
this.template = new TemplateEngine(this);
@@ -47,7 +52,7 @@ Output.prototype.generate = function() {
// Load all plugins
.then(function() {
return that.plugins.loadAll()
return Promise(that.parent? null: that.plugins.loadAll())
.then(function() {
that.template.addFilters(that.plugins.getFilters());
that.template.addBlocks(that.plugins.getBlocks());
@@ -191,7 +196,7 @@ Output.prototype.onResolveTemplate = function(from, to) {
// Prepare output for a language book
Output.prototype.onLanguageBook = function(book) {
return new this.constructor(book, this.opts);
return new this.constructor(book, this.opts, this);
};