Skip to content

Commit 8ba74ea

Browse files
committed
Merge pull request #46 from ignovak/leading-zero
option: leading-zero
2 parents 5a9716f + 343f26a commit 8ba74ea

File tree

6 files changed

+73
-7
lines changed

6 files changed

+73
-7
lines changed

.csscomb.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"node_modules/**"
55
],
66
"colon-space": true,
7+
"leading-zero": false,
78
"rule-indent": true,
89
"block-indent": true,
910
"stick-brace": "\n",

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Example configuration:
3535
{
3636
"exclude": ["node_modules/**"],
3737
"colon-space": true,
38+
"leading-zero": false,
3839
"rule-indent": true,
3940
"block-indent": true,
4041
"stick-brace": true,

lib/csscomb.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var Comb = function() {
1212
this._handlers;
1313
this._options = [
1414
'always-semicolon',
15+
'leading-zero',
1516
'strip-spaces',
1617
'stick-brace',
1718
'colon-space',
@@ -35,7 +36,7 @@ Comb.prototype = {
3536
var _this = this;
3637
this._handlers = [];
3738
this._options.forEach(function(option) {
38-
if (config[option]) {
39+
if (config[option] !== undefined) {
3940
try {
4041
var handler = require('./options/' + option).setValue(config[option]);
4142
handler && _this._handlers.push(handler);

lib/options/leading-zero.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module.exports = {
2+
3+
/**
4+
* Sets handler value.
5+
*
6+
* @param {Boolean} value Option value
7+
* @returns {Object}
8+
*/
9+
setValue: function(value) {
10+
if (value === true || value === false) {
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 === 'number') {
23+
if (this._value) {
24+
if (node[0][0] === '.')
25+
node[0] = '0' + node[0];
26+
} else {
27+
node[0] = node[0].replace(/^0+(?=\.)/, '');
28+
}
29+
}
30+
}
31+
32+
};

test/integral.expect.css

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
/* :before — бордер */
55
.radio-button_theme_normal .radio-button__radio:before
66
{
7-
background: rgba(0,0,0,0.4);
8-
background: -webkit-linear-gradient(top, rgba(0,0,0,0.2) 0,rgba(0,0,0,0.4) 100%);
9-
background: -moz-linear-gradient(top, rgba(0,0,0,0.2) 0, rgba(0,0,0,0.4) 100%);
10-
background: -o-linear-gradient(top, rgba(0,0,0,0.2) 0,rgba(0,0,0,0.4) 100%);
11-
background: linear-gradient(to bottom, rgba(0,0,0,0.2) 0,rgba(0,0,0,0.4) 100%);
7+
background: rgba(0,0,0,.4);
8+
background: -webkit-linear-gradient(top, rgba(0,0,0,.2) 0,rgba(0,0,0,.4) 100%);
9+
background: -moz-linear-gradient(top, rgba(0,0,0,.2) 0, rgba(0,0,0,.4) 100%);
10+
background: -o-linear-gradient(top, rgba(0,0,0,.2) 0,rgba(0,0,0,.4) 100%);
11+
background: linear-gradient(to bottom, rgba(0,0,0,.2) 0,rgba(0,0,0,.4) 100%);
1212
-moz-box-shadow: 0 1px 0 rgba(0,0,0,.07);
1313
box-shadow: 0 1px 0 rgba(0,0,0,.07);
1414
}
@@ -87,7 +87,7 @@ div p em
8787
{
8888
-moz-box-sizing: border-box;
8989
box-sizing: border-box;
90-
padding: 0.4em 0;
90+
padding: .4em 0;
9191

9292
border: 0;
9393
outline: 0;

test/leading-zero.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var Comb = require('../lib/csscomb');
2+
var assert = require('assert');
3+
4+
describe('options/leading-zero', function() {
5+
var comb;
6+
7+
beforeEach(function() {
8+
comb = new Comb();
9+
});
10+
11+
it('Should add leading zero in dimensions', function() {
12+
comb.configure({ 'leading-zero': true });
13+
assert.equal(
14+
comb.processString(
15+
'div { margin: .5em }'
16+
),
17+
'div { margin: 0.5em }'
18+
);
19+
});
20+
21+
it('Should remove leading zero in dimensions', function() {
22+
comb.configure({ 'leading-zero': false });
23+
assert.equal(
24+
comb.processString(
25+
'div { margin: 0.5em }'
26+
),
27+
'div { margin: .5em }'
28+
);
29+
});
30+
31+
});

0 commit comments

Comments
 (0)