-
Notifications
You must be signed in to change notification settings - Fork 0
/
dust.js
44 lines (40 loc) · 1.34 KB
/
dust.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
32
33
34
35
36
37
38
39
40
41
42
43
44
var filters = {
};
var helpers = {
objCColor: function(chunk, ctx, bodies, params) {
var color = ctx.get('color');
var f = function(n) { return n < 0.001 ? 0 : (n/255).toFixed(3); };
return chunk.write('colorWithRed:'+f(color.r)+' green:'+f(color.g)+' blue:'+f(color.b)+' alpha:' + color.a);
},
objCAlignment: function(chunk, ctx, bodies, params) {
var align = ctx.get('textAlign');
var code = '';
switch (align) {
case 'left':
code = 'NSTextAlignmentLeft';
break;
case 'right':
code = 'NSTextAlignmentRight';
break;
case 'center':
code = 'NSTextAlignmentCenter';
break;
case 'justified':
code = 'NSTextAlignmentJustified';
break;
}
return chunk.write(code);
},
objCFont: function(chunk, ctx, bodies, params) {
var baseTextStyle = ctx.get('baseTextStyle');
return chunk.write(baseTextStyle.font.postScriptName || baseTextStyle.font.name);
},
nsLocalizedString: function(chunk, ctx, bodies, params) {
var loc = ctx.get('options')['localizedString'] ? true : false;
return chunk.write(loc ?
'NSLocalizedString(@"' + ctx.get('text') + '", nil)' :
'@"' + ctx.get('text') + '"');
}
};
exports.filters = filters;
exports.helpers = helpers;