Skip to content

Commit

Permalink
Merge pull request #24 from jerone/issue-23
Browse files Browse the repository at this point in the history
🐛 Add support for Node 0.12 and node-sass 2.0. Fixes #23
  • Loading branch information
am11 committed Feb 14, 2015
2 parents b8b6032 + 6150d21 commit 8b6621c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
node_js:
- '0.10'
- '0.11'
- '0.12'
deploy:
provider: npm
email:
Expand Down
52 changes: 25 additions & 27 deletions middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ module.exports = function(options){
if (!src) { throw new Error('sass.middleware() requires "src" directory'); }

// Default dest dir to source
var dest = options.dest
? options.dest
: src;
var dest = options.dest || src;

var root = options.root || null;

Expand Down Expand Up @@ -111,31 +109,31 @@ module.exports = function(options){
var style = options.compile();
var paths = [];
delete imports[sassPath];
style.render(str, function(err, css){
if (err) { return next(err); }
if (debug) { log('render', options.response ? '<response>' : sassPath); }
imports[sassPath] = paths;

// If response is falsey, also write to file
if (!options.response) {
mkdirp(dirname(cssPath), 0700, function(err){
if (err) return error(err);
fs.writeFile(cssPath, css, 'utf8', function(err) {
if (err) return error(err);
});
});
}

res.writeHead(200, {
'Content-Type': 'text/css',
'Cache-Control': 'max-age=0'
});
res.end(css);
style.render({
data: str,
success: function(result){
if (debug) { log('render', options.response ? '<response>' : sassPath); }
imports[sassPath] = paths;

// If response is falsey, also write to file
if (!options.response) {
mkdirp(dirname(cssPath), 0700, function(err){
if (err) return error(err);
fs.writeFile(cssPath, result.css, 'utf8', function(err) {
if (err) return error(err);
});
});
}

}, {
include_paths: [ sassDir ].concat(options.include_paths || options.includePaths || []),
image_path: options.image_path || options.imagePath,
output_style: options.output_style || options.outputStyle
res.writeHead(200, {
'Content-Type': 'text/css',
'Cache-Control': 'max-age=0'
});
res.end(result.css);
},
includePaths: [ sassDir ].concat(options.include_paths || options.includePaths || []),
imagePath: options.image_path || options.imagePath,
outputStyle: options.output_style || options.outputStyle
});
});
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"dependencies": {
"mkdirp": "0.5.x",
"node-sass": "^1.0.0"
"node-sass": "^2.0.1"
},
"devDependencies": {
"connect": "^2.25.7",
Expand Down
10 changes: 5 additions & 5 deletions test/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,26 @@ describe('Using middleware', function () {

it('serves the compiled contents of the relative scss file', function (done) {
var filesrc = fs.readFileSync(scssfile),
css = sass.renderSync(filesrc.toString());
result = sass.renderSync({ data: filesrc.toString() });
request(server)
.get('/test.css')
.expect(css)
.expect(result.css)
.expect(200, done);
});

it('writes the file contents out to the expected file', function (done) {
var filesrc = fs.readFileSync(scssfile),
css = sass.renderSync(filesrc.toString());
result = sass.renderSync({ data: filesrc.toString() });
request(server)
.get('/test.css')
.expect(css)
.expect(result.css)
.expect(200, function (err) {
if (err) {
done(err);
} else {
(function checkFile() {
if (fs.existsSync(cssfile)) {
fs.readFileSync(cssfile).toString().should.equal(css);
fs.readFileSync(cssfile).toString().should.equal(result.css);
done();
} else {
setTimeout(checkFile, 25);
Expand Down

0 comments on commit 8b6621c

Please sign in to comment.