Skip to content

Commit ef53c95

Browse files
committed
Merge pull request #10 from csscomb/colon-space
Option: colon-space
2 parents 530b8fe + 9935d94 commit ef53c95

File tree

4 files changed

+53
-5
lines changed

4 files changed

+53
-5
lines changed

lib/csscomb.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ Comb.prototype = {
3333
if (config.hasOwnProperty(option) && config[option] && this._options[option]) {
3434
var handler;
3535
try {
36-
handler = require('./options/' + option);
37-
handler.value = config[option];
38-
this._config[option] = handler;
36+
this._config[option] = require('./options/' + option).setValue(config[option]);
3937
} catch (e) {}
4038
}
4139
}

lib/options/colon-space.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module.exports = {
2+
3+
_value: false,
4+
5+
/**
6+
* Sets handler value.
7+
*
8+
* @param {String|Boolean} value Option value
9+
* @returns {Object}
10+
*/
11+
setValue: function(value) {
12+
if (!value) return this;
13+
if (typeof value === 'string') {
14+
this._value = value;
15+
} else {
16+
this._value = 'after'; // default
17+
}
18+
return this;
19+
},
20+
21+
/**
22+
* Processes tree node.
23+
* @param {String} nodeType
24+
* @param {node} node
25+
*/
26+
process: function(nodeType, node) {
27+
if (nodeType === 'property') {
28+
if (node[node.length - 1][0] === 's') node.pop();
29+
if (this._value === 'both' || this._value === 'before')
30+
node.push(['s', ' ']);
31+
}
32+
if (nodeType === 'value') {
33+
if (node[0][0] === 's') node.shift();
34+
if (this._value === 'both' || this._value === 'after')
35+
node.unshift(['s', ' ']);
36+
}
37+
}
38+
39+
};

lib/options/strip-spaces.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ module.exports = {
22

33
value: false,
44

5+
/**
6+
* Sets handler value.
7+
*
8+
* @param {String|Boolean} value Option value
9+
* @returns {Object}
10+
*/
11+
setValue: function(value) {
12+
this._value = !!value;
13+
return this;
14+
},
15+
516
/**
617
* Processes tree node.
718
* @param {String} nodeType

test/test.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ div {
4545
}
4646

4747
a{
48-
top:0;/* ololo */margin:0;}
48+
top: 0;/* ololo */margin :0;}
4949
b{
50-
top:0/* trololo */;margin:0;}
50+
top :0/* trololo */;margin : 0;}
5151

5252

5353

0 commit comments

Comments
 (0)