forked from linkedin/dustjs
/
template.helper.js
31 lines (31 loc) · 929 Bytes
/
template.helper.js
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
(function (root, factory) {
if (typeof exports === 'object') {
factory(require('../../'), require('ayepromise'));
} else {
factory(root.dust, root.ayepromise);
}
}(this, function(dust, ayepromise) {
dust.helpers.error = function(chunk, context, bodies, params) {
throw params.errorMessage;
};
dust.helpers.promise = function(chunk, context, bodies, params) {
var defer = ayepromise.defer();
if (params.reject) {
defer.reject(params.reject);
} else {
defer.resolve(params.resolve);
}
return defer.promise;
};
dust.helpers.val = function(chunk, context, bodies, params) {
var val = params.value;
if(dust.isTemplateFn(val)) {
return val(chunk, context);
}
return val;
};
dust.filters.woo = function(string, context) {
var wooLevel = parseInt(context.get('woo')) + 1;
return string.toUpperCase() + new Array(wooLevel).join('!');
};
}));