@@ -4,7 +4,7 @@ var gutil = require('gulp-util');
4
4
5
5
module . exports = function ( ) {
6
6
return through ( function ( file ) {
7
- var regex = / \$ ( .* ?) : ( . * ?) ; / g;
7
+ var regex = / \$ ( .* ?) : ( [ \s \S ] * ?) ; / g;
8
8
var variables = { } ;
9
9
var stringifiedContent ;
10
10
var jsonVariables ;
@@ -24,8 +24,35 @@ module.exports = function() {
24
24
if ( m . index === regex . lastIndex ) {
25
25
regex . lastIndex ++ ;
26
26
}
27
+ // test for sass maps
28
+ if ( m [ 2 ] . indexOf ( ':' ) > - 1 &&
29
+ m [ 2 ] . indexOf ( '(' ) > - 1 &&
30
+ m [ 2 ] . indexOf ( ')' ) > - 1 &&
31
+ m [ 2 ] . indexOf ( ',' ) > - 1 ) {
32
+ // Split of the SASS map property
33
+ var sassMapRule = m [ 2 ] . split ( ',' ) ;
34
+ // Empty object that will be the JSON property
35
+ var outputObj = { } ;
27
36
28
- variables [ m [ 1 ] . trim ( ) ] = m [ 2 ] . trim ( ) ;
37
+ for ( var prop in sassMapRule ) {
38
+ var sassMapRuleObj = sassMapRule [ prop ] . split ( ':' ) ;
39
+
40
+ // ignore sass map property it it is null or undefined
41
+ if ( ! sassMapRuleObj [ 0 ] || ! sassMapRuleObj [ 1 ] ) {
42
+ continue ;
43
+ }
44
+
45
+ // time newlines, whitespaces, and parentheses
46
+ var sassMapKey = sassMapRuleObj [ 0 ] . replace ( / [ \( \n ] / , '' ) . trim ( ) ;
47
+ var sassMapVal = sassMapRuleObj [ 1 ] . trim ( ) ;
48
+
49
+ outputObj [ sassMapKey ] = sassMapVal ;
50
+ }
51
+ variables [ m [ 1 ] . trim ( ) ] = outputObj ;
52
+ // non sass maps rules
53
+ } else {
54
+ variables [ m [ 1 ] . trim ( ) ] = m [ 2 ] . trim ( ) ;
55
+ }
29
56
}
30
57
31
58
jsonVariables = JSON . stringify ( variables , null , '\t' ) ;
0 commit comments