From 40cc20e06e64a52ded4bd36ae4023000c9df2855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Wed, 24 Feb 2016 16:53:33 +0100 Subject: [PATCH] Load plugins once --- lib/output/base.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/output/base.js b/lib/output/base.js index fb0adca71..e0b58b404 100644 --- a/lib/output/base.js +++ b/lib/output/base.js @@ -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); };