@@ -9,13 +9,14 @@ var vfs = require('vow-fs');
99 * @name Comb
1010 */
1111var Comb = function ( ) {
12- this . _options = {
13- 'colon-space' : { } ,
14- 'rule-indent' : { } ,
15- 'sort-order' : { } ,
16- 'stick-brace' : { } ,
17- 'strip-spaces' : { }
18- } ,
12+ this . _handlers ;
13+ this . _options = [
14+ 'strip-spaces' ,
15+ 'stick-brace' ,
16+ 'colon-space' ,
17+ 'rule-indent' ,
18+ 'sort-order'
19+ ] ;
1920 this . _config = { } ;
2021 this . _exclude = null ;
2122} ;
@@ -29,13 +30,18 @@ Comb.prototype = {
2930 * @param {Object } config
3031 */
3132 configure : function ( config ) {
32- for ( var option in config ) {
33- if ( config . hasOwnProperty ( option ) && config [ option ] && this . _options [ option ] ) {
33+ var _this = this ;
34+ this . _handlers = [ ] ;
35+ this . _options . forEach ( function ( option ) {
36+ if ( config [ option ] ) {
3437 try {
35- this . _config [ option ] = require ( './options/' + option ) . setValue ( config [ option ] ) ;
36- } catch ( e ) { }
38+ var handler = require ( './options/' + option ) . setValue ( config [ option ] ) ;
39+ handler && _this . _handlers . push ( handler ) ;
40+ } catch ( e ) {
41+ throw new Error ( 'Handler ' + option + ' was not found.' ) ;
42+ }
3743 }
38- }
44+ } ) ;
3945 this . _exclude = ( config . exclude || [ ] ) . map ( function ( pattern ) {
4046 return new minimatch . Minimatch ( pattern ) ;
4147 } ) ;
@@ -62,11 +68,9 @@ Comb.prototype = {
6268 node . forEach ( function ( node ) {
6369 if ( ! Array . isArray ( node ) ) return ;
6470 var nodeType = node . shift ( ) ;
65- for ( var option in config ) {
66- if ( config . hasOwnProperty ( option ) ) {
67- config [ option ] . process ( nodeType , node ) ;
68- }
69- }
71+ _this . _handlers . forEach ( function ( handler ) {
72+ handler . process ( nodeType , node ) ;
73+ } ) ;
7074 node . unshift ( nodeType ) ;
7175 _this . processNode ( node , level ) ;
7276 } ) ;
@@ -84,7 +88,7 @@ Comb.prototype = {
8488 } catch ( e ) {
8589 throw new Error ( 'Parsing error at ' + filename + ': ' + e . message ) ;
8690 }
87- return cssp . translate ( cssp . transform ( tree ) ) ;
91+ return cssp . translate ( tree ) ;
8892 } ,
8993
9094 /**
0 commit comments