Skip to content

Commit

Permalink
Merge branch 'crazy2be-only-toString-sass-files' into v1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenschobert committed Jan 20, 2019
2 parents b8c1f2c + d443be9 commit 1bcbc6d
Showing 1 changed file with 45 additions and 41 deletions.
86 changes: 45 additions & 41 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@
},

compile = function(config, basePath, files, filename, done) {
if (isPartial(filename)) {
delete files[filename];
done();
return;
}

if (!isAnySassFile(filename)) {
done();
return;
}

var file = files[filename],
filePath = path.join(basePath, filename),
opts = extend({
Expand All @@ -57,54 +68,47 @@
opts.outFile = filePath.replace(/\.s[ca]ss/, '.css');
}

if (isAnySassFile(filename) === true) {
// Append the file's base path to the available include paths.
opts.includePaths.push(fileDir);

// Compile the file using SASS.
sass.render(opts, function (err, result) {
var error = null;

if (err && err instanceof Error) {
error = new Error([
'[metalsmith-sass] Error: ',
err.message, ' -> ',
err.file,
':',
err.line, ':', err.column
].join(''));
} else if (err) {
error = new Error(err);
}
// Append the file's base path to the available include paths.
opts.includePaths.push(fileDir);

// Compile the file using SASS.
sass.render(opts, function (err, result) {
var error = null;

if (err && err instanceof Error) {
error = new Error([
'[metalsmith-sass] Error: ',
err.message, ' -> ',
err.file,
':',
err.line, ':', err.column
].join(''));
} else if (err) {
error = new Error(err);
}

if (error) {
done(error);
return;
}
if (error) {
done(error);
return;
}

// add soure map
if (result.map) {
files[dest+'.map'] = {
contents: result.map,
mode: file.mode
};
}
// add soure map
if (result.map) {
files[dest+'.map'] = {
contents: result.map,
mode: file.mode
};
}

// replace contents
file.contents = result.css;
// replace contents
file.contents = result.css;

// rename file extension
files[dest] = file;
// rename file extension
files[dest] = file;

delete files[filename];
done();
});
} else if (isPartial(filename) === true) {
delete files[filename];
done();
} else {
done();
}
});
},

compileSass = function compileSass(config, files, metalsmith, done) {
Expand Down

0 comments on commit 1bcbc6d

Please sign in to comment.