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

Pug 2.0 Upgrade #133

Closed
wants to merge 10 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

### Supported Pre-Processors

**HTML** – EJS, Jade, Markdown
**HTML** – EJS, Pug (was Jade), Markdown
**CSS** – LESS, Stylus, Sass (SCSS)
**JavaScript** – CoffeeScript

Expand Down Expand Up @@ -43,7 +43,7 @@ var planet = terraform.root("path/to/public/dir", { "title": "Bitchin" })
Step 3) render a file

```javascript
planet.render('index.jade', { "title": "Override the global title" }, function(error, body){
planet.render('index.pug', { "title": "Override the global title" }, function(error, body){
console.log(body)
})
```
Expand Down
58 changes: 29 additions & 29 deletions 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": ["pug", "ejs", "md"],
"css" : ["styl", "less", "scss", "sass"],
"js" : ["coffee"]
}
Expand All @@ -24,28 +24,28 @@ var processors = exports.processors = {
*
* returns a priority list of files to look for on a given request.
*
* `css` and `html` are special extensions that will add `less` and `jade`
* `css` and `html` are special extensions that will add `less` and `pug`
* to the priority list (respectively).
*
* e.g
*
* buildPriorityList("foobar")
* => ["foobar", "foobar.html", "foobar.jade", "foobar.html.jade"]
* => ["foobar", "foobar.html", "foobar.pug", "foobar.html.pug"]
*
* buildPriorityList("foobar.css")
* => ["foobar.css", "foobar.less", "foobar.css.less"]
*
* buildPriorityList("foobar.html")
* => ["foobar.html", "foobar.jade", "foobar.html.jade"]
* => ["foobar.html", "foobar.pug", "foobar.html.pug"]
*
* buildPriorityList("foobar.jade")
* => ["foobar.jade"]
* buildPriorityList("foobar.pug")
* => ["foobar.pug"]
*
* buildPriorityList("foobar.html.jade.html")
* => ["foobar.html.jade.html", "foobar.html.jade.jade", "foobar.html.jade.html.jade"]
* buildPriorityList("foobar.html.pug.html")
* => ["foobar.html.pug.html", "foobar.html.pug.pug", "foobar.html.pug.html.pug"]
*
* buildPriorityList("hello/foobar")
* => ["hello/foobar", "hello/foobar.html", "hello/foobar.jade", "hello/foobar.html.jade"]
* => ["hello/foobar", "hello/foobar.html", "hello/foobar.pug", "hello/foobar.html.pug"]
*
*/

Expand All @@ -62,13 +62,13 @@ var buildPriorityList = exports.buildPriorityList = function(filePath){

if(processor){

// foo.html => foo.jade
// foo.html => foo.pug
processor.forEach(function(p){
var regexp = new RegExp(ext + '$')
list.push(filePath.replace(regexp, p))
})

// foo.html => foo.html.jade
// foo.html => foo.html.pug
processor.forEach(function(p){
list.push(filePath + '.' + p)
})
Expand All @@ -78,7 +78,7 @@ var buildPriorityList = exports.buildPriorityList = function(filePath){
if(processors['html'].indexOf(ext) !== -1){
list.push(filePath)
}else{
// foo.xml => foo.xml.jade
// foo.xml => foo.xml.pug
processors['html'].forEach(function(p){
list.push(filePath + '.' + p)
})
Expand All @@ -97,8 +97,8 @@ var buildPriorityList = exports.buildPriorityList = function(filePath){
*
* Takes a directory and an array of files. Returns the first file in the list that exists.
*
* findFirstFile("/path/to/public", ["foo.html", "foo.jade", "foo.html.jade"])
* => "foo.jade"
* findFirstFile("/path/to/public", ["foo.html", "foo.pug", "foo.html.pug"])
* => "foo.pug"
*
* returns null if no file is found.
*
Expand Down Expand Up @@ -137,7 +137,7 @@ var layoutPriorityList = buildPriorityList("_layout.html")
* Walks up the tree to find the nearest _layout file. Returns relative path to root
*
* findNearestLayout("/path/to/public", "/path/to/public/nested/dir")
* => "_layout.jade"
* => "_layout.pug"
*
* returns null if no layout is found.
*
Expand Down Expand Up @@ -170,7 +170,7 @@ var findDefaultLayout = exports.findDefaultLayout = function(rootPath, filePath)
if (arr.length > 2 && arr[1] == "json"){
return null
} else {
return findNearestLayout(rootPath, path.dirname(filePath))
return findNearestLayout(rootPath, path.dirname(filePath))
}
}

Expand Down Expand Up @@ -283,7 +283,7 @@ var dataTree = exports.dataTree = function (filename) {
*
* returns current object based on the path of source file
*
* getCurrent("foo/bar/baz.jade")
* getCurrent("foo/bar/baz.pug")
* => { path: ["foo", "bar", "baz"], source: "baz" }
*
* getCurrent("index.html")
Expand Down Expand Up @@ -312,7 +312,7 @@ exports.getCurrent = function(sourcePath){
*
* Returns processor based on file path.
*
* sourceType("foobar.jade") => "jade"
* sourceType("foobar.pug") => "pug"
* sourceType("foobar.less") => "less"
* sourceType("foobar") => null
*
Expand Down Expand Up @@ -369,8 +369,8 @@ var walkData = exports.walkData = function(tail, obj){
* (and faster performance)
*
* eg.
* foo.jade => foo.html
* foo.html.jade => foo.html
* foo.pug => foo.html
* foo.html.pug => foo.html
*/

var outputPath = exports.outputPath = function(source, allowAlternateExtensions){
Expand All @@ -379,9 +379,9 @@ 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
processors[targetExtension].forEach(function(sourceExtension){ // .pug, .ejs, .md
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
// Search for a alternate extension before the known source extension e.g. foobar.bar.pug
var alternateFileExtension = new RegExp("^.*\\.(\\w{3,4})\\." + sourceExtension + "$")
var match = alternateFileExtension.exec(source)
if (match) {
Expand All @@ -392,8 +392,8 @@ var outputPath = exports.outputPath = function(source, allowAlternateExtensions)
// Let's try to match known sourceExtensions. Optionally, capture the targetExtension BEFORE.
var regexp = new RegExp('(\\.' + targetExtension + ')?\\.' + sourceExtension + '$')
// If found, will replace the whole extension with target extension, e.g.:
// .html.jade -> .html (matches)
// .jade -> .html (matches)
// .html.pug -> .html (matches)
// .pug -> .html (matches)
// .html -> .html (doesn't matches - doesn't matter)
// .foo -> .foo (doesn't matches - doesn't matter)
source = source.replace(regexp, "." + targetExtension)
Expand All @@ -412,8 +412,8 @@ var outputPath = exports.outputPath = function(source, allowAlternateExtensions)
* Returns output type source file.
*
* eg.
* foo.jade => html
* foo.html.jade => html
* foo.pug => html
* foo.html.pug => html
*/

var outputType = exports.outputType = function(source){
Expand Down Expand Up @@ -460,15 +460,15 @@ exports.shouldIgnore = function(filePath){
* returns true if file is a template file
*
* eg.
* isTemplate('foo.jade') => true
* isTemplate('foo.pug') => true
* isTemplate('foo.md') => true
* isTemplate('foo.html') => false
* isTemplate('foo/bar.jade') => true
* isTemplate('foo/bar.pug') => true
* isTemplate('foo/bar.md') => true
* isTemplate('foo/bar.html') => false
* isTemplate('foo.less') => false
* isTemplate('foo.css') => false
* isTemplate('foo.bar.baz.jade') => true
* isTemplate('foo.bar.baz.pug') => true
*/

exports.isTemplate = function(filePath){
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('harp-minify')
var minify = require('harp-minify')

/**
* Build Processor list for javascripts.
Expand Down
6 changes: 3 additions & 3 deletions lib/template/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var minify = require('harp-minify')
* same as doing...
*
* var processors = {
* "jade" : require("./processors/jade"),
* "pug" : require("./processors/pug"),
* "md" : require("./processors/md")
* }
*
Expand Down Expand Up @@ -42,7 +42,7 @@ var scope = module.exports = function(projectPath, parentLocals){
*
* This is the function for rendering a template. It is has access
* to the partials of its parent template but accepts locals that
* will override that the variables that it inherents from its parent.
* will override the variables that it inherents from its parent.
* If given a local of `layout` it will use it.
*
*/
Expand Down Expand Up @@ -91,7 +91,7 @@ var scope = module.exports = function(projectPath, parentLocals){


/**
* Add the locals the are added to the `_data.json` file.
* Add the locals that are added to the `_data.json` file.
* We ignore the `layout` value here because the layout
* property should not be inherited when just being called
* as a partial.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
var jade = require('jade')
var pug = require('pug')
var TerraformError = require("../../error").TerraformError

module.exports = function(fileContents, options){

return {
compile: function(){
return jade.compile(fileContents, options)
return pug.compile(fileContents, options)
},

parseError: function(error){

var arr = error.message.split("\n")
var path_arr = arr[0].split(":")
var line = error.line ||
(path_arr.length == 2 && path_arr[path_arr.length -1]) ||
(path_arr.length > 2 && path_arr[path_arr.length -2]) ||
-1

error.lineno = parseInt(error.lineno || path_arr[path_arr.length -1] || -1)
error.lineno = parseInt(line)
error.message = arr[arr.length - 1]
error.name = error.name
error.source = "Jade"
error.source = "Pug"
error.dest = "HTML"
error.filename = error.path || options.filename
error.stack = fileContents.toString()
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@
"coffee-script": "1.10.0",
"ejs": "2.3.4",
"harp-minify": "0.4.0",
"jade": "1.11.0",
"less": "2.5.3",
"lodash": "3.10.1",
"lru-cache": "4.0.0",
"marked": "0.3.5",
"node-sass": "3.7.0",
"postcss": "5.0.14",
"pug": "^2.0.0-beta6",
"stylus": "0.54.5",
"through": "2.3.8"
},
Expand Down
2 changes: 1 addition & 1 deletion test/contents.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe("contents", function(){
it("should return public object", function(done){
var root = __dirname + "/fixtures/data/valid"
var poly = polymer.root(root)
poly.render("pub.json.jade", { "layout": false }, function(err, result){
poly.render("pub.json.pug", { "layout": false }, function(err, result){
var pub = JSON.parse(result)
should.exist(pub["_contents"])
done()
Expand Down
12 changes: 6 additions & 6 deletions test/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe("data", function(){
var poly = polymer.root(root)

it("should be available in the layouts", function(done){
poly.render("index.jade", function(error, body){
poly.render("index.pug", function(error, body){
should.not.exist(error)
should.exist(body)
body.should.include("<h1>My Articles</h1>")
Expand All @@ -18,7 +18,7 @@ describe("data", function(){
})

it("should be available in the template", function(done){
poly.render("articles/hello-jupiter.jade", function(error, body){
poly.render("articles/hello-jupiter.pug", function(error, body){
should.not.exist(error)
should.exist(body)
body.should.include("<h3>I was born on Jupiter</h3>")
Expand All @@ -28,7 +28,7 @@ describe("data", function(){
})

it("should handle escaped html", function(done){
poly.render("articles/hello-pluto.jade", function(error, body){
poly.render("articles/hello-pluto.pug", function(error, body){
should.not.exist(error)
should.exist(body)
body.should.include("<h1><a href=\"http://harpjs.com\">Harp</a></h1>")
Expand All @@ -38,7 +38,7 @@ describe("data", function(){


it("should be available to override data when calling partial", function(done){
poly.render("index.jade", function(error, body){
poly.render("index.pug", function(error, body){
should.not.exist(error)
should.exist(body)
body.should.include("<h3>I was born on Jupiter</h3>")
Expand Down Expand Up @@ -88,7 +88,7 @@ describe("data", function(){
it("should return public object", function(done){
var root = __dirname + "/fixtures/data/valid"
var poly = polymer.root(root)
poly.render("pub.json.jade", function(err, result){
poly.render("pub.json.pug", function(err, result){
var pub = JSON.parse(result)
should.not.exist(pub[".foo"])
done()
Expand All @@ -100,7 +100,7 @@ describe("data", function(){
it("should return public object", function(done){
var root = __dirname + "/fixtures/data/dynamic"
var poly = polymer.root(root)
poly.render("pub.json.jade", { "layout": false }, function(err, result){
poly.render("pub.json.pug", { "layout": false }, function(err, result){
var pub = JSON.parse(result)
should.exist(pub["articles"]["_data"]["hello-world"])
should.not.exist(pub[".foo"])
Expand Down
Loading