diff --git a/.travis.yml b/.travis.yml index 6e5919de3..7ab627a6f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ language: node_js node_js: - "0.10" + - "0.12" diff --git a/lib/helpers/raw.js b/lib/helpers/raw.js index 5a0bd006b..b04454be6 100644 --- a/lib/helpers/raw.js +++ b/lib/helpers/raw.js @@ -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"] } diff --git a/lib/javascript/index.js b/lib/javascript/index.js index d5ec6b6bf..bf5be4e9f 100644 --- a/lib/javascript/index.js +++ b/lib/javascript/index.js @@ -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. diff --git a/lib/stylesheet/index.js b/lib/stylesheet/index.js index 2944eec31..2fc7bf75f 100644 --- a/lib/stylesheet/index.js +++ b/lib/stylesheet/index.js @@ -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. diff --git a/lib/template/index.js b/lib/template/index.js index 94e1f178d..1011f3531 100644 --- a/lib/template/index.js +++ b/lib/template/index.js @@ -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') /** diff --git a/lib/template/processors/hbs.js b/lib/template/processors/hbs.js new file mode 100644 index 000000000..7e4f35060 --- /dev/null +++ b/lib/template/processors/hbs.js @@ -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" }'}} + * + * @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) + } + } + +} diff --git a/lib/template/processors/jade.js b/lib/template/processors/jade.js index 2b230c9f7..93c91fd21 100644 --- a/lib/template/processors/jade.js +++ b/lib/template/processors/jade.js @@ -1,4 +1,4 @@ -var jade = require('jade') +var jade = require('harp-jade') var TerraformError = require("../../error").TerraformError module.exports = function(fileContents, options){ diff --git a/package.json b/package.json index d74702f8f..0c5ca9778 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/fixtures/globals/_data.json b/test/fixtures/globals/_data.json index 07a394bbc..b9e1b14a0 100644 --- a/test/fixtures/globals/_data.json +++ b/test/fixtures/globals/_data.json @@ -1,5 +1,8 @@ { "about":{ "title": "About Page" + }, + "blog": { + "title": "Blog Page" } -} \ No newline at end of file +} diff --git a/test/fixtures/globals/blog.hbs b/test/fixtures/globals/blog.hbs new file mode 100644 index 000000000..b6515528b --- /dev/null +++ b/test/fixtures/globals/blog.hbs @@ -0,0 +1 @@ +

{{ title }}

diff --git a/test/fixtures/globals/contact.hbs b/test/fixtures/globals/contact.hbs new file mode 100644 index 000000000..225a173e2 --- /dev/null +++ b/test/fixtures/globals/contact.hbs @@ -0,0 +1,7 @@ + + + + {{ title }} + +

{{ name }}

+ diff --git a/test/fixtures/templates/content.hbs b/test/fixtures/templates/content.hbs new file mode 100644 index 000000000..1a614b8d5 --- /dev/null +++ b/test/fixtures/templates/content.hbs @@ -0,0 +1 @@ +

Hello! This is {{!-- should be invisible --}}Handlebars!

diff --git a/test/fixtures/templates/hbs/partials-with-data.hbs b/test/fixtures/templates/hbs/partials-with-data.hbs new file mode 100644 index 000000000..ed243f646 --- /dev/null +++ b/test/fixtures/templates/hbs/partials-with-data.hbs @@ -0,0 +1,2 @@ +

Hello Handlebars

+{{partial '../profile.jade' '{ "title": "Brock Whitten" }' }} diff --git a/test/fixtures/templates/hbs/partials.hbs b/test/fixtures/templates/hbs/partials.hbs new file mode 100644 index 000000000..ef4040556 --- /dev/null +++ b/test/fixtures/templates/hbs/partials.hbs @@ -0,0 +1,2 @@ +

Hello Handlebars

+{{partial '../stuff.md' }} diff --git a/test/fixtures/templates/index.jade b/test/fixtures/templates/index.jade index eee22fc56..19e13809e 100644 --- a/test/fixtures/templates/index.jade +++ b/test/fixtures/templates/index.jade @@ -3,7 +3,7 @@ h2 Hello World -!= partial("profile.jade") +!= partial("profile.jade", { title: "Brock Whitten" }) != partial("stuff.md") h4= place pre diff --git a/test/fixtures/templates/profile.jade b/test/fixtures/templates/profile.jade index 5d358cf2b..95b34cc6f 100644 --- a/test/fixtures/templates/profile.jade +++ b/test/fixtures/templates/profile.jade @@ -1 +1 @@ -h3 Brock Whitten \ No newline at end of file +h3= title diff --git a/test/globals.js b/test/globals.js index 716dc7445..52c6f950d 100644 --- a/test/globals.js +++ b/test/globals.js @@ -6,15 +6,21 @@ 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("Default Title") + }) + poly.render("contact.hbs", function(error, body){ + should.not.exist(error) + should.exist(body) + body.should.include("

Annie Person

") done() }) + }) it("should be able to override globals in the template vars", function(done){ @@ -22,10 +28,15 @@ describe("data", function(){ should.not.exist(error) should.exist(body) body.should.include("About Page") + }) + poly.render("blog.hbs", function(error, body){ + should.not.exist(error) + should.exist(body) + body.should.include("

Blog Page

") done() }) }) }) -}) \ No newline at end of file +}) diff --git a/test/helpers.js b/test/helpers.js index f7dbf3075..da2603190 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -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() }) @@ -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() }) diff --git a/test/templates.js b/test/templates.js index 9bb436a1b..0d2ab0032 100644 --- a/test/templates.js +++ b/test/templates.js @@ -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("

Hello! This is Handlebars!

") + 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("

Hello Handlebars

") + // from markdown partial + body.should.include("

hello markdown

") + 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("

Hello Handlebars

") + // from jade partial + body.should.include("

Brock Whitten

") + done() + }) + }) + }) + describe(".md", function(){ it("should render markdown file", function(done){ poly.render("stuff.md", function(error, body){ @@ -114,10 +148,7 @@ describe("templates", function(){ poly.render("extend.jade", function(error, body){ should.not.exist(error) should.exist(body) - body.should.include("

Sintaxi

") - body.should.include("

Hello World

") - body.should.include("

Brock Whitten

") - body.should.include("

Vancouver

") + body.should.include("

hello markdown

") done() }) })