Added: Default for includePaths option

This commit is contained in:
David Manning 2014-01-22 12:52:04 -08:00
parent 137d01d374
commit d009ffb818
4 changed files with 14 additions and 16 deletions

View file

@ -36,7 +36,7 @@ If you pass `errLogToConsole: true` into the options hash, sass errors will be l
#Imports and Partials #Imports and Partials
If you want to use imports or partials, you'll need to pass the `includePaths` option along to node-sass. So if you have files like this: gulp-sass now automatically passes along the directory of every scss file it parses as an include path for node-sass. This means that as long as you specify your includes relative to path of your scss file, everything will just work.
scss/includes/_settings.scss: scss/includes/_settings.scss:
@ -48,7 +48,7 @@ $margin: 16px;
scss/style.scss: scss/style.scss:
```scss ```scss
@import "settings"; @import "includes/settings";
.content-navigation { .content-navigation {
border-color: $blue; border-color: $blue;
@ -63,12 +63,3 @@ scss/style.scss:
} }
``` ```
Your code should look something like this:
```javascript
gulp.task('sass', function () {
gulp.src('./scss/*.scss')
.pipe(sass({includePaths: ['scss/includes']}))
.pipe(gulp.dest('./css'));
});
```

View file

@ -19,6 +19,16 @@ module.exports = function (options) {
opts.data = file.contents.toString(); opts.data = file.contents.toString();
var fileDir = path.dirname(file.path);
if (opts.includePaths && Array.isArray(opts.includePaths)) {
if (opts.includePaths.indexOf(fileDir) === -1) {
opts.includePaths.push(fileDir)
}
} else {
opts.includePaths = [fileDir];
}
opts.success = function (css) { opts.success = function (css) {
file.path = ext(file.path, '.css'); file.path = ext(file.path, '.css');
file.contents = new Buffer(css); file.contents = new Buffer(css);

View file

@ -1,4 +1,4 @@
@import "cats"; @import "includes/cats";
.error { .error {
border: #f00; border: #f00;

View file

@ -67,10 +67,7 @@ test('compile multiple sass files', function (t) {
]; ];
t.plan(files.length * 4); t.plan(files.length * 4);
var stream = gsass({ var stream = gsass();
includePaths: [path.join(__dirname, 'scss'),
path.join(__dirname, 'scss/includes')]
});
stream.on('data', function (cssFile) { stream.on('data', function (cssFile) {
t.ok(cssFile, 'cssFile exists'); t.ok(cssFile, 'cssFile exists');