summaryrefslogtreecommitdiffstats
path: root/lib/models/templateOutput.js
blob: ae63c06cd1c096e8511fb67b6ac28285fc268ca6 (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
var Immutable = require('immutable');

var TemplateOutput = Immutable.Record({
    // Text content of the template
    content:        String(),

    // Map of blocks to replace / post process
    blocks:         Immutable.Map()
}, 'TemplateOutput');

TemplateOutput.prototype.getContent = function() {
    return this.get('content');
};

TemplateOutput.prototype.getBlocks = function() {
    return this.get('blocks');
};

/**
 * Update content of this output
 * @param {String} content
 * @return {TemplateContent}
 */
TemplateOutput.prototype.setContent = function(content) {
    return this.set('content', content);
};

/**
 * Create a TemplateOutput from a text content
 * and an object containing block definition
 * @param {String} content
 * @param {Object} blocks
 * @return {TemplateOutput}
 */
TemplateOutput.create = function(content, blocks) {
    return new TemplateOutput({
        content:    content,
        blocks:     Immutable.fromJS(blocks)
    });
};

module.exports = TemplateOutput;