Skip to content

Commit

Permalink
Merge pull request #59 from sintaxi/release-v0.9.1
Browse files Browse the repository at this point in the history
Release v0.9.1
  • Loading branch information
sintaxi committed Feb 6, 2015
2 parents 8540c7a + 3d2da7c commit 0b4d119
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 17 deletions.
17 changes: 14 additions & 3 deletions lib/javascript/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

var path = require("path")
var fs = require("fs")
var helpers = require('../helpers')
var minify = require('minify')

/**
* Build Processor list for javascripts.
Expand Down Expand Up @@ -41,8 +41,19 @@ module.exports = function(root, filePath, callback){
* Lookup Directories
*/

var render = processors[ext].compile(srcPath, data, callback)
var render = processors[ext].compile(srcPath, data, function(err, js) {
if (err) return callback(err);

/**
* Consistently minify
*/
var post = minify.js(js, {
compress: false,
mangle: true
});
callback(null, post);
})

})

}
}
8 changes: 6 additions & 2 deletions lib/stylesheet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var path = require("path")
var fs = require("fs")
var helpers = require('../helpers')
var autoprefixer = require('autoprefixer')
var minify = require('minify')

/**
* Build Processor list for stylesheets.
Expand Down Expand Up @@ -56,8 +57,11 @@ module.exports = function(root, filePath, callback){
var render = processors[ext].compile(srcPath, dirs, data, function(err, css) {
if (err) return callback(err);

var prefixed = autoprefixer.process(css).css;
callback(null, prefixed);
/**
* Autoprefix, then consistently minify
*/
var post = minify.css(autoprefixer.process(css).css);
callback(null, post);
})

})
Expand Down
6 changes: 3 additions & 3 deletions lib/template/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

var fs = require("fs")
var path = require("path")
var helpers = require('../helpers')
var minify = require('minify')


/**
Expand Down Expand Up @@ -157,10 +157,10 @@ var scope = module.exports = function(projectPath, partentLocals){


/**
* render the layout (if there is one) with the output of the template as yield.
* render the layout (if there is one) with the minified output of the template as yield.
*/

if(layout) output = scope(projectPath, locals).partial(layout, { yield: output })
if(layout) output = scope(projectPath, locals).partial(layout, { yield: minify.html(output) })

return output

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "terraform",
"version": "0.9.0",
"version": "0.9.1",
"description": "pre-processor engine that powers the harp web server",
"repository": {
"type": "git",
Expand Down Expand Up @@ -30,7 +30,8 @@
"marked": "0.2.9",
"less": "1.7.4",
"stylus": "0.47.3",
"autoprefixer": "~2.2.0"
"autoprefixer": "~2.2.0",
"minify": "git://github.com/ianstormtaylor/minify#0.2.0"
},
"devDependencies": {
"mocha": "1.8.2",
Expand Down
5 changes: 4 additions & 1 deletion test/fixtures/javascripts/coffee/main.coffee
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@



add = (x, y) ->
return x + y
return x + y
1 change: 1 addition & 0 deletions test/fixtures/javascripts/coffee/unused.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
() -> alert("hello world")
7 changes: 6 additions & 1 deletion test/fixtures/templates/bio.ejs
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@





<h1>Hello EJS</h1>
<%- partial("stuff.md") %>
<%- partial("stuff.md") %>
6 changes: 5 additions & 1 deletion test/fixtures/templates/index.jade
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@




h2 Hello World
!= partial("profile.jade")
!= partial("stuff.md")
h4= place
pre
!= JSON.stringify(locals, null, 2)
include location
include location
6 changes: 5 additions & 1 deletion test/fixtures/templates/nest/stuff.jade
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
h2 hi




h2 hi
6 changes: 5 additions & 1 deletion test/fixtures/templates/stuff.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@




# hello markdown

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Expand All @@ -9,4 +13,4 @@ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
"date": "1610-01-01"
}
}
```
```
14 changes: 14 additions & 0 deletions test/javascripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ describe("javascripts", function(){
done()
})
})
it("should minify beyond preprocessor", function(done){
poly.render("main.coffee", function(errors, body){
should.not.exist(errors)
body.should.not.include("\n\n")
done()
})
})
it("shouldn’t strip unused javascript when minifying", function(done){
poly.render("unused.coffee", function(errors, body){
should.not.exist(errors)
body.should.include("alert")
done()
})
})

it("should return errors if invalid", function(done){
poly.render("invalid.coffee", function(errors, body){
Expand Down
4 changes: 2 additions & 2 deletions test/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ describe("render(path, callback)", function(){
poly.render("less.less", function(errors, body){
should.not.exist(errors)
should.exist(body)
body.should.include("body{background:#FF00AA}")
body.should.include("body{background:#F0A}")
done()
})
})
Expand All @@ -188,7 +188,7 @@ describe("render(path, callback)", function(){
poly.render("scss.scss", function(errors, body){
should.not.exist(errors)
should.exist(body)
body.should.include("body{background:#FF00AA;}")
body.should.include("body{background:#F0A}")
done()
})
})
Expand Down
55 changes: 55 additions & 0 deletions test/stylesheets.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,25 @@ describe("stylesheets", function(){
poly.render("main.less", function(error, body){
should.not.exist(error)
body.should.include("background:#ffc0cb")
done()
})
})
it("should autoprefix css", function(done){
poly.render("main.less", function(error, body){
should.not.exist(error)
body.should.include("-webkit-font-feature-settings")
done()
})
})

it("should minify beyond preprocessor", function(done){
poly.render("main.less", function(error, body){
should.not.exist(error)
body.should.not.include(";}")
done()
})
})



})
Expand All @@ -31,11 +45,26 @@ describe("stylesheets", function(){
should.not.exist(error)
should.exist(body)
body.should.include("background:#ffc0cb")
done()
})
})

it("should autoprefix css", function(done){
poly.render("main.styl", function(error, body){
should.not.exist(error)
body.should.include("-webkit-font-feature-settings")
done()
})
})

it("should minify beyond preprocessor", function(done){
poly.render("main.styl", function(error, body){
should.not.exist(error)
body.should.not.include(";}")
done()
})
})

})

describe(".scss", function(){
Expand All @@ -51,10 +80,23 @@ describe("stylesheets", function(){
should.exist(body)
body.should.include("background:#ffc3cd")
body.should.include("color:#000")
done()
})
})
it("should autoprefix css", function(done){
poly.render("main.scss", function(error, body){
should.not.exist(error)
body.should.include("-webkit-font-feature-settings")
done()
})
})
it("should minify beyond preprocessor", function(done){
poly.render("main.scss", function(error, body){
should.not.exist(error)
body.should.not.include(";}")
done()
})
})

})

Expand All @@ -71,10 +113,23 @@ describe("stylesheets", function(){
should.exist(body)
body.should.include("background:#ffc3cd")
body.should.include("color:#000")
done()
})
})
it("should autoprefix css", function(done){
poly.render("main.sass", function(error, body){
should.not.exist(error)
body.should.include("-webkit-font-feature-settings")
done()
})
})
it("should minify beyond preprocessor", function(done){
poly.render("main.sass", function(error, body){
should.not.exist(error)
body.should.not.include(";}")
done()
})
})

})

Expand Down
24 changes: 24 additions & 0 deletions test/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ describe("templates", function(){
done()
})
})

it("should minify beyond preprocessor", function(done){
poly.render("bio.ejs", function(error, body){
should.not.exist(error)
body.should.not.include("\n\n")
done()
})
})
})

describe(".md", function(){
Expand All @@ -30,6 +38,14 @@ describe("templates", function(){
})
})

it("should minify beyond preprocessor", function(done){
poly.render("stuff.md", function(error, body){
should.not.exist(error)
body.should.not.include("\n\n")
done()
})
})

it("should render markdown file encoded in UTF-8 with BOM", function(done){
poly.render("bom.md", function(error, body){
should.not.exist(error)
Expand All @@ -54,6 +70,14 @@ describe("templates", function(){
})
})

it("should minify beyond preprocessor", function(done){
poly.render("index.jade", function(error, body){
should.not.exist(error)
body.should.not.include("\n\n")
done()
})
})

it("should pass in partials from the global object", function(done){
poly.render("index.jade", function(error, body){
should.not.exist(error)
Expand Down

0 comments on commit 0b4d119

Please sign in to comment.