|
9 | 9 | return out; |
10 | 10 | }; |
11 | 11 |
|
12 | | - exporter.get_value = function get_value(a) { |
| 12 | + function toHex(c) { |
| 13 | + var hex = Math.round(c).toString(16).toUpperCase(); |
| 14 | + return hex.length == 1 ? "0" + hex : hex; |
| 15 | + }; |
| 16 | + |
| 17 | + exporter.get_value = function get_value(a, opt) { |
13 | 18 | var value, i; |
14 | 19 | switch (a.constructor.name) { |
15 | 20 | case 'SassList': |
16 | 21 | value = []; |
17 | 22 | for (i = 0; i < a.getLength(); i++) { |
18 | | - value.push(get_value(a.getValue(i))); |
| 23 | + value.push(get_value(a.getValue(i), opt)); |
19 | 24 | } |
20 | 25 | break; |
21 | 26 | case 'SassMap': |
22 | 27 | value = {}; |
23 | 28 | for (i = 0; i < a.getLength(); i++) { |
24 | | - value[a.getKey(i).getValue()] = get_value(a.getValue(i)); |
| 29 | + value[a.getKey(i).getValue()] = get_value(a.getValue(i), opt); |
25 | 30 | } |
26 | 31 | break; |
27 | 32 | case 'SassColor': |
28 | 33 | if (1 === a.getA()) { |
29 | | - value = 'rgb(' + a.getR() + ', ' + a.getG() + ', ' + a.getB() + ')'; |
| 34 | + if (opt.hex_color) { |
| 35 | + value = '#' + toHex(a.getR()) + toHex(a.getG()) + toHex(a.getB()); |
| 36 | + } |
| 37 | + else { |
| 38 | + value = 'rgb(' + Math.round(a.getR()) + ', ' + Math.round(a.getG()) + ', ' + Math.round(a.getB()) + ')'; |
| 39 | + } |
30 | 40 | } |
31 | 41 | else { |
32 | | - value = 'rgba(' + a.getR() + ', ' + a.getG() + ', ' + a.getB() + ', ' + a.getA() + ')'; |
| 42 | + value = 'rgba(' + Math.round(a.getR()) + ', ' + Math.round(a.getG()) + ', ' + Math.round(a.getB()) + ', ' + a.getA() + ')'; |
33 | 43 | } |
34 | 44 | break; |
35 | 45 | case 'SassNumber': |
|
46 | 56 |
|
47 | 57 | exporter.function = function (path) { |
48 | 58 | return function (file, value, options) { |
49 | | - var opt = _.defaults(exporter.get_value(options), {prefix: '', suffix: '', extend: false}); |
50 | | - var output = exporter.get_value(value); |
| 59 | + var opt = _.defaults(exporter.get_value(options), { |
| 60 | + prefix: '', |
| 61 | + suffix: '', |
| 62 | + extend: false, |
| 63 | + hex_color: false |
| 64 | + }); |
| 65 | + var output = exporter.get_value(value, opt); |
51 | 66 | if (opt.extend && 'SassMap' === value.constructor.name) { |
52 | 67 | try { |
53 | 68 | _.defaults(output, JSON.parse(fs.readFileSync(path + '/' + file.getValue()))); |
|
0 commit comments