-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.js
39 lines (38 loc) · 1.19 KB
/
helpers.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
var helpers = {
swiftColor: function(color) {
var f = function(n) { return n < 0.001 ? 0 : (n/255).toFixed(3); };
return 'red:'+f(color.r)+' green:'+f(color.g)+' blue:'+f(color.b)+' alpha:' + color.a;
},
swiftAlignment: function(align) {
var code = '';
switch (align) {
case 'left':
code = '.Left';
break;
case 'right':
code = '.Right';
break;
case 'center':
code = '.Center';
break;
case 'justified':
code = '.Justified';
break;
}
return code;
},
swiftFont: function(chunk, ctx, bodies, params) {
var baseTextStyle = ctx.get('baseTextStyle');
return chunk.write(baseTextStyle.font.postScriptName || baseTextStyle.font.name);
},
nsLocalizedString: function(data) {
var loc = data.options['localizedString'] ? true : false;
return loc ?
'NSLocalizedString("' + data.text + '", comment: "")' :
'"' + data.text + '"';
}
};
exports.swiftColor = helpers.swiftColor
exports.swiftAlignment = helpers.swiftAlignment
exports.swiftFont = helpers.swiftFont
exports.nsLocalizedString = helpers.nsLocalizedString