Skip to content
Open
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
8 changes: 8 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var terraform = require('terraform')
var async = require('async')
var connect = require('connect')
var mime = require('mime')
var http = require('http')
var helpers = require('./helpers')
var middleware = require('./middleware')
var pkg = require('../package.json')
Expand Down Expand Up @@ -191,13 +192,20 @@ exports.compile = function(projectPath, outputPath, callback){
*/

var compileFile = function(file, done){
var codes = http.STATUS_CODES
var match
process.nextTick(function () {
terra.render(file, function(error, body){
if(error){
done(error)
}else{
if(body){
var dest = path.resolve(outputPath, terraform.helpers.outputPath(file))
if(match = (/^.*\/(.*?)\.html$/).exec(dest)) {
if(match[1] !== "index" && !codes.hasOwnProperty(match[1])) {
dest = dest.replace(/\.html$/, "/index.html")
}
}
fs.mkdirp(path.dirname(dest), function(err){
fs.writeFile(dest, body, done)
})
Expand Down
2 changes: 2 additions & 0 deletions test/apps/compile/basic/public/777.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
h1 777
p A numerically named page, but not an error
20 changes: 20 additions & 0 deletions test/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,26 @@ describe("compile", function(){
})
})

it("compile should create directory indexes and ignore existing indexes", function(done){
var rsp = fs.existsSync(path.join(outputPath, "/index.html"))
rsp.should.be.true

var rsp = fs.existsSync(path.join(outputPath, "/about/index.html"))
rsp.should.be.true

done()
})

it("compile should ignore files named after http statuses when creating directory indexes", function(done){
var rsp = fs.existsSync(path.join(outputPath, "/404.html"))
rsp.should.be.true

var rsp = fs.existsSync(path.join(outputPath, "/777/index.html"))
rsp.should.be.true

done()
})

it("compile should not include folders named with underscores", function(done) {
var cssOutputPath = path.join(outputPath, "/css")

Expand Down