Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

browserify coffeescripts #33

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/javascript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,20 @@ 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, script) {
if (err) return callback(err)

/**
* Skip browserification if string does not contain
* any require() statements...
*/
if (!script.match(/require ?\(/)) return callback(err, script)

require('browserify-string')(script)
.bundle(function (err, script) {
callback(err, script)
});
})

})

Expand Down
4 changes: 2 additions & 2 deletions lib/terraform.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ exports.root = function(root, globals){
/**
* Render
*
* This is the main method to to render a view. This function is
* responsible to for figuring out the layout to use and sets the
* This is the main method to render a view. This function is
* responsible for figuring out the layout to use and sets the
* `current` object.
*
*/
Expand Down
38 changes: 27 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,44 @@
"name": "terraform",
"version": "0.6.2",
"description": "pre-processor engine that powers the harp web server",
"repository" : { "type" : "git", "url" : "https://github.com/sintaxi/terraform.git" },
"repository": {
"type": "git",
"url": "https://github.com/sintaxi/terraform.git"
},
"main": "./lib/terraform",
"scripts": {
"test": "mocha --reporter spec"
},
"author": "Brock Whitten <brock@chloi.io>",
"contributors": [
{ "name": "Brock Whitten", "email": "brock@chloi.io" },
{ "name": "Brian Donovan", "email": "donovan@squareup.com" },
{ "name": "Kenneth Ormandy", "email": "kenneth@chloi.io" },
{ "name": "Zhang Yichao", "email": "echaozh@gmail.com" }
{
"name": "Brock Whitten",
"email": "brock@chloi.io"
},
{
"name": "Brian Donovan",
"email": "donovan@squareup.com"
},
{
"name": "Kenneth Ormandy",
"email": "kenneth@chloi.io"
},
{
"name": "Zhang Yichao",
"email": "echaozh@gmail.com"
}
],
"license": "MIT",
"dependencies": {
"lru-cache" : "2.3.0",
"jade" : "0.35.0",
"coffee-script" : "1.6.3",
"ejs" : "0.8.4",
"lru-cache": "2.3.0",
"jade": "0.35.0",
"coffee-script": "1.6.3",
"ejs": "0.8.4",
"node-sass": "0.7.0",
"marked": "0.2.9",
"less" : "1.5.1",
"stylus": "0.40.0"
"less": "1.5.1",
"stylus": "0.40.0",
"browserify-string": "0.0.3"
},
"devDependencies": {
"mocha": "1.8.2",
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/javascripts/coffee/browserify.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
should = require('should')
19 changes: 19 additions & 0 deletions test/javascripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@ describe("javascripts", function(){
})
})

it("should browserify coffeescripts", function(done){
poly.render("browserify.coffee", function(errors, body){
should.not.exist(errors)
should.exist(body)
body.should.match(/typeof require=="function"/);
body.should.match(/should = require\('should'\);/);
done()
})
})

it("should not browserify scripts that don't contain 'require' statements", function(done){
poly.render("main.coffee", function(errors, body){
should.not.exist(errors)
should.exist(body)
body.should.not.match(/typeof require=="function"/);
done()
})
})

it("should return errors if invalid", function(done){
poly.render("invalid.coffee", function(errors, body){
should.exist(errors)
Expand Down