Skip to content

Commit

Permalink
Ignore "_" partial files
Browse files Browse the repository at this point in the history
This matches the expected behaviour in Ruby globbing
  • Loading branch information
nschonni committed Dec 8, 2013
1 parent 26921ef commit 26b1e30
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ module.exports = function (grunt) {
'test/tmp/source-comments.css': 'test/fixtures/test.scss'
}
},
ignorePartials: {
cwd: 'test/fixtures/partials',
src: '*.scss',
dest: 'test/tmp',
expand: true,
ext: '.css'
}
},
nodeunit: {
tasks: ['test/test.js']
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ grunt.loadNpmTasks('grunt-sass');

See the [Gruntfile](https://github.com/sindresorhus/grunt-sass/blob/master/Gruntfile.js) in this repo for a full example.

Note: Files that begin with "_" are ignored even if they match the globbing pattern. This is done to match the expected [Sass partial behaviour](http://sass-lang.com/documentation/file.SASS_REFERENCE.html#partials).

### Options

Expand Down
8 changes: 7 additions & 1 deletion tasks/sass.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
var sass = require('node-sass');
var async = require('async');
var path = require('path');

module.exports = function (grunt) {
grunt.registerMultiTask('sass', 'Compile SCSS to CSS', function () {
Expand All @@ -11,8 +12,13 @@ module.exports = function (grunt) {
});

async.eachSeries(this.files, function (el, next) {
var src = el.src[0];
if (path.basename(src)[0] === '_') {
return next();
}

sass.render({
file: el.src[0],
file: src,
success: function (css) {
grunt.file.write(el.dest, css);
grunt.log.writeln('File "' + el.dest + '" created.');
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/partials/_partial.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.foo {
color: red;
}
7 changes: 7 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ exports.sass = {
var actual = grunt.file.read('test/tmp/source-comments.css');
test.ok(/^\/\* line 1/.test(actual), 'should include sourceComments');

test.done();
},
ignorePartials: function (test) {
test.expect(1);

test.ok(!grunt.file.exists('test/tmp/_partial.css'), 'underscore partial files should be ignored');

test.done();
}
};

0 comments on commit 26b1e30

Please sign in to comment.