summaryrefslogtreecommitdiffstats
path: root/lib/models/templateShortcut.js
blob: 672c7ba27a0e5978c3c2fa7ff4b4aaa1640c8932 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var Immutable = require('immutable');
var is = require('is');

/*
    A TemplateShortcut is defined in plugin's template blocks
    to replace content with a templating block using delimiters.
*/
var TemplateShortcut = Immutable.Record({
    // List of parser names accepting this shortcut
    parsers:     Immutable.Map(),

    start:       String(),
    end:         String(),

    startTag:    String(),
    endTag:      String()
}, 'TemplateShortcut');

TemplateShortcut.prototype.getStart = function() {
    return this.get('start');
};

TemplateShortcut.prototype.getEnd = function() {
    return this.get('end');
};

TemplateShortcut.prototype.getStartTag = function() {
    return this.get('startTag');
};

TemplateShortcut.prototype.getEndTag = function() {
    return this.get('endTag');
};

TemplateShortcut.prototype.getParsers = function() {
    return this.get('parsers');
};

/**
    Test if this shortcut accept a parser

    @param {Parser|String} parser
    @return {Boolean}
*/
TemplateShortcut.prototype.acceptParser = function(parser) {
    if (!is.string(parser)) {
        parser = parser.getName();
    }

    var parserNames = this.get('parsers');
    return parserNames.includes(parser);
};

/**
    Create a shortcut for a block

    @param {TemplateBlock} block
    @param {Map} details
    @return {TemplateShortcut}
*/
TemplateShortcut.createForBlock = function(block, details) {
    return new TemplateShortcut({
        parsers:        details.get('parsers'),
        start:          details.get('start'),
        end:            details.get('end'),
        startTag:       block.getName(),
        endTag:         block.getEndTag()
    });
};

module.exports = TemplateShortcut;