Total Complexity | 12 |
Complexity/F | 1.71 |
Lines of Code | 51 |
Function Count | 7 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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 |