Skip to content

Commit f2501de

Browse files
committed
gitignore
1 parent 10a31fd commit f2501de

4 files changed

Lines changed: 31 additions & 10 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ build/Release
2929
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
3030
node_modules
3131

32+
.idea

index.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,37 @@
99
return out;
1010
};
1111

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) {
1318
var value, i;
1419
switch (a.constructor.name) {
1520
case 'SassList':
1621
value = [];
1722
for (i = 0; i < a.getLength(); i++) {
18-
value.push(get_value(a.getValue(i)));
23+
value.push(get_value(a.getValue(i), opt));
1924
}
2025
break;
2126
case 'SassMap':
2227
value = {};
2328
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);
2530
}
2631
break;
2732
case 'SassColor':
2833
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+
}
3040
}
3141
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() + ')';
3343
}
3444
break;
3545
case 'SassNumber':
@@ -46,8 +56,13 @@
4656

4757
exporter.function = function (path) {
4858
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);
5166
if (opt.extend && 'SassMap' === value.constructor.name) {
5267
try {
5368
_.defaults(output, JSON.parse(fs.readFileSync(path + '/' + file.getValue())));

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-sass-export",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"description": "lightweight extension that allows you to export an encoded Sass variables (map, list, etc) into an external JSON file",
55
"main": "index.js",
66
"scripts": {

readme.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# node-sass-export
22

3-
**node-sass-export** provide export function fo use with Node-sass [function option](https://github.com/sass/node-sass#functions--v300---experimental).
3+
**node-sass-export** provide export function for use with Node-sass [function option](https://github.com/sass/node-sass#functions--v300---experimental).
44

55
## Usage
66

@@ -56,4 +56,9 @@ $breakpoints: export('lib/breakpoints.js', $breakpoints, (prefix:'var breakpoint
5656
#### Usage with another functions
5757
```
5858
{ functions: _.extend(export_sass('export_path'), {'foobar()': function(){}}) }
59-
```
59+
```
60+
61+
#### Export hex colors
62+
```
63+
$colors: export('lib/colors.json', $colors, (hex_color: true));
64+
```

0 commit comments

Comments
 (0)