summaryrefslogtreecommitdiffstats
path: root/lib/generate/plugin.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2014-04-20 00:10:46 +0200
committerSamy Pessé <samypesse@gmail.com>2014-04-20 00:10:46 +0200
commit74d628676b3d5a49b0f461261ba39c6839557410 (patch)
treee22d2b7a6fc53235d4218e8ad3d3fb36f20ac09f /lib/generate/plugin.js
parent6fdd98ec3aa9158b74a5f80e1b35dec1604531d2 (diff)
downloadgitbook-74d628676b3d5a49b0f461261ba39c6839557410.zip
gitbook-74d628676b3d5a49b0f461261ba39c6839557410.tar.gz
gitbook-74d628676b3d5a49b0f461261ba39c6839557410.tar.bz2
Add option to change templates from plugin
Diffstat (limited to 'lib/generate/plugin.js')
-rw-r--r--lib/generate/plugin.js70
1 files changed, 39 insertions, 31 deletions
diff --git a/lib/generate/plugin.js b/lib/generate/plugin.js
index b51d1ff..77bbee5 100644
--- a/lib/generate/plugin.js
+++ b/lib/generate/plugin.js
@@ -80,6 +80,35 @@ Plugin.prototype.callHook = function(name, args) {
});
};
+// Normalize a list of plugin name to use
+Plugin.normalizeNames = function(names) {
+ // Normalize list to an array
+ names = _.isString(names) ? names.split(":") : (names || []);
+
+ // List plugins to remove
+ var toremove = _.chain(names)
+ .filter(function(name) {
+ return name.length > 0 && name[0] == "-";
+ })
+ .map(function(name) {
+ return name.slice(1)
+ })
+ .value();
+
+ // Merge with defaults
+ names = _.chain(names)
+ .concat(Plugin.defaults)
+ .uniq()
+ .value();
+
+ // Remove plugins starting with
+ names = _.filter(names, function(name) {
+ return !_.contains(toremove, name) && !(name.length > 0 && name[0] == "-");
+ });
+
+ return names;
+};
+
// Extract data from a list of plugin
Plugin.fromList = function(names) {
var failed = [];
@@ -118,40 +147,19 @@ Plugin.fromList = function(names) {
return plugin.callHook(name, args);
})
}, Q());
- }
+ },
+ 'template': function(name) {
+ var withTpl = _.find(plugins, function(plugin) {
+ return (plugin.infos.templates
+ && plugin.infos.templates[name]);
+ });
+
+ if (!withTpl) return null;
+ return withTpl.resolveFile(withTpl.infos.templates[name]);
+ }
});
};
-
-// Normalize a list of plugin name to use
-Plugin.normalizeNames = function(names) {
- // Normalize list to an array
- names = _.isString(names) ? names.split(":") : (names || []);
-
- // List plugins to remove
- var toremove = _.chain(names)
- .filter(function(name) {
- return name.length > 0 && name[0] == "-";
- })
- .map(function(name) {
- return name.slice(1)
- })
- .value();
-
- // Merge with defaults
- names = _.chain(names)
- .concat(Plugin.defaults)
- .uniq()
- .value();
-
- // Remove plugins starting with
- names = _.filter(names, function(name) {
- return !_.contains(toremove, name) && !(name.length > 0 && name[0] == "-");
- });
-
- return names;
-};
-
// Default plugins
Plugin.defaults = [
"mixpanel"