-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d25f0bb
commit 509f0a2
Showing
8 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,5 @@ results | |
|
||
npm-debug.log | ||
node_modules | ||
|
||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.myclass { | ||
background: #eee; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.shouldnotchange { | ||
width: 50%; | ||
color: red; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
$color: #eee; | ||
|
||
.myclass { | ||
background: $color; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.shouldnotchange { | ||
width: 50%; | ||
color: red; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}()); |