summaryrefslogtreecommitdiffstats
path: root/packages/gitbook/src/models/readme.js
blob: 59eea22846f394ffc7e1d06c2fc4375a0bb0b6dd (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
39
40
41
42
43
44
45
46
47
48
49
const { Record } = require('immutable');
const File = require('./file');

const DEFAULTS = {
    file:        new File(),
    title:       String(),
    description: String()
};

class Readme extends Record(DEFAULTS) {
    getFile() {
        return this.get('file');
    }

    getTitle() {
        return this.get('title');
    }

    getDescription() {
        return this.get('description');
    }

    /**
     * Set file linked to the readme.
     * @param  {File} file
     * @return {Readme}
     */
    setFile(file) {
        return this.merge({ file });
    }

    /**
     * Create a new readme
     *
     * @param {File} file
     * @param {Object} def
     * @return {Readme}
     */
    static create(def) {
        def = def || {};

        return new Readme({
            title: def.title || '',
            description: def.description || ''
        });
    }
}

module.exports = Readme;