Skip to content

Commit

Permalink
Merge pull request #49 from noahcooper/master
Browse files Browse the repository at this point in the history
Allow src only
  • Loading branch information
noahcooper authored Dec 7, 2018
2 parents 86c190e + fc25cb2 commit de1a22e
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = function (grunt) {

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

// Configuration to be run (and then tested).
Expand Down Expand Up @@ -54,6 +54,10 @@ module.exports = function (grunt) {
src: ['*.css', '!*.resorted.css'],
dest: 'test/fixtures/dest/',
ext: '.resorted.css'
},
src_only: {
src: ['test/fixtures/src/*.css', '!test/fixtures/src/*.resorted.css'],
ext: '.resorted.css'
}
},

Expand Down
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,24 @@ grunt.initConfig({
});
```

#### Src Only

If you provide only a `src` with no value for `dest`, then `dest` will automatically be set to the `src` directory.

```js
grunt.initConfig({
csscomb: {
src_only: {
src: ['foo/bar.css'],
ext: '.resorted.css'
}
}
});
```

## Release History

+ v4.0.0: Update csscomb.js to v4; update dependencies.
+ v4.0.0: Update csscomb.js to v4; update dependencies; allow src only.
+ v3.1.1: Update grunt version.
+ v3.0.0: Update csscomb.js to v3.0 but `grunt-csscomb` API doesn't change.
+ v2.0.1: Stop searching config if we reach root directory.
Expand Down
8 changes: 6 additions & 2 deletions tasks/csscomb.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,20 @@ module.exports = function (grunt) {
return true;
}
}).forEach(function (src) {
var dest = f.dest,
syntax = src.split('.').pop();
if (!dest) {
dest = grunt.file.expandMapping(src, '', { ext: f.ext || '.' + syntax })[0].dest;
}

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

// Comb it:
grunt.log.ok('Sorting file "' + src + '"...');
var syntax = src.split('.').pop();
try {
comb.processString(css, { syntax: syntax }).then(function(combed) {
grunt.file.write(f.dest, combed);
grunt.file.write(dest, combed);
});
} catch(e) {
grunt.log.error(e);
Expand Down
13 changes: 13 additions & 0 deletions test/csscomb_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ exports.csscomb = {
var expected2 = grunt.file.read('test/expected/multi2.css');
test.equal(actual2, expected2, 'should be sorted.');

test.done();
},
src_only: function (test) {
test.expect(2);

var actual = grunt.file.read('test/fixtures/src/multi1.resorted.css');
var expected = grunt.file.read('test/expected/multi1.css');
test.equal(actual, expected, 'should be sorted.');

var actual2 = grunt.file.read('test/fixtures/src/multi2.resorted.css');
var expected2 = grunt.file.read('test/expected/multi2.css');
test.equal(actual2, expected2, 'should be sorted.');

test.done();
}
};
13 changes: 13 additions & 0 deletions test/fixtures/src/multi1.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.multi1 {
z-index: 100;
display: block;
visibility: hidden;
max-height: 44px;
width: 100px;
height: 100px;
border-color: 1px #000 solid;
background-color: red;
vertical-align: 5px;
text-align: center;
font-weight: bold;
}
19 changes: 19 additions & 0 deletions test/fixtures/src/multi1.resorted.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.multi1
{
font-weight: bold;

z-index: 100;

display: block;
visibility: hidden;

width: 100px;
height: 100px;
max-height: 44px;

text-align: center;
vertical-align: 5px;

border-color: 1px #000 solid;
background-color: red;
}
13 changes: 13 additions & 0 deletions test/fixtures/src/multi2.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.multi2 {
position: absolute;
top: 10px;
left: 10px;
z-index: 10;
display: table;
float: left;
margin: 10px;
padding: 10px;
width: 10px;
height: 10px;
border: 1px #fff solid;
}
17 changes: 17 additions & 0 deletions test/fixtures/src/multi2.resorted.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.multi2
{
position: absolute;
z-index: 10;
top: 10px;
left: 10px;

display: table;
float: left;

width: 10px;
height: 10px;
margin: 10px;
padding: 10px;

border: 1px #fff solid;
}

0 comments on commit de1a22e

Please sign in to comment.