Skip to content

Commit 78f8e2a

Browse files
committed
Make new Comb() and configure() chainable
You can now do things like: // Init, configure and process: var css = new Comb('csscomb').processFile('nani.scss'); // Comb a file with one line of code: new Comb().configure({ 'always-semicolon': true }).processFile('panda.less');
1 parent ea97641 commit 78f8e2a

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

lib/csscomb.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ var Comb = function(config) {
4242
}
4343

4444
if (typeof config === 'object') this.configure(config);
45+
46+
// Return Comb's object to make creating new instance chainable:
47+
return this;
4548
};
4649

4750
Comb.prototype = {
@@ -95,6 +98,9 @@ Comb.prototype = {
9598
this.changed = 0;
9699
this._verbose = config.verbose;
97100
this._lint = config.lint;
101+
102+
// Return Comb's object to make the method chainable:
103+
return this;
98104
},
99105

100106
/**

test/configure.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,20 @@ describe('csscomb methods', function() {
2929

3030
assert.equal(expected, output);
3131
});
32+
33+
it('new Comb() should be chainable', function() {
34+
input = 'a { color: tomato; top: 0; }';
35+
expected = 'a {top: 0; color: tomato; }';
36+
output = new Comb('zen').processString(input);
37+
38+
assert.equal(expected, output);
39+
});
40+
41+
it('configure() should be chainable', function() {
42+
input = 'a { color: tomato }';
43+
expected = 'a { color: tomato; }';
44+
output = new Comb().configure({ 'always-semicolon': true }).processString(input);
45+
46+
assert.equal(expected, output);
47+
});
3248
});

0 commit comments

Comments
 (0)