Skip to content

Commit 02746c5

Browse files
committed
Merge pull request #61 from kizu/element-case
Adds `element-case` option (close #58)
2 parents 9432998 + 45eb522 commit 02746c5

File tree

7 files changed

+107
-3
lines changed

7 files changed

+107
-3
lines changed

.csscomb.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"colon-space": true,
99
"color-case": "lower",
1010
"color-shorthand": true,
11+
"element-case": "lower",
1112
"leading-zero": false,
1213
"rule-indent": true,
1314
"stick-brace": "\n",

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Example configuration:
4444
"colon-space": true,
4545
"color-case": "lower",
4646
"color-shorthand": true,
47+
"element-case": "lower",
4748
"leading-zero": false,
4849
"rule-indent": true,
4950
"stick-brace": true,
@@ -163,6 +164,20 @@ b { color: #ffcc00 }
163164
b { color: #fc0 }
164165
```
165166
167+
### element-case
168+
169+
Available values: `{String}` `lower` or `upper`
170+
171+
Example: `{ "element-case": "upper" }`
172+
173+
```css
174+
/* before */
175+
li > a { color: red }
176+
177+
/* after */
178+
LI > A { color: red }
179+
```
180+
166181
### leading-zero
167182
168183
Available values: `{Boolean}` `true` or `false`

lib/csscomb.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var Comb = function() {
1414
'always-semicolon',
1515
'color-case',
1616
'color-shorthand',
17+
'element-case',
1718
'leading-zero',
1819
'strip-spaces',
1920
'stick-brace',

lib/options/element-case.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
module.exports = {
2+
3+
/**
4+
* Sets handler value.
5+
*
6+
* @param {String} value Option value
7+
* @returns {Object|undefined}
8+
*/
9+
setValue: function(value) {
10+
if (value === 'lower' || value === 'upper') {
11+
this._value = value;
12+
return this;
13+
}
14+
},
15+
16+
/**
17+
* Processes tree node.
18+
* @param {String} nodeType
19+
* @param {node} node
20+
*/
21+
process: function(nodeType, node) {
22+
if (nodeType === 'simpleselector') {
23+
for (var i = node.length; i--;) {
24+
var nodeItem = node[i];
25+
if (nodeItem[0] === 'ident') {
26+
if (this._value === 'lower') {
27+
nodeItem[1] = nodeItem[1].toLowerCase();
28+
} else if (this._value === 'upper') {
29+
nodeItem[1] = nodeItem[1].toUpperCase();
30+
}
31+
}
32+
}
33+
}
34+
}
35+
36+
};

test/element-case.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
var Comb = require('../lib/csscomb');
2+
var assert = require('assert');
3+
4+
describe('options/element-case', function() {
5+
var comb;
6+
7+
beforeEach(function() {
8+
comb = new Comb();
9+
});
10+
11+
it('Invalid String should not change case of elements', function() {
12+
comb.configure({ 'element-case': 'foobar' });
13+
assert.equal(
14+
comb.processString(
15+
'LI a { color : red }'
16+
),
17+
'LI a { color : red }'
18+
);
19+
});
20+
21+
it('Should switch tag name to upper case', function() {
22+
comb.configure({ 'element-case': 'upper' });
23+
assert.equal(
24+
comb.processString(
25+
'div { color: #fff }'
26+
),
27+
'DIV { color: #fff }'
28+
);
29+
});
30+
31+
it('Should switch tag name to lower case', function() {
32+
comb.configure({ 'element-case': 'lower' });
33+
assert.equal(
34+
comb.processString(
35+
'DIV { color: #FFF }'
36+
),
37+
'div { color: #FFF }'
38+
);
39+
});
40+
41+
it('Should switch element-case in complex rules', function() {
42+
comb.configure({ 'element-case': 'lower' });
43+
assert.equal(
44+
comb.processString(
45+
'UL > LI > .foo:not(A) { color: red }'
46+
),
47+
'ul > li > .foo:not(a) { color: red }'
48+
);
49+
});
50+
51+
});

test/integral.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ div p em
135135
border-bottom: 1px solid red; /* trololo */ /* trololo */
136136
}
137137

138-
a
138+
a:not(b)
139139
{
140140
top: 0;/* ololo */
141141

test/integral.origin.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ div {
110110
font-size:1px;
111111
top:0
112112
}
113-
div p em {
113+
div P EM {
114114
/* upline comment*/
115115
font-style:italic;
116116

117117
border-bottom:1px solid red /* trololo */ /* trololo */
118118
}
119119

120-
a{
120+
a:not(B){
121121
top: 0;/* ololo */margin :0;}
122122
b
123123
{

0 commit comments

Comments
 (0)