0
我使用[email protected] + [email protected] + [email protected]。當我呈現一個頁面時,輸出結果與預期不符。這裏的玉:Node.js:Consolidate.js + Jade無法正確呈現Jade
index.jade
extends ../../layouts/default
block headIncludes
link(href='/_widgets/search/index.css',rel='stylesheet')
block footerIncludes
script(type='text/javascript',src='/_widgets/search/index.js')
script(src='/views/site/home/js/index.js')
block content
header(class='jumbotron masthead')
div.inner
h1 Pricing Page
//Search
div.row-fluid
div(class='span12 centeredText',id='searchWidget')
div.row-fluid
div.span12
div.row-fluid
div.span12
div.row-fluid
div.span12
這裏的輸出:
<extends>../../layouts/default</extends><block>headIncludes</block> link(href='/_widgets/search/index.css',rel='stylesheet') <block>footerIncludes</block> script(type='text/javascript',src='/_widgets/search/index.js') script(src='/views/site/home/js/index.js') <block>content</block> header(class='jumbotron masthead') div.inner h1 Pricing Page //Search div.row-fluid div(class='span12 centeredText',id='searchWidget') div.row-fluid div.span12 div.row-fluid div.span12 div.row-fluid div.span12
正如你所看到的,而不是評價擴展爲玉總是有,現在創建
<extends>../../layouts/default</extends>
相同的塊。
<block>headIncludes</block>
下面是我如何設置應用起來:
app.js
....
var app = express()
require('./settings').boot(app, config, passport)
settings.js
var express = require('express')
, RedisStore = require('connect-redis')(express)
, url = require("url")
, cons = require('consolidate')
exports.boot = function(app, config, passport){
bootApplication(app, config, passport)
}
// App settings and middleware
function bootApplication(app, config, passport) {
app.set('showStackError', true)
app.use(express.static(__dirname + '/public'))
app.use(express.logger(':method :url :status'))
// set views path, template engine and default layout
app.configure(function() {
app.engine('jade', require('jade').renderFile)
app.set('views', __dirname + '/app/views')
app.set('view engine', 'jade')
app.set('view options', { layout: false })
// cookieParser should be above session
app.use(express.cookieParser())
// bodyParser should be above methodOverride
app.use(express.bodyParser())
app.use(express.methodOverride())
var redisURL = process.env.REDISTOGO_URL || config.redis
console.log(redisURL)
var redisUrl = url.parse(redisURL),
redisAuth = redisUrl.auth.split(':');
app.set('redisHost', redisUrl.hostname);
app.set('redisPort', redisUrl.port);
app.set('redisDb', redisAuth[0]);
app.set('redisPass', redisAuth[1]);
app.use(express.session({
secret: '......',
cookie: { maxAge: new Date(Date.now() + 360000)}, //1 Hour
store: new RedisStore({
host: app.set('redisHost'),
port: app.set('redisPort'),
db: app.set('redisDb'),
pass: app.set('redisPass')
})
}))
app.use(passport.initialize())
app.use(passport.session())
app.use(express.favicon())
require('./config/customMiddleware').boot(app)
// routes should be at the last
app.use(app.router)
// assume "not found" in the error msgs
// is a 404. this is somewhat silly, but
// valid, you can do whatever you like, set
// properties, use instanceof etc.
app.use(function(err, req, res, next){
// treat as 404
if (~err.message.indexOf('not found')) return next()
// log it
console.error(err.stack)
// error page
res.status(500).render('500')
})
// assume 404 since no middleware responded
app.use(function(req, res, next){
res.status(404).render('404', { url: req.originalUrl })
})
})
app.set('showStackError', false)
}
這似乎很奇怪的我,因爲翡翠看起來編譯一點點,只是不像預期的那樣。有任何想法嗎?
謝謝,我已經更新了Jade和Express,它現在按預期工作。再次感謝Jonathan的幫助。 – Bob