Skip to content

Commit d88d572

Browse files
committed
v0.0.3
2 parents 2277ba4 + 499a9cc commit d88d572

File tree

7 files changed

+98
-17
lines changed

7 files changed

+98
-17
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Example configuration:
3333
```javascript
3434
{
3535
"exclude": ["node_modules/**"],
36+
"colon-space": true,
37+
"stick-brace": true,
3638
"strip-spaces": true
3739
}
3840
```

lib/csscomb.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var vfs = require('vow-fs');
99
* @name Comb
1010
*/
1111
var Comb = function() {
12-
this._rules = {
12+
this._options = {
1313
'colon-space': {},
1414
'rule-indent': {},
1515
'sort-order': {},
@@ -24,18 +24,15 @@ Comb.prototype = {
2424

2525
/**
2626
* Loads configuration from JSON.
27-
* Activates and configures required rules.
27+
* Activates and configures required options.
2828
*
2929
* @param {Object} config
3030
*/
3131
configure: function(config) {
32-
for (var rule in config) {
33-
if (config.hasOwnProperty(rule) && config[rule] && this._rules[rule]) {
34-
var beautifier;
32+
for (var option in config) {
33+
if (config.hasOwnProperty(option) && config[option] && this._options[option]) {
3534
try {
36-
beautifier = require('./rules/' + rule);
37-
beautifier.value = config[rule];
38-
this._config[rule] = beautifier;
35+
this._config[option] = require('./options/' + option).setValue(config[option]);
3936
} catch (e) {}
4037
}
4138
}
@@ -65,9 +62,9 @@ Comb.prototype = {
6562
node.forEach(function(node) {
6663
if (!Array.isArray(node)) return;
6764
var nodeType = node.shift();
68-
for (var rule in config) {
69-
if (config.hasOwnProperty(rule)) {
70-
config[rule].process(nodeType, node);
65+
for (var option in config) {
66+
if (config.hasOwnProperty(option)) {
67+
config[option].process(nodeType, node);
7168
}
7269
}
7370
node.unshift(nodeType);

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/stick-brace.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module.exports = {
2+
3+
_value: false,
4+
5+
/**
6+
* Sets handler value.
7+
*
8+
* @param {String|Number|Boolean} value Option value
9+
* @returns {Object}
10+
*/
11+
setValue: function(value) {
12+
if (!value) return this;
13+
if (value === true) value = ' '; // 1 space by default
14+
if (typeof value === 'number') this._value = new Array(Math.round(value) + 1).join(' ');
15+
if (typeof value === 'string' && value.match(/^[ \t\n]*$/)) this._value = value;
16+
return this;
17+
},
18+
19+
/**
20+
* Processes tree node.
21+
* @param {String} nodeType
22+
* @param {node} node
23+
*/
24+
process: function(nodeType, node) {
25+
if (nodeType === 'simpleselector') {
26+
if (node[node.length - 1][0] === 's') node.pop();
27+
node.push(['s', this._value]);
28+
}
29+
}
30+
31+
};
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 = Boolean(value);
13+
return this;
14+
},
15+
516
/**
617
* Processes tree node.
718
* @param {String} nodeType

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "csscomb",
33
"description": "Tool for beautify CSS",
4-
"version": "0.0.2",
4+
"version": "0.0.3",
55
"homepage": "http://csscomb.com/",
66
"author": "Mikhail Troshev <mishanga@yandex-team.ru>",
7-
"repository": "https://github.com/mishanga/csscomb.js",
7+
"repository": "https://github.com/csscomb/csscomb.js",
88
"contributors": [
99
{
1010
"name": "Slava Oliyanchuk",
@@ -18,7 +18,7 @@
1818
}
1919
],
2020
"engines": {
21-
"node": ">= 0.8.0"
21+
"node": "0.8 | 0.10"
2222
},
2323
"dependencies": {
2424
"commander": "1.1.1",

test/test.css

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

4747
a{
48-
top:0;/* ololo */margin:0;}
49-
b{
50-
top:0/* trololo */;margin:0;}
48+
top: 0;/* ololo */margin :0;}
49+
b
50+
{
51+
top :0/* trololo */;margin : 0;}
5152

5253

5354

0 commit comments

Comments
 (0)