Skip to content

Commit

Permalink
Commits from PR #98
Browse files Browse the repository at this point in the history
  • Loading branch information
vbwx committed Jun 23, 2015
1 parent b426d88 commit f5fd562
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 16 deletions.
6 changes: 3 additions & 3 deletions lib/helpers/raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ var TerraformError = exports.TerraformError = require("../error").TerraformError
*/

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


Expand Down Expand Up @@ -362,7 +362,7 @@ var outputPath = exports.outputPath = function(source, allowAlternateExtensions)
for(var targetExtension in processors){ // .html, .css, .js
if (processors.hasOwnProperty(targetExtension)) {
processors[targetExtension].forEach(function(sourceExtension){ // .jade, .ejs, .md
if (allowAlternateExtensions) {
if (allowAlternateExtensions && targetExtension !== sourceExtension) { // Don’t bother if it’s .js to .js
// Search for a alternate extension before the known source extension e.g. foobar.bar.jade
var alternateFileExtension = new RegExp("^.*\\.(\\w{3,4})\\." + sourceExtension + "$")
var match = alternateFileExtension.exec(source)
Expand Down
14 changes: 8 additions & 6 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')
var path = require("path")
var fs = require("fs")
var helpers = require('../helpers')
var minify = require('harp-minify')
var browserify = require('browserify')
var through = require('through')

Expand All @@ -20,7 +20,8 @@ helpers.processors["js"].forEach(function(sourceType){
extensions.push('.' + sourceType)
processors[sourceType] = require("./processors/" + sourceType)
})
processors['js'] = processors['es'] // so it's possible to require .js files

// processors['js'] = processors['es'] // so it's possible to require .js files

module.exports = function(root, filePath, callback){

Expand Down Expand Up @@ -70,7 +71,7 @@ module.exports = function(root, filePath, callback){
}

process.once('uncaughtException', exceptionHandler)
browserify(filePath, {extensions: extensions}).transform(function(file) {
browserify(srcPath, {extensions: extensions}).transform(function(file) {
var result = ''
return through(write, end)

Expand All @@ -80,6 +81,7 @@ module.exports = function(root, filePath, callback){
function end() {
if(success) {
var that = this
console.log(path.extname(file))
render(path.extname(file).replace(/^\./, '').toLowerCase(), result, function(err, data) {
that.queue(data)
that.queue(null)
Expand Down
File renamed without changes.
28 changes: 28 additions & 0 deletions lib/template/processors/hbs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var Handlebars = require('handlebars')
var TerraformError = require("../../error").TerraformError

module.exports = function(fileContents, options){

return {
compile: function(){
return Handlebars.compile(fileContents.toString(), options)
},

parseError: function(error){

var arr = error.message.split("\n")
var path_arr = arr[0].split(":")

error.lineno = parseInt(error.lineno || path_arr[path_arr.length -1] || -1)
error.message = arr[arr.length - 1]
error.name = error.name
error.source = "Handlebars"
error.dest = "HTML"
error.filename = error.path || options.filename
error.stack = fileContents.toString()

return new TerraformError(error)
}
}

}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"license": "MIT",
"dependencies": {
"autoprefixer": "5.1.0",
"handlebars": "1.3.0",
"browserify": "^10.2.4",
"coffee-script": "1.9.2",
"ejs": "1.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pow = require('./../../../../Math.js').pow

console.log pow(4)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var pow = require('./../../../../Math.js').pow;

console.log(pow(4));
28 changes: 21 additions & 7 deletions test/javascripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ describe("javascripts", function(){
})

})

describe("browserify", function() {
var root = __dirname + "/fixtures/javascripts/browserify"
var poly = polymer.root(root)

process.chdir(root)

it("should require coffeescript file in coffeescript", function(done) {
poly.render("require_coffee.coffee", function(errors, body) {
should.not.exist(errors)
Expand All @@ -63,14 +63,14 @@ describe("javascripts", function(){
})
})
it("should require coffeescript file in javascript", function(done) {
poly.render("require_coffee.es", function(errors, body) {
poly.render("require_coffee.js", function(errors, body) {
should.not.exist(errors)
body.should.include("MODULE_NOT_FOUND")
done()
})
})
it("should require javascript file in javascript", function(done) {
poly.render("require_js.es", function(errors, body) {
poly.render("require_js.js", function(errors, body) {
should.not.exist(errors)
body.should.include("MODULE_NOT_FOUND")
done()
Expand All @@ -84,7 +84,7 @@ describe("javascripts", function(){
})
})
it("should skip commented require in javascript", function(done) {
poly.render("comment.es", function(errors, body) {
poly.render("comment.js", function(errors, body) {
should.not.exist(errors)
body.should.not.include("MODULE_NOT_FOUND")
done()
Expand All @@ -98,12 +98,26 @@ describe("javascripts", function(){
})
})
it("should skip already declared require in javascript", function(done) {
poly.render("declared.es", function(errors, body) {
poly.render("declared.js", function(errors, body) {
should.not.exist(errors)
body.should.not.include("MODULE_NOT_FOUND")
done()
})
})
it("should require javascript file in heavily nested coffeescript", function(done) {
poly.render("nested/way/in/here/nested.coffee", function(errors, body) {
should.not.exist(errors)
body.should.include("MODULE_NOT_FOUND")
done()
})
})
it("should require javascript file in heavily nested javascript file", function(done) {
poly.render("nested/way/in/here/nested.js", function(errors, body) {
should.not.exist(errors)
body.should.include("MODULE_NOT_FOUND")
done()
})
})
})

})

0 comments on commit f5fd562

Please sign in to comment.