mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-23 19:06:31 +00:00
Load plugins once
This commit is contained in:
+9
-4
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user