diff --git a/.gitignore b/.gitignore index ac4d94dfe..f38640614 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules *.swp *.log +.eyeglass_cache diff --git a/lib/stylesheet/processors/sass.js b/lib/stylesheet/processors/sass.js index 786c5f18a..021168746 100644 --- a/lib/stylesheet/processors/sass.js +++ b/lib/stylesheet/processors/sass.js @@ -1,8 +1,9 @@ var sass = require("node-sass") +var eyeglass = require("eyeglass") var TerraformError = require("../../error").TerraformError exports.compile = function(filePath, dirs, fileContents, callback){ - sass.render({ + var opts = { file: filePath, includePaths: dirs, outputStyle: 'compressed', @@ -10,8 +11,15 @@ exports.compile = function(filePath, dirs, fileContents, callback){ sourceMapEmbed: false, sourceMapContents: true, outFile: filePath, - omitSourceMapUrl: true - }, function (e, css) { + omitSourceMapUrl: true, + eyeglass: { + engines: { + sass: sass + } + } + } + + sass.render(eyeglass(opts), function (e, css) { if (e) { var error = new TerraformError ({ source: "Sass", @@ -24,7 +32,7 @@ exports.compile = function(filePath, dirs, fileContents, callback){ }) return callback(error) } - + callback(null, css.css, css.map.toString()) }); } diff --git a/lib/stylesheet/processors/scss.js b/lib/stylesheet/processors/scss.js index 3def095a7..7890e90d8 100644 --- a/lib/stylesheet/processors/scss.js +++ b/lib/stylesheet/processors/scss.js @@ -1,8 +1,9 @@ var scss = require("node-sass") +var eyeglass = require("eyeglass") var TerraformError = require("../../error").TerraformError exports.compile = function(filePath, dirs, fileContents, callback){ - scss.render({ + var opts = { file: filePath, includePaths: dirs, outputStyle: 'compressed', @@ -10,8 +11,15 @@ exports.compile = function(filePath, dirs, fileContents, callback){ sourceMapEmbed: false, sourceMapContents: true, outFile: filePath, - omitSourceMapUrl: true - }, function (e, css) { + omitSourceMapUrl: true, + eyeglass: { + engines: { + sass: scss + } + } + } + + scss.render(eyeglass(opts), function (e, css) { if (e) { var error = new TerraformError ({ source: "Sass", diff --git a/package.json b/package.json index bc8e73f1d..211e6c91f 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,8 @@ "through": "2.3.8" }, "devDependencies": { + "eyeglass": "0.8.1", + "eyeglass-sample": "0.0.3", "mocha": "2.3.4", "should": "1.2.2" } diff --git a/test/fixtures/stylesheets/sass/eyeglass.sass b/test/fixtures/stylesheets/sass/eyeglass.sass new file mode 100644 index 000000000..d8184569d --- /dev/null +++ b/test/fixtures/stylesheets/sass/eyeglass.sass @@ -0,0 +1,4 @@ +@import "eyeglass-sample" + +.sass:before + content: hello("Kenneth") diff --git a/test/fixtures/stylesheets/scss/eyeglass.scss b/test/fixtures/stylesheets/scss/eyeglass.scss new file mode 100644 index 000000000..0bcdcb2ff --- /dev/null +++ b/test/fixtures/stylesheets/scss/eyeglass.scss @@ -0,0 +1,7 @@ +@import "eyeglass-sample"; + +body { + &:before { + content: hello("Kenneth") + } +} diff --git a/test/stylesheets.js b/test/stylesheets.js index fb71e337d..a563e7bb1 100644 --- a/test/stylesheets.js +++ b/test/stylesheets.js @@ -146,6 +146,17 @@ describe("stylesheets", function(){ done() }) }) + it("should include an Eyeglass module in an SCSS file", function (done) { + poly.render("eyeglass.scss", function(error, body, sourcemap) { + should.not.exist(error) + should.exist(body) + should.exist(sourcemap) + body.should.include("Kenneth") + body.should.include("hello") + body.should.include(".sassy") + done() + }) + }) }) @@ -194,6 +205,18 @@ describe("stylesheets", function(){ done() }) }) + it("should include an SCSS Eyeglass module in a Sass file", function (done) { + poly.render("eyeglass.sass", function(error, body, sourcemap) { + should.not.exist(error) + should.exist(body) + should.exist(sourcemap) + body.should.include("Kenneth") + body.should.include("hello") + body.should.include(".sassy") + done() + }) + }) + })