-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdust.js
87 lines (73 loc) · 2.5 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
var css = require('octopus-helpers').css;
var utils = require('octopus-helpers').utils;
// Options: selector, selectorTextStyle, selectorType, colorType, inheritFontStyles
var filters = {
px: css.px,
radius: css.radius,
gradientAngle: function(angle) {
return new css.GradientAngle(angle).toOldCssString();
},
css3GradientAngle: function(angle) {
return new css.GradientAngle(angle).toNewCssString();
}
};
var helpers = {
border: css.border,
font: function(chunk, ctx, bodies, params) {
if (params.font.type === undefined) {
return chunk.render(bodies.block, ctx.push(params.font));
}
var fontStyles = css.fontStyleNameToCSS(params.font.type);
for (var j = 0, jLength = fontStyles.length; j < jLength; j++) {
var fontStyle = fontStyles[j];
params.font[fontStyle.property] = fontStyle.value;
}
return chunk.render(bodies.block, ctx.push(params.font));
},
color: function(chunk, ctx, bodies, params) {
var color = ctx.get('color');
var type = params.type || 'hex';
return chunk.write(css.color(color, type));
},
selector: function(chunk, ctx, bodies, params) {
var data = ctx.get('name');
var index = '';
var prefix = '';
var range = null;
var dictionary = {
"Dash-case" : "dash",
"CamelCase": "camel",
"Snake_case": "snake"
};
var style = dictionary[params.style] || 'dash';
var type = '.';
if (params.type === 'id') {
type = '#';
} else if (params.type === 'element') {
type = '';
}
if (params.ranges) {
index = params.index;
range = params.ranges[index].ranges[0];
data = ctx.get('text').substring(range.from, range.to);
}
var format = utils.format(data, style);
if (params.isText != '0') {
prefix = 'textStyle-';
}
format = prefix + (format && format || index);
return chunk.write(type + format);
},
textSnippet: function(chunk, ctx, bodies, params) {
var data = ctx.get('name');
if (params.ranges) {
var index = params.index;
var range = params.ranges[index].ranges[0];
data = ctx.get('text').substring(range.from, range.to);
}
data = 'Style for "' + data.slice(0, 14) + '"';
return chunk.write('// ' + data);
}
};
exports.filters = filters;
exports.helpers = helpers;