diff --git a/lib/helpers/raw.js b/lib/helpers/raw.js index 6f1bf933f..2fe7ed331 100644 --- a/lib/helpers/raw.js +++ b/lib/helpers/raw.js @@ -13,8 +13,8 @@ var TerraformError = exports.TerraformError = require("../error").TerraformError */ var processors = exports.processors = { - "html": ["jade", "ejs", "md"], - "css" : ["styl", "less", "scss", "sass"], + "html": ["html", "jade", "ejs", "md"], + "css" : ["css", "scss", "sass", "less", "styl"], "js" : ["js", "coffee"] } diff --git a/lib/stylesheet/processors/css.js b/lib/stylesheet/processors/css.js new file mode 100644 index 000000000..4d23577bb --- /dev/null +++ b/lib/stylesheet/processors/css.js @@ -0,0 +1,3 @@ +exports.compile = function(filePath, dirs, fileContents, callback){ + callback(null, fileContents.toString()) +} diff --git a/lib/template/index.js b/lib/template/index.js index 1011f3531..d5bca99bf 100644 --- a/lib/template/index.js +++ b/lib/template/index.js @@ -146,14 +146,19 @@ var scope = module.exports = function(projectPath, parentLocals){ */ var tmpl = processors[ext](fileContents, { filename: filePath, basedir: projectPath }) - try{ - var render = tmpl.compile() - var output = render(locals) - }catch(e){ - throw e.source && e.dest - ? e - : tmpl.parseError(e) - } + try { + var render = tmpl.compile() + var output + if (ext !== 'html') { + output = render(locals) + } else { + output = minify.html(tmpl.compile()) + } + } catch(e) { + throw e.source && e.dest + ? e + : tmpl.parseError(e) + } /** diff --git a/lib/template/processors/html.js b/lib/template/processors/html.js new file mode 100644 index 000000000..b12a53412 --- /dev/null +++ b/lib/template/processors/html.js @@ -0,0 +1,26 @@ +var TerraformError = require("../../error").TerraformError + +module.exports = function(fileContents, options){ + + return { + compile: function(){ + return fileContents.toString() + }, + + 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 = "HTML" + error.dest = "HTML" + error.filename = error.path || options.filename + error.stack = fileContents.toString() + + return new TerraformError(error) + } + } + +} diff --git a/test/fixtures/stylesheets/css/main.css b/test/fixtures/stylesheets/css/main.css new file mode 100644 index 000000000..bf661d6af --- /dev/null +++ b/test/fixtures/stylesheets/css/main.css @@ -0,0 +1,4 @@ +body { + background: #ffc0cb; + font-feature-settings: "kern", "liga", "pnum", "onum"; +} diff --git a/test/fixtures/templates/html/index.html b/test/fixtures/templates/html/index.html new file mode 100644 index 000000000..35a9e7789 --- /dev/null +++ b/test/fixtures/templates/html/index.html @@ -0,0 +1,5 @@ + + + +
Vancouver, Canada
diff --git a/test/helpers.js b/test/helpers.js index abc17662b..096d2cca4 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.html, index.jade, index.ejs, index.md, index.html.html, index.html.jade, index.html.ejs, index.html.md".split(', ') list.should.eql(plist) done() }) @@ -18,8 +18,8 @@ describe("helpers", function(){ it('should build priority list for css file.', function(done){ var list = polymer.helpers.buildPriorityList('main.css') list.should.be.an.instanceOf(Array) - list.should.have.lengthOf(8) - list.should.eql("main.styl, main.less, main.scss, main.sass, main.css.styl, main.css.less, main.css.scss, main.css.sass".split(', ')) + list.should.have.lengthOf(10) + list.should.eql("main.css, main.scss, main.sass, main.less, main.styl, main.css.css, main.css.scss, main.css.sass, main.css.less, main.css.styl".split(', ')) done() }) @@ -36,27 +36,27 @@ 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.html, feed.xml.jade, feed.xml.ejs, feed.xml.md'. 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.eql('profile.json.html, profile.json.jade, profile.json.ejs, profile.json.md'. 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.html, appcache.jade, appcache.ejs, appcache.md'.split(', ')) done() }) diff --git a/test/stylesheets.js b/test/stylesheets.js index fb71e337d..f25642ddb 100644 --- a/test/stylesheets.js +++ b/test/stylesheets.js @@ -3,6 +3,52 @@ var polymer = require('../') describe("stylesheets", function(){ + describe(".css", function(){ + + var root = __dirname + '/fixtures/stylesheets/css' + var poly = polymer.root(root) + + it("should have basic css file", function(done){ + poly.render("main.css", function(error, body){ + should.not.exist(error) + body.should.include("background:#ffc0cb") + done() + }) + }) + it("should autoprefix css", function(done){ + poly.render("main.css", 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.css", function(error, body){ + should.not.exist(error) + body.should.not.include(";}") + done() + }) + }) + + // it("should render a source map", function(done){ + // poly.render("main.css", function(error, body, sourcemap){ + // should.not.exist(error) + // should.exist(sourcemap) + // sourcemap.toString().should.include('main.css') + // done() + // }) + // }) + it("should not include the source map in the css body", function(done){ + poly.render("main.css", function(error, body, sourcemap){ + should.not.exist(error) + body.should.not.include("/*#") + done() + }) + }) + + }) + describe(".less", function(){ var root = __dirname + '/fixtures/stylesheets/less' diff --git a/test/templates.js b/test/templates.js index d9ad2504c..b8b3beb69 100644 --- a/test/templates.js +++ b/test/templates.js @@ -6,6 +6,28 @@ describe("templates", function(){ var root = __dirname + "/fixtures/templates" var poly = polymer.root(root) + describe(".html", function(){ + it("should render html file", function(done){ + poly.render("html/index.html", function(error, body){ + should.not.exist(error) + should.exist(body) + body.should.include("