Skip to content

Commit

Permalink
first pass
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenschobert committed Mar 11, 2014
1 parent d25f0bb commit 509f0a2
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ results

npm-debug.log
node_modules

build/
52 changes: 52 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
(function() {
'use strict';

var sass = require('node-sass'),
each = require('async').each,
join = require('path').join,

isSassFile = function isSassFile(filename) {
return (/.*\.scss/).test(filename);
},

compile = function(basePath, files, filename, done) {
var file = files[filename],
includes = this.includePaths || [],
outputStyle = this.outputStyle || 'compressed',
imagePath = this.imagePath || '/';

if (isSassFile(filename) === true) {
sass.render({
file: join(basePath, filename),
includePaths: includes,
imagePath: imagePath,
outputStyle: outputStyle,
success: function(css) {
// replace contents
file.contents = new Buffer(css);
// rename file extension
files[filename.replace('.scss', '.css')] = file;
delete files[filename];
done();
},
error: function(err) {
throw err;
}
});
} else {
done();
}
},

compileSass = function compileSass(files, metalsmith, done) {
var basePath = join(metalsmith.dir, metalsmith._src);
each(Object.keys(files), compile.bind(this, basePath, files), done);
},

plugin = function plugin(options) {
var config = options || {};
return compileSass.bind(config);
};

module.exports = plugin;
}());
33 changes: 33 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "metalsmith-sass",
"version": "0.1.0",
"description": "Sass plugin for Metalsmith.",
"main": "lib/index.js",
"scripts": {
"test": "mocha --reporter spec test/test.js"
},
"repository": {
"type": "git",
"url": "git://github.com/stevenschobert/metalsmith-sass.git"
},
"keywords": [
"metalsmith",
"sass"
],
"author": "Steven Schobert <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/stevenschobert/metalsmith-sass/issues"
},
"homepage": "https://github.com/stevenschobert/metalsmith-sass",
"devDependencies": {
"metalsmith": "^0.3.0",
"mocha": "^1.17.1",
"rimraf": "^2.2.6",
"assert-dir-equal": "^1.0.1"
},
"dependencies": {
"async": "^0.2.10",
"node-sass": "^0.8.1"
}
}
2 changes: 2 additions & 0 deletions test/fixtures/basic/expected/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.myclass {
background: #eee; }
4 changes: 4 additions & 0 deletions test/fixtures/basic/expected/oldfile.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.shouldnotchange {
width: 50%;
color: red;
}
5 changes: 5 additions & 0 deletions test/fixtures/basic/src/main.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$color: #eee;

.myclass {
background: $color;
}
4 changes: 4 additions & 0 deletions test/fixtures/basic/src/oldfile.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.shouldnotchange {
width: 50%;
color: red;
}
37 changes: 37 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
(function () {
"use strict";

var each = require("async").each,
join = require("path").join,
metalsmith = require("metalsmith"),
rm = require("rimraf"),
sass = require(".."),
equal = require("assert-dir-equal");

describe("the plugin", function () {
beforeEach(function (done) {
var dirsToClean = [
join(__dirname, "fixtures/basic/build")
];
each(dirsToClean, rm, done);
});

describe("core", function () {
it("should compile sass files", function (done) {
metalsmith(__dirname)
.source("fixtures/basic/src")
.destination("fixtures/basic/build")
.use(sass({
outputStyle: 'expanded'
}))
.build(function (err) {
if (err) {
throw err;
}
equal(join(__dirname, "fixtures/basic/build"), join(__dirname, "fixtures/basic/expected"));
done();
});
});
});
});
}());

0 comments on commit 509f0a2

Please sign in to comment.