summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-core/src/models/Config.js
blob: 3a0883954f0656caac2b0de5a0eeb895c2183805 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
const { Record, Map, fromJS } = require('immutable');

const DEFAULTS = {
    title:         String(),
    pluginsConfig: Map()
};

/**
 * Configuration from the book.
 * @type {Class}
 */
class Config extends Record(DEFAULTS) {

    /**
     * Create a config instance from values.
     * @param  {Mixed} values
     * @return {Config}
     */
    static create(values) {
        return (values instanceof Config) ?
            values :
            new Config(fromJS(values));
    }

    /**
     * Get configuration for a plugin.
     * @param  {String} pluginName
     * @return {Map}
     */
    getForPlugin(pluginName, defaultValue = Map()) {
        return this.getIn([
            'pluginsConfig', pluginName
        ], defaultValue);
    }

}

module.exports = Config;