Skip to content

Commit ea97641

Browse files
committed
Pass config to Comb constructor
You can now create new Comb instance and configure it at the same time. To use one of predefined configs, pass its name: var comb = new Comb('zen'); // or `csscomb`, or `yandex` To use custom config, pass its object: var comb = new Comb({ 'always-semicolon': true });
1 parent df133d6 commit ea97641

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

lib/csscomb.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var doNothing = function() {};
1111
* @constructor
1212
* @name Comb
1313
*/
14-
var Comb = function() {
14+
var Comb = function(config) {
1515
this.SUPPORTED_SYNTAXES = ['css', 'scss', 'less'];
1616
this._options = [
1717
'remove-empty-rulesets',
@@ -34,6 +34,14 @@ var Comb = function() {
3434
];
3535
this._exclude = null;
3636
this._detect = false;
37+
38+
// If config was passed, configure:
39+
if (typeof config === 'string' &&
40+
['csscomb', 'zen', 'yandex'].indexOf(config) > -1) {
41+
config = require('../config/' + config + '.json');
42+
}
43+
44+
if (typeof config === 'object') this.configure(config);
3745
};
3846

3947
Comb.prototype = {

test/configure.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
var Comb = require('../lib/csscomb');
2+
var assert = require('assert');
3+
4+
describe('csscomb methods', function() {
5+
var comb;
6+
var input;
7+
var output;
8+
var expected;
9+
10+
it('Passing no config to constructor should not configure anything', function() {
11+
comb = new Comb();
12+
assert.equal(undefined, comb._handlers);
13+
});
14+
15+
it('Passing valid config name to constructor should configure using correct config', function() {
16+
comb = new Comb('zen');
17+
input = 'a { color: tomato; top: 0; }';
18+
expected = 'a {top: 0; color: tomato; }';
19+
output = comb.processString(input);
20+
21+
assert.equal(expected, output);
22+
});
23+
24+
it('Passing config object to constructor should configure using that object', function() {
25+
comb = new Comb({ 'always-semicolon': true });
26+
input = 'a { color: tomato }';
27+
expected = 'a { color: tomato; }';
28+
output = comb.processString(input);
29+
30+
assert.equal(expected, output);
31+
});
32+
});

0 commit comments

Comments
 (0)