Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
language: node_js
node_js:
- "0.10"
- "0.12"
2 changes: 1 addition & 1 deletion lib/helpers/raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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"]
}
Expand Down
2 changes: 1 addition & 1 deletion 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 minify = require('harp-minify')

/**
* Build Processor list for javascripts.
Expand Down
2 changes: 1 addition & 1 deletion lib/stylesheet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var path = require("path")
var fs = require("fs")
var helpers = require('../helpers')
var autoprefixer = require('autoprefixer')
var minify = require('minify')
var minify = require('harp-minify')

/**
* Build Processor list for stylesheets.
Expand Down
2 changes: 1 addition & 1 deletion 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')
var minify = require('harp-minify')


/**
Expand Down
45 changes: 45 additions & 0 deletions lib/template/processors/hbs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var Handlebars = require('handlebars')
var TerraformError = require("../../error").TerraformError

module.exports = function(fileContents, options){

/**
* Provides support to load partials.
*
* @usage without locals
* {{partial '../foo.md'}}
*
* @example with provided locals
* {{partial '../foo.jade' locals='{ "a": "b" }'}}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete locals= here for clarity. I did have an alternate branch with option 3 implemented, if you wanted to provide the "locals" helper as well. See commit ef88790.

*
* @returns {Handlebars.SafeString} HTML-safe rendered partial
*/
Handlebars.registerHelper('partial', function(filePath, options) {
var locals = options || {};
if (typeof locals === 'string') locals = JSON.parse(locals)
return new Handlebars.SafeString(this.partial(filePath, locals))
});

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 = "HBS"
error.dest = "HTML"
error.filename = error.path || options.filename
error.stack = fileContents.toString()

return new TerraformError(error)
}
}

}
2 changes: 1 addition & 1 deletion lib/template/processors/jade.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var jade = require('jade')
var jade = require('harp-jade')
var TerraformError = require("../../error").TerraformError

module.exports = function(fileContents, options){
Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@
],
"license": "MIT",
"dependencies": {
"lru-cache": "2.6.1",
"jade": "git://github.com/harp/jade#v1.9.3-bc.2",
"lru-cache": "2.6.4",
"harp-jade": "1.9.3-bc.4",
"coffee-script": "1.9.2",
"ejs": "1.0.0",
"node-sass": "3.0.0-beta.5",
"ejs": "2.3.1",
"node-sass": "3.1.2",
"marked": "0.3.3",
"less": "2.5.0",
"less": "2.5.1",
"stylus": "0.47.3",
"minify": "git://github.com/kennethormandy/minify#v0.3.0",
"autoprefixer": "5.1.0"
"harp-minify": "0.3.2",
"autoprefixer": "5.1.1",
"handlebars": "3.0.3"
},
"devDependencies": {
"mocha": "1.8.2",
Expand Down
5 changes: 4 additions & 1 deletion test/fixtures/globals/_data.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"about":{
"title": "About Page"
},
"blog": {
"title": "Blog Page"
}
}
}
1 change: 1 addition & 0 deletions test/fixtures/globals/blog.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>{{ title }}</h1>
7 changes: 7 additions & 0 deletions test/fixtures/globals/contact.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>{{ title }}</title>
</head>
<h1>{{ name }}</h1>
</html>
1 change: 1 addition & 0 deletions test/fixtures/templates/content.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Hello! This is {{!-- should be invisible --}}Handlebars!</h1>
2 changes: 2 additions & 0 deletions test/fixtures/templates/hbs/partials-with-data.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Hello Handlebars</h1>
{{partial '../profile.jade' '{ "title": "Brock Whitten" }' }}
2 changes: 2 additions & 0 deletions test/fixtures/templates/hbs/partials.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Hello Handlebars</h1>
{{partial '../stuff.md' }}
2 changes: 1 addition & 1 deletion test/fixtures/templates/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


h2 Hello World
!= partial("profile.jade")
!= partial("profile.jade", { title: "Brock Whitten" })
!= partial("stuff.md")
h4= place
pre
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/templates/profile.jade
Original file line number Diff line number Diff line change
@@ -1 +1 @@
h3 Brock Whitten
h3= title
15 changes: 13 additions & 2 deletions test/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,37 @@ describe("data", function(){

describe("valid", function(){
var root = __dirname + "/fixtures/globals"
var poly = polymer.root(root, { "title": "Default Title" })
var poly = polymer.root(root, { "title": "Default Title", "name": "Annie Person" })

it("should have global available by default", function(done){
poly.render("index.jade", function(error, body){
should.not.exist(error)
should.exist(body)
body.should.include("<title>Default Title</title>")
})
poly.render("contact.hbs", function(error, body){
should.not.exist(error)
should.exist(body)
body.should.include("<h1>Annie Person</h1>")
done()
})

})

it("should be able to override globals in the template vars", function(done){
poly.render("about.jade", function(error, body){
should.not.exist(error)
should.exist(body)
body.should.include("<title>About Page</title>")
})
poly.render("blog.hbs", function(error, body){
should.not.exist(error)
should.exist(body)
body.should.include("<h1>Blog Page</h1>")
done()
})
})

})

})
})
17 changes: 9 additions & 8 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ describe("helpers", function(){
it('should return all possible file names for html ordered by priority.', function(done){
var list = polymer.helpers.buildPriorityList('index.html')
list.should.be.an.instanceOf(Array)
list.should.have.lengthOf(6)
var plist = "index.jade, index.ejs, index.md, index.html.jade, index.html.ejs, index.html.md".split(', ')
list.should.have.lengthOf(8)
var plist = "index.jade, index.ejs, index.md, index.hbs, index.html.jade, index.html.ejs, index.html.md, index.html.hbs".split(', ')
list.should.eql(plist)
done()
})
Expand All @@ -26,27 +26,28 @@ describe("helpers", function(){
it('should build priority list assuming template file when unknown.', function(done){
var list = polymer.helpers.buildPriorityList('feed.xml')
list.should.be.an.instanceOf(Array)
list.should.have.lengthOf(3)
list.should.eql('feed.xml.jade, feed.xml.ejs, feed.xml.md'. split(', '))
list.should.have.lengthOf(4)
list.should.eql('feed.xml.jade, feed.xml.ejs, feed.xml.md, feed.xml.hbs'. split(', '))
done()
})

it('should look for templates on json files.', function(done){
var list = polymer.helpers.buildPriorityList('profile.json')
list.should.be.an.instanceOf(Array)
list.should.have.lengthOf(3)
list.should.have.lengthOf(4)
list.should.include('profile.json.jade')
list.should.include('profile.json.ejs')
list.should.include('profile.json.md')
list.should.eql('profile.json.jade, profile.json.ejs, profile.json.md'. split(', '))
list.should.include('profile.json.hbs')
list.should.eql('profile.json.jade, profile.json.ejs, profile.json.md, profile.json.hbs'. split(', '))
done()
})

it('should look for templates when no ext present.', function(done){
var list = polymer.helpers.buildPriorityList('appcache')
list.should.be.an.instanceOf(Array)
list.should.have.lengthOf(3)
list.should.eql('appcache.jade, appcache.ejs, appcache.md'.split(', '))
list.should.have.lengthOf(4)
list.should.eql('appcache.jade, appcache.ejs, appcache.md, appcache.hbs'.split(', '))
done()
})

Expand Down
39 changes: 35 additions & 4 deletions test/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,40 @@ describe("templates", function(){
})
})

describe(".hbs", function(){
it("should render handlebars file", function(done){
poly.render("content.hbs", function(error, body){
should.exist(body)
body.should.include("<h1>Hello! This is Handlebars!</h1>")
done()
})
})

it("should render partials", function(done){
poly.render("hbs/partials.hbs", function(error, body){
should.not.exist(error)
should.exist(body)
// from main file
body.should.include("<h1>Hello Handlebars</h1>")
// from markdown partial
body.should.include("<h1>hello markdown</h1>")
done()
})
})

it("should pass data into partials", function(done){
poly.render("hbs/partials-with-data.hbs", function(error, body){
should.not.exist(error)
should.exist(body)
// from main file
body.should.include("<h1>Hello Handlebars</h1>")
// from jade partial
body.should.include("<h3>Brock Whitten</h3>")
done()
})
})
})

describe(".md", function(){
it("should render markdown file", function(done){
poly.render("stuff.md", function(error, body){
Expand Down Expand Up @@ -114,10 +148,7 @@ describe("templates", function(){
poly.render("extend.jade", function(error, body){
should.not.exist(error)
should.exist(body)
body.should.include("<h1>Sintaxi</h1>")
body.should.include("<h2>Hello World</h2>")
body.should.include("<h3>Brock Whitten</h3>")
body.should.include("<h4>Vancouver</h4>")
body.should.include("<h1>hello markdown</h1>")
done()
})
})
Expand Down