-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.js
43 lines (42 loc) · 1.48 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
40
41
42
43
var helpers = {
swiftColor: 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('TODO');
// return chunk.write('colorWithRed:'+f(color.r)+' green:'+f(color.g)+' blue:'+f(color.b)+' alpha:' + color.a);
},
swiftAlignment: 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);
},
swiftFont: function(chunk, ctx, bodies, params) {
var baseTextStyle = ctx.get('baseTextStyle');
return chunk.write(baseTextStyle.font.postScriptName || baseTextStyle.font.name);
},
// 'NSLocalizedString("'+this.name+'", comment: "")'
nsLocalizedString: function(data) {
var loc = data.options['localizedString'] ? true : false;
return loc ?
'NSLocalizedString("' + data.text + '", nil)' :
'"' + data.text + '"';
}
};
exports.swiftColor = helpers.swiftColor
exports.swiftAlignment = helpers.swiftAlignment
exports.swiftFont = helpers.swiftFont
exports.nsLocalizedString = helpers.nsLocalizedString