Skip to content

Commit de1a22e

Browse files
authored
Merge pull request #49 from noahcooper/master
Allow src only
2 parents 86c190e + fc25cb2 commit de1a22e

File tree

8 files changed

+102
-4
lines changed

8 files changed

+102
-4
lines changed

Gruntfile.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = function (grunt) {
2424

2525
// Before generating any new files, remove any previously-created files.
2626
clean: {
27-
tests: ['test/fixtures/tmp_*.css','test/fixtures/dest/*.resorted.css'],
27+
tests: ['test/fixtures/tmp_*.css', 'test/fixtures/dest/*.resorted.css', 'test/fixtures/src/*.resorted.css'],
2828
},
2929

3030
// Configuration to be run (and then tested).
@@ -54,6 +54,10 @@ module.exports = function (grunt) {
5454
src: ['*.css', '!*.resorted.css'],
5555
dest: 'test/fixtures/dest/',
5656
ext: '.resorted.css'
57+
},
58+
src_only: {
59+
src: ['test/fixtures/src/*.css', '!test/fixtures/src/*.resorted.css'],
60+
ext: '.resorted.css'
5761
}
5862
},
5963

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,24 @@ grunt.initConfig({
101101
});
102102
```
103103

104+
#### Src Only
105+
106+
If you provide only a `src` with no value for `dest`, then `dest` will automatically be set to the `src` directory.
107+
108+
```js
109+
grunt.initConfig({
110+
csscomb: {
111+
src_only: {
112+
src: ['foo/bar.css'],
113+
ext: '.resorted.css'
114+
}
115+
}
116+
});
117+
```
118+
104119
## Release History
105120

106-
+ v4.0.0: Update csscomb.js to v4; update dependencies.
121+
+ v4.0.0: Update csscomb.js to v4; update dependencies; allow src only.
107122
+ v3.1.1: Update grunt version.
108123
+ v3.0.0: Update csscomb.js to v3.0 but `grunt-csscomb` API doesn't change.
109124
+ v2.0.1: Stop searching config if we reach root directory.

tasks/csscomb.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,20 @@ module.exports = function (grunt) {
7171
return true;
7272
}
7373
}).forEach(function (src) {
74+
var dest = f.dest,
75+
syntax = src.split('.').pop();
76+
if (!dest) {
77+
dest = grunt.file.expandMapping(src, '', { ext: f.ext || '.' + syntax })[0].dest;
78+
}
7479

7580
// Get CSS from a source file:
7681
var css = grunt.file.read(src);
7782

7883
// Comb it:
7984
grunt.log.ok('Sorting file "' + src + '"...');
80-
var syntax = src.split('.').pop();
8185
try {
8286
comb.processString(css, { syntax: syntax }).then(function(combed) {
83-
grunt.file.write(f.dest, combed);
87+
grunt.file.write(dest, combed);
8488
});
8589
} catch(e) {
8690
grunt.log.error(e);

test/csscomb_test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ exports.csscomb = {
4545
var expected2 = grunt.file.read('test/expected/multi2.css');
4646
test.equal(actual2, expected2, 'should be sorted.');
4747

48+
test.done();
49+
},
50+
src_only: function (test) {
51+
test.expect(2);
52+
53+
var actual = grunt.file.read('test/fixtures/src/multi1.resorted.css');
54+
var expected = grunt.file.read('test/expected/multi1.css');
55+
test.equal(actual, expected, 'should be sorted.');
56+
57+
var actual2 = grunt.file.read('test/fixtures/src/multi2.resorted.css');
58+
var expected2 = grunt.file.read('test/expected/multi2.css');
59+
test.equal(actual2, expected2, 'should be sorted.');
60+
4861
test.done();
4962
}
5063
};

test/fixtures/src/multi1.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.multi1 {
2+
z-index: 100;
3+
display: block;
4+
visibility: hidden;
5+
max-height: 44px;
6+
width: 100px;
7+
height: 100px;
8+
border-color: 1px #000 solid;
9+
background-color: red;
10+
vertical-align: 5px;
11+
text-align: center;
12+
font-weight: bold;
13+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.multi1
2+
{
3+
font-weight: bold;
4+
5+
z-index: 100;
6+
7+
display: block;
8+
visibility: hidden;
9+
10+
width: 100px;
11+
height: 100px;
12+
max-height: 44px;
13+
14+
text-align: center;
15+
vertical-align: 5px;
16+
17+
border-color: 1px #000 solid;
18+
background-color: red;
19+
}

test/fixtures/src/multi2.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.multi2 {
2+
position: absolute;
3+
top: 10px;
4+
left: 10px;
5+
z-index: 10;
6+
display: table;
7+
float: left;
8+
margin: 10px;
9+
padding: 10px;
10+
width: 10px;
11+
height: 10px;
12+
border: 1px #fff solid;
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.multi2
2+
{
3+
position: absolute;
4+
z-index: 10;
5+
top: 10px;
6+
left: 10px;
7+
8+
display: table;
9+
float: left;
10+
11+
width: 10px;
12+
height: 10px;
13+
margin: 10px;
14+
padding: 10px;
15+
16+
border: 1px #fff solid;
17+
}

0 commit comments

Comments
 (0)