diff options
-rw-r--r-- | lib/index.js | 1 | ||||
-rw-r--r-- | lib/pluginslist.js | 2 | ||||
-rw-r--r-- | lib/utils/logger.js | 5 | ||||
-rw-r--r-- | test/helper.js | 3 | ||||
-rw-r--r-- | test/plugins.js | 27 | ||||
-rw-r--r-- | test/plugins/resources/index.js | 7 | ||||
-rw-r--r-- | test/plugins/resources/package.json | 9 |
7 files changed, 50 insertions, 4 deletions
diff --git a/lib/index.js b/lib/index.js index 35322fb..26a47d5 100644 --- a/lib/index.js +++ b/lib/index.js @@ -27,6 +27,7 @@ var FORMAT_OPTION = { module.exports = { Book: Book, + LOG_LEVELS: logger.LEVELS, commands: _.flatten([ { diff --git a/lib/pluginslist.js b/lib/pluginslist.js index 35ba8c3..2101c6f 100644 --- a/lib/pluginslist.js +++ b/lib/pluginslist.js @@ -80,7 +80,7 @@ PluginsList.prototype.load = function(plugin, options) { .then(function(plResources) { // Extract js and css _.each(Plugin.RESOURCES, function(resourceType) { - that.resources[resourceType].concat(plResources[resourceType] || []); + that.resources[resourceType] = that.resources[resourceType].concat(plResources[resourceType] || []); }); // Map of html resources by name added by each plugin diff --git a/lib/utils/logger.js b/lib/utils/logger.js index 9ef9ccf..064c196 100644 --- a/lib/utils/logger.js +++ b/lib/utils/logger.js @@ -6,7 +6,8 @@ var LEVELS = { DEBUG: 0, INFO: 1, WARN: 2, - ERROR: 3 + ERROR: 3, + DISABLED: 10 }; var COLORS = { @@ -76,7 +77,7 @@ module.exports = function(_write, logLevel) { return logger.log(level, color.red("ERROR")+"\n"); }; - _.each(LEVELS, function(level, levelKey) { + _.each(_.omit(LEVELS, 'DISABLED'), function(level, levelKey) { levelKey = levelKey.toLowerCase(); logger[levelKey] = _.partial(logger.log, level); diff --git a/test/helper.js b/test/helper.js index fbdd85c..5e16bc0 100644 --- a/test/helper.js +++ b/test/helper.js @@ -5,6 +5,7 @@ var _ = require('lodash'); var fsUtil = require("../lib/utils/fs"); var Book = require('../').Book; +var LOG_LEVELS = require('../').LOG_LEVELS; // Nicety for mocha / Q global.qdone = function qdone(promise, done) { @@ -38,7 +39,7 @@ global.books = _.chain(books) .map(function(book) { if (book.indexOf("test") !== 0) return null; return new Book(path.join(__dirname, './fixtures/', book), { - logLevel: Book.LOG_LEVELS.DISABLED + logLevel: LOG_LEVELS.DISABLED }); }) .compact() diff --git a/test/plugins.js b/test/plugins.js index 78f5b44..f72f719 100644 --- a/test/plugins.js +++ b/test/plugins.js @@ -36,6 +36,33 @@ describe('Plugins', function () { }); }); + describe('resources plugin', function() { + var plugin = new Plugin(books[0], "resources"); + plugin.load("./resources", PLUGINS_ROOT); + + before(function(done) { + qdone(books[0].plugins.load(plugin), done); + }); + + it('should valid a plugin', function() { + assert(plugin.isValid()); + }); + + it('should return a valid list of resources', function(done) { + qdone( + plugin.getResources() + .then(function(resources) { + assert.equal(resources["js"].length, 1); + }), + done); + }); + + it('should extend books plugins', function() { + var resources = books[0].plugins.resources; + assert.equal(resources["js"].length, 1); + }); + }); + describe('filters', function() { var plugin = new Plugin(books[0], "filters"); plugin.load("./filters", PLUGINS_ROOT); diff --git a/test/plugins/resources/index.js b/test/plugins/resources/index.js new file mode 100644 index 0000000..68b3c39 --- /dev/null +++ b/test/plugins/resources/index.js @@ -0,0 +1,7 @@ +module.exports = { + book: { + js: [ + "https://cdn.mathjax.org/mathjax/2.4-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" + ] + } +}; diff --git a/test/plugins/resources/package.json b/test/plugins/resources/package.json new file mode 100644 index 0000000..ab4320d --- /dev/null +++ b/test/plugins/resources/package.json @@ -0,0 +1,9 @@ +{ + "name": "gitbook-plugin-resources", + "description": "Test resources plugin", + "main": "index.js", + "version": "0.0.1", + "engines": { + "gitbook": "*" + } +}
\ No newline at end of file |