Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .csscomb.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
],
"colon-space": true,
"color-case": "lower",
"color-shorthand": true,
"leading-zero": false,
"rule-indent": true,
"block-indent": true,
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Example configuration:
"exclude": ["node_modules/**"],
"colon-space": true,
"color-case": "lower",
"color-shorthand": true,
"leading-zero": false,
"rule-indent": true,
"block-indent": true,
Expand Down
1 change: 1 addition & 0 deletions lib/csscomb.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var Comb = function() {
this._options = [
'always-semicolon',
'color-case',
'color-shorthand',
'leading-zero',
'strip-spaces',
'stick-brace',
Expand Down
31 changes: 31 additions & 0 deletions lib/options/color-shorthand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = {

/**
* Sets handler value.
*
* @param {Boolean} value Option value
* @returns {Object}
*/
setValue: function(value) {
if (value === true || value === false) {
this._value = value;
return this;
}
},

/**
* Processes tree node.
* @param {String} nodeType
* @param {node} node
*/
process: function(nodeType, node) {
if (nodeType === 'vhash') {
if (this._value) {
node[0] = node[0].replace(/(\w)\1(\w)\2(\w)\3/i, '$1$2$3');
} else {
node[0] = node[0].replace(/^(\w)(\w)(\w)$/, '$1$1$2$2$3$3');
}
}
}

};
41 changes: 41 additions & 0 deletions test/color-shorthand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
var Comb = require('../lib/csscomb');
var assert = require('assert');

describe('options/color-shorthand', function() {
var comb;

beforeEach(function() {
comb = new Comb();
});

it('Should shrink hexadecimal colors to 3 symbols', function() {
comb.configure({ 'color-shorthand': true });
assert.equal(
comb.processString(
'div { color: #aabbcc }'
),
'div { color: #abc }'
);
});

it('Should expand hexadecimal colors to 6 symbols', function() {
comb.configure({ 'color-shorthand': false });
assert.equal(
comb.processString(
'div { color: #7ad }'
),
'div { color: #77aadd }'
);
});

it('Should save case while processing', function() {
comb.configure({ 'color-shorthand': true });
assert.equal(
comb.processString(
'div { color: #fFAafF }'
),
'div { color: #fAf }'
);
});

});
4 changes: 2 additions & 2 deletions test/integral.origin.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
.radio-button_theme_normal .radio-button__radio:after
{
background: #fFf;
background: -webkit-linear-gradient(top, #Fff 0,#eeE 100%);
background: -webkit-linear-gradient(top, #FffFff 0,#eeeeEe 100%);
background: -moz-linear-gradient(top, #fff 0, #eEe 100%);
background: -o-linear-gradient(top, #fff 0,#eee 100%);
background: linear-gradient(to bottom, #fff 0,#eEe 100%);
background: linear-gradient(to bottom, #ffffff 0,#eeEeee 100%);
}

/* _focused_yes */
Expand Down