1
- var template = require ( 'lodash.template' ) ;
2
1
var decls = require ( './decls.json' ) ;
3
2
3
+ function template ( string , data ) {
4
+ return string . replace ( / \$ \{ ( [ \w \- \. ] * ) \} / g, function ( _str , key ) {
5
+ var v = data [ key ] ;
6
+ return typeof v !== 'undefined' && v !== null ? v : '' ;
7
+ } ) ;
8
+ }
9
+
4
10
/*
5
11
Rules legend:
6
12
- combined - if rule is combined it will be rendered with template
@@ -23,8 +29,7 @@ function _compileDecls(inputDecls) {
23
29
var templateVars = _getRulesMap ( inputDecls ) ;
24
30
return inputDecls . map ( function ( decl ) {
25
31
if ( decl . combined && decl . initial ) {
26
- var t = template ( decl . initial . replace ( / \- / g, '' ) ) ;
27
- decl . initial = t ( templateVars ) ;
32
+ decl . initial = template ( decl . initial . replace ( / \- / g, '' ) , templateVars ) ;
28
33
}
29
34
return decl ;
30
35
} ) ;
@@ -33,8 +38,8 @@ function _compileDecls(inputDecls) {
33
38
function _getRequirements ( inputDecls ) {
34
39
return inputDecls . reduce ( function ( map , decl ) {
35
40
if ( ! decl . contains ) return map ;
36
- return decl . contains . reduce ( function ( mapInner , dependensy ) {
37
- mapInner [ dependensy ] = decl ;
41
+ return decl . contains . reduce ( function ( mapInner , dependency ) {
42
+ mapInner [ dependency ] = decl ;
38
43
return mapInner ;
39
44
} , map ) ;
40
45
} , { } ) ;
@@ -46,11 +51,11 @@ function _expandContainments(inputDecls) {
46
51
. filter ( function ( decl ) {
47
52
return ! decl . contains ;
48
53
} ) . map ( function ( decl ) {
49
- var dependensy = requiredMap [ decl . prop ] ;
50
- if ( dependensy ) {
51
- decl . requiredBy = dependensy . prop ;
52
- decl . basic = decl . basic || dependensy . basic ;
53
- decl . inherited = decl . inherited || dependensy . inherited ;
54
+ var dependency = requiredMap [ decl . prop ] ;
55
+ if ( dependency ) {
56
+ decl . requiredBy = dependency . prop ;
57
+ decl . basic = decl . basic || dependency . basic ;
58
+ decl . inherited = decl . inherited || dependency . inherited ;
54
59
}
55
60
return decl ;
56
61
} ) ;
0 commit comments