Skip to content

Commit

Permalink
Bring in Node-sass update. Why not?
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethormandy committed Jan 12, 2014
2 parents c65d625 + ef55125 commit 4c081f8
Show file tree
Hide file tree
Showing 16 changed files with 106 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# terraform
# terraform

> Terraform is the pre-processor engine for the Harp Web Server. Terraform does not write or serve files. It processes and provides a layout/partial paradgm.
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var TerraformError = exports.TerraformError = require("../error").TerraformError

var processors = exports.processors = {
"html": ["jade", "ejs", "md"],
"css" : ["styl", "less"],
"css" : ["styl", "less", "scss"],
"js" : ["coffee"]
}

Expand Down
1 change: 1 addition & 0 deletions lib/javascript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module.exports = function(root, filePath, callback){
/**
* Lookup Directories
*/

var render = processors[ext].compile(srcPath, data, callback)

})
Expand Down
2 changes: 1 addition & 1 deletion lib/stylesheet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = function(root, filePath, callback){
var srcPath = path.resolve(root, filePath)
var ext = path.extname(srcPath).replace(/^\./, '')


fs.readFile(srcPath, function(err, data){

/**
Expand Down Expand Up @@ -51,7 +52,6 @@ module.exports = function(root, filePath, callback){
/**
* Lookup Directories
*/

var render = processors[ext].compile(srcPath, dirs, data, callback)

})
Expand Down
26 changes: 26 additions & 0 deletions lib/stylesheet/processors/scss.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var scss = require("node-sass")
var TerraformError = require("../../error").TerraformError

exports.compile = function(filePath, dirs, fileContents, callback){
scss.render({
file: filePath,
includePaths: dirs,
success: function(css) {
callback(null, css);
},
error: function(e) {
var arr = e.split(":")
var error = new TerraformError ({
source: "SCSS",
dest: "CSS",
lineno: arr[1] || 99,
name: "SCSS Error",
message: (arr[4] ? arr[3].replace("Backtrace", "").trim() + " " + arr[4].trim() : arr[3].trim()).replace(/"/g, '\\"'),
filename: arr[0] || filePath,
stack: fileContents.toString()
})
return callback(error)
},
outputStyle: 'compressed'
});
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "terraform",
"version": "0.6.1",
"version": "0.6.2",
"description": "pre-processor engine that powers the harp web server",
"repository" : { "type" : "git", "url" : "https://github.com/sintaxi/terraform.git" },
"main": "./lib/terraform",
Expand All @@ -20,6 +20,8 @@
"jade" : "0.35.0",
"coffee-script" : "1.6.3",
"ejs" : "0.8.5",
"ejs" : "0.8.4",
"node-sass": "0.8.0",
"marked": "0.2.9",
"less" : "1.6.1",
"stylus": "0.42.0"
Expand Down
3 changes: 1 addition & 2 deletions test/contents.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ describe("contents", function(){
var poly = polymer.root(root)
poly.render("pub.json.jade", { "layout": false }, function(err, result){
var pub = JSON.parse(result)
console.log(pub)
should.exist(pub["_contents"])
done()
})
})
})

})
})
32 changes: 31 additions & 1 deletion test/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,34 @@ describe("errors", function(){
})
})

})
describe(".scss", function(){
it("should get error if var missing in scss", function(done){
poly.render("scss/novar.scss", function(error, body){
should.not.exist(body)
should.exist(error)
error.should.have.property('source')
error.should.have.property('dest')
error.should.have.property('lineno')
error.should.have.property('filename')
error.should.have.property('message')
error.should.have.property('stack')
done()
})
})

it("should get errors if syntax not correct", function(done){
poly.render("scss/invalid.scss", function(error, body){
should.not.exist(body)
should.exist(error)
error.should.have.property('source')
error.should.have.property('dest')
error.should.have.property('lineno')
error.should.have.property('filename')
error.should.have.property('message')
error.should.have.property('stack')
done()
})
})
})

})
2 changes: 1 addition & 1 deletion test/fixtures/errors/jade/invalid.jade
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

//- keep on line 3
if (youAreUsingJade youAreUsingJade
if (youAreUsingJade youAreUsingJade
1 change: 1 addition & 0 deletions test/fixtures/errors/scss/invalid.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
darken(asdlnasd
3 changes: 3 additions & 0 deletions test/fixtures/errors/scss/novar.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background: @fail;
}
3 changes: 3 additions & 0 deletions test/fixtures/stylesheets/scss/_part.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background: darken(red, 20%);
}
3 changes: 3 additions & 0 deletions test/fixtures/stylesheets/scss/invalid.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background: $main;
}
9 changes: 9 additions & 0 deletions test/fixtures/stylesheets/scss/main.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@import "part";

$pink: #ffc3cd;
$black: #000;

body {
background: $pink;
color: $black;
}
4 changes: 2 additions & 2 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ describe("helpers", function(){
it('should build priority list for css file.', function(done){
var list = polymer.helpers.buildPriorityList('main.css')
list.should.be.an.instanceOf(Array)
list.should.have.lengthOf(4)
list.should.eql("main.styl, main.less, main.css.styl, main.css.less".split(', '))
list.should.have.lengthOf(6)
list.should.eql("main.styl, main.less, main.scss, main.css.styl, main.css.less, main.css.scss".split(', '))
done()
})

Expand Down
19 changes: 19 additions & 0 deletions test/stylesheets.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,23 @@ describe("stylesheets", function(){

})

describe(".scss", function(){

var root = __dirname + '/fixtures/stylesheets/scss'
var poly = polymer.root(root)

console.log(root);

it("should have basic css file", function(done){
poly.render("main.scss", function(error, body){
should.not.exist(error)
should.exist(body)
body.should.include("background:#ffc3cd")
body.should.include("color:#000")
done()
})
})

})

})

0 comments on commit 4c081f8

Please sign in to comment.