summaryrefslogtreecommitdiffstats
path: root/lib/plugins/plugin.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/plugins/plugin.js')
-rw-r--r--lib/plugins/plugin.js47
1 files changed, 32 insertions, 15 deletions
diff --git a/lib/plugins/plugin.js b/lib/plugins/plugin.js
index 094c82d..7fb44b2 100644
--- a/lib/plugins/plugin.js
+++ b/lib/plugins/plugin.js
@@ -34,6 +34,9 @@ function BookPlugin(book, pluginId) {
this.packageInfos = undefined;
this.content = undefined;
+ // Cache for resources
+ this._resources = {};
+
_.bindAll(this);
}
@@ -191,25 +194,37 @@ BookPlugin.prototype.hook = function(name, input) {
// Return resources without normalization
BookPlugin.prototype._getResources = function(base) {
- base = base;
- var book = this.content[base];
+ var that = this;
+
+ return Promise()
+ .then(function() {
+ if (that._resources[base]) return that._resources[base];
- // Compatibility with version 1.x.x
- if (base == 'website') book = book || this.content.book;
+ base = base;
+ var book = that.content[base];
- // Nothing specified, fallback to default
- if (!book) {
- return Promise({});
- }
+ // Compatibility with version 1.x.x
+ if (base == 'website') book = book || that.content.book;
- // Dynamic function
- if(typeof book === 'function') {
- // Call giving it the context of our book
- return Promise().then(book.bind(this.book));
- }
+ // Nothing specified, fallback to default
+ if (!book) {
+ return Promise({});
+ }
- // Plain data object
- return Promise(_.cloneDeep(book));
+ // Dynamic function
+ if(typeof book === 'function') {
+ // Call giving it the context of our book
+ return book.call(that.book);
+ }
+
+ // Plain data object
+ return book;
+ })
+
+ .then(function(resources) {
+ that._resources[base] = resources;
+ return _.cloneDeep(resources);
+ });
};
// Normalize a specific resource
@@ -256,3 +271,5 @@ BookPlugin.prototype.getBlocks = function() {
};
module.exports = BookPlugin;
+module.exports.RESOURCES = RESOURCES;
+