mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-24 11:26:31 +00:00
Change config modifier to work on a config object
This commit is contained in:
@@ -2,21 +2,18 @@ var PluginDependency = require('../../models/pluginDependency');
|
||||
|
||||
/**
|
||||
* Add a plugin to a book's configuration
|
||||
* @param {Book} book
|
||||
* @param {Config} config
|
||||
* @param {String} plugin
|
||||
* @param {String} version (optional)
|
||||
* @return {Book}
|
||||
* @return {Config}
|
||||
*/
|
||||
function addPlugin(book, plugin, version) {
|
||||
var config = book.getConfig();
|
||||
function addPlugin(config, plugin, version) {
|
||||
var deps = config.getPluginDependencies();
|
||||
|
||||
var dep = PluginDependency.create(plugin, version);
|
||||
|
||||
deps = deps.push(dep);
|
||||
config = config.setPluginDependencies(deps);
|
||||
|
||||
return book.setConfig(config);
|
||||
return config.setPluginDependencies(deps);
|
||||
}
|
||||
|
||||
module.exports = addPlugin;
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
|
||||
/**
|
||||
* Edit ocnfiguration of a plugin
|
||||
* @param {Book} book
|
||||
* Edit configuration of a plugin
|
||||
* @param {Config} config
|
||||
* @param {String} plugin
|
||||
* @param {Object} pluginConfig
|
||||
* @return {Book}
|
||||
* @return {Config}
|
||||
*/
|
||||
function editPlugin(book, pluginName, pluginConfig) {
|
||||
var config = book.getConfig();
|
||||
config = config.set('pluginsConfig.'+pluginName, pluginConfig);
|
||||
|
||||
return book.setConfig(config);
|
||||
function editPlugin(config, pluginName, pluginConfig) {
|
||||
return config.set('pluginsConfig.'+pluginName, pluginConfig);
|
||||
}
|
||||
|
||||
module.exports = editPlugin;
|
||||
|
||||
@@ -1,21 +1,17 @@
|
||||
|
||||
/**
|
||||
* Remove a plugin from a book's configuration
|
||||
* @param {Book} book
|
||||
* @param {Config} config
|
||||
* @param {String} plugin
|
||||
* @return {Book}
|
||||
* @return {Config}
|
||||
*/
|
||||
function removePlugin(book, pluginName) {
|
||||
var config = book.getConfig();
|
||||
function removePlugin(config, pluginName) {
|
||||
var deps = config.getPluginDependencies();
|
||||
|
||||
|
||||
deps = deps.filter(function(dep) {
|
||||
return dep.getName() === pluginName;
|
||||
});
|
||||
config = config.setPluginDependencies(deps);
|
||||
|
||||
return book.setConfig(config);
|
||||
return config.setPluginDependencies(deps);
|
||||
}
|
||||
|
||||
module.exports = removePlugin;
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
|
||||
/**
|
||||
* Enable/disable a plugin dependency
|
||||
* @param {Book} book
|
||||
* @param {Config} config
|
||||
* @param {String} plugin
|
||||
* @param {Boolean} state (optional)
|
||||
* @return {Book}
|
||||
* @return {Config}
|
||||
*/
|
||||
function togglePlugin(book, plugin, state) {
|
||||
var config = book.getConfig();
|
||||
function togglePlugin(config, plugin, state) {
|
||||
var deps = config.getPluginDependencies();
|
||||
|
||||
deps = deps.map(function(dep) {
|
||||
@@ -18,8 +17,7 @@ function togglePlugin(book, plugin, state) {
|
||||
return dep;
|
||||
});
|
||||
|
||||
config = config.setPluginDependencies(deps);
|
||||
return book.setConfig(config);
|
||||
return config.setPluginDependencies(deps);
|
||||
}
|
||||
|
||||
module.exports = togglePlugin;
|
||||
|
||||
Reference in New Issue
Block a user