Passed
Push — master ( 1b32bd...d6fc40 )
by Dmytro
02:35 queued 12s
created

src/handlebars.js   A

Complexity

Total Complexity 12
Complexity/F 1.71

Size

Lines of Code 51
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 12
eloc 27
mnd 5
bc 5
fnc 7
dl 0
loc 51
rs 10
bpm 0.7141
cpm 1.7142
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
D handlebars.js ➔ getTemplate 0 5 12
1
import HandleBars from 'handlebars';
2
import mdinclude from 'mdinclude';
3
import { isString } from 'myrmidon';
4
5
HandleBars.registerHelper('join', (items = [], sep = ' ') => {
6
    return items.join(sep);
7
});
8
9
HandleBars.registerHelper('lowercase', str => {
10
    return isString(str) ? str.toLowerCase() : '';
11
});
12
13
HandleBars.registerHelper('is', function (value, test, options) {
14
    if (value && value === test) {
15
        return options.fn(this);
16
    }
17
18
    return options.inverse(this);
19
});
20
21
HandleBars.registerHelper('any', function (array, options) {
22
    if (array && array.length > 0) {
23
        return options.fn(this);
24
    }
25
26
    return options.inverse(this);
27
});
28
29
HandleBars.registerHelper('more', function (value, test, options) {
30
    if (value > test) {
31
        return options.fn(this);
32
    }
33
34
    return options.inverse(this);
35
});
36
37
HandleBars.registerHelper('less', function (value, test, options) {
38
    if (value < test) {
39
        return options.fn(this);
40
    }
41
42
    return options.inverse(this);
43
});
44
45
export default HandleBars;
46
47
export function getTemplate(entry) {
48
    const templateText = mdinclude.readFileSync(entry); // eslint-disable-line no-sync
49
50
    return HandleBars.compile(templateText, { noEscape: true });
51
}
52