summaryrefslogtreecommitdiffstats
path: root/lib/modifiers/config/togglePlugin.js
blob: 13d4406a085c3714dc895d5f6a51b5f3f5998dc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

/**
 * Enable/disable a plugin dependency
 * @param {Book} book
 * @param {String} plugin
 * @param {Boolean} state (optional)
 * @return {Book}
 */
function togglePlugin(book, plugin, state) {
    var config = book.getConfig();
    var deps = config.getPluginDependencies();

    deps = deps.map(function(dep) {
        if (dep.getName() === plugin) {
            return dep.toggle(state);
        }

        return dep;
    });

    config = config.setPluginDependencies(deps);
    return book.setConfig(config);
}

module.exports = togglePlugin;