UNPKG

2.2 kBJavaScriptView Raw
1"use strict";
2var Handlebars = require("handlebars");
3exports.initHelpers = function () {
4 Handlebars.registerHelper('times', function (n, block) {
5 var accum = '';
6 for (var i = 0; i < n; ++i) {
7 accum += block.fn(i);
8 }
9 return accum;
10 });
11 Handlebars.registerHelper('for', function (from, to, incr, block) {
12 var accum = '';
13 for (var i = from; i < to; i += incr) {
14 accum += block.fn(i);
15 }
16 return accum;
17 });
18 Handlebars.registerHelper('limitedEach', function (context, block) {
19 var ret = '';
20 var count = parseInt(block.hash.count);
21 for (var i = 0, j = count; i < j; i++) {
22 ret = ret + block.fn(context[i], {
23 data: {
24 last: i === count - 1,
25 first: i === 0,
26 index: 1
27 }
28 });
29 }
30 return ret;
31 });
32 Handlebars.registerHelper('ifCond', function (v1, operator, v2, options) {
33 switch (operator) {
34 case '==':
35 return (v1 === v2) ? options.fn(this) : options.inverse(this);
36 case '===':
37 return (v1 === v2) ? options.fn(this) : options.inverse(this);
38 case '!=':
39 return (v1 !== v2) ? options.fn(this) : options.inverse(this);
40 case '!==':
41 return (v1 !== v2) ? options.fn(this) : options.inverse(this);
42 case '<':
43 return (v1 < v2) ? options.fn(this) : options.inverse(this);
44 case '<=':
45 return (v1 <= v2) ? options.fn(this) : options.inverse(this);
46 case '>':
47 return (v1 > v2) ? options.fn(this) : options.inverse(this);
48 case '>=':
49 return (v1 >= v2) ? options.fn(this) : options.inverse(this);
50 case '&&':
51 return (v1 && v2) ? options.fn(this) : options.inverse(this);
52 case '||':
53 return (v1 || v2) ? options.fn(this) : options.inverse(this);
54 default:
55 return options.inverse(this);
56 }
57 });
58};
59//# sourceMappingURL=handlebars-helpers.js.map
\No newline at end of file