summaryrefslogtreecommitdiffstats
path: root/lib/models
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-06-08 14:57:54 +0200
committerSamy Pessé <samypesse@gmail.com>2016-06-08 14:57:54 +0200
commite6c6ec4293fdf0bd225f1c6613ea484469fa98fd (patch)
tree31cfe8c67936b5f7713755aa7ea64c6d090ee06f /lib/models
parenta1d3acf065677607928eb71a11c89f6c6c7bb85b (diff)
downloadgitbook-e6c6ec4293fdf0bd225f1c6613ea484469fa98fd.zip
gitbook-e6c6ec4293fdf0bd225f1c6613ea484469fa98fd.tar.gz
gitbook-e6c6ec4293fdf0bd225f1c6613ea484469fa98fd.tar.bz2
Improve testing for sortPlugins
Diffstat (limited to 'lib/models')
-rw-r--r--lib/models/plugin.js82
1 files changed, 43 insertions, 39 deletions
diff --git a/lib/models/plugin.js b/lib/models/plugin.js
index e3d6c4d..c8bb2f7 100644
--- a/lib/models/plugin.js
+++ b/lib/models/plugin.js
@@ -1,9 +1,10 @@
var Immutable = require('immutable');
var TemplateBlock = require('./templateBlock');
-var DEFAULT_VERSION = '*';
-
var PluginDependency = require('./pluginDependency');
+var THEME_PREFIX = require('../constants/themePrefix');
+
+var DEFAULT_VERSION = '*';
var Plugin = Immutable.Record({
name: String(),
@@ -49,37 +50,43 @@ Plugin.prototype.getDepth = function() {
};
/**
- Return the ID on NPM for this plugin
-
- @return {String}
-*/
+ * Return the ID on NPM for this plugin
+ * @return {String}
+ */
Plugin.prototype.getNpmID = function() {
return PluginDependency.nameToNpmID(this.getName());
};
/**
- Check if a plugin is loaded
-
- @return {Boolean}
-*/
+ * Check if a plugin is loaded
+ * @return {Boolean}
+ */
Plugin.prototype.isLoaded = function() {
return Boolean(this.getPackage().size > 0);
};
/**
- Return map of hooks
- @return {Map<String:Function>}
-*/
+ * Check if a plugin is a theme given its name
+ * @return {Boolean}
+ */
+Plugin.prototype.isTheme = function() {
+ var name = this.getName();
+ return (name && name.indexOf(THEME_PREFIX) === 0);
+};
+
+/**
+ * Return map of hooks
+ * @return {Map<String:Function>}
+ */
Plugin.prototype.getHooks = function() {
return this.getContent().get('hooks') || Immutable.Map();
};
/**
- Return infos about resources for a specific type
-
- @param {String} type
- @return {Map<String:Mixed>}
-*/
+ * Return infos about resources for a specific type
+ * @param {String} type
+ * @return {Map<String:Mixed>}
+ */
Plugin.prototype.getResources = function(type) {
if (type != 'website' && type != 'ebook') {
throw new Error('Invalid assets type ' + type);
@@ -92,17 +99,17 @@ Plugin.prototype.getResources = function(type) {
};
/**
- Return map of filters
- @return {Map<String:Function>}
-*/
+ * Return map of filters
+ * @return {Map<String:Function>}
+ */
Plugin.prototype.getFilters = function() {
return this.getContent().get('filters');
};
/**
- Return map of blocks
- @return {Map<String:TemplateBlock>}
-*/
+ * Return map of blocks
+ * @return {Map<String:TemplateBlock>}
+ */
Plugin.prototype.getBlocks = function() {
var blocks = this.getContent().get('blocks');
blocks = blocks || Immutable.Map();
@@ -114,21 +121,19 @@ Plugin.prototype.getBlocks = function() {
};
/**
- Return a specific hook
-
- @param {String} name
- @return {Function|undefined}
-*/
+ * Return a specific hook
+ * @param {String} name
+ * @return {Function|undefined}
+ */
Plugin.prototype.getHook = function(name) {
return this.getHooks().get(name);
};
/**
- Create a plugin from a string
-
- @param {String}
- @return {Plugin}
-*/
+ * Create a plugin from a string
+ * @param {String}
+ * @return {Plugin}
+ */
Plugin.createFromString = function(s) {
var parts = s.split('@');
var name = parts[0];
@@ -141,11 +146,10 @@ Plugin.createFromString = function(s) {
};
/**
- Create a plugin from a dependency
-
- @param {PluginDependency}
- @return {Plugin}
-*/
+ * Create a plugin from a dependency
+ * @param {PluginDependency}
+ * @return {Plugin}
+ */
Plugin.createFromDep = function(dep) {
return new Plugin({
name: dep.getName(),