0

我正在使用 Express@3.0.0rc2 + jam@0.2.3 + consolidate@0.5.0。当我呈现页面时,输出与预期不符。这是玉:

索引.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               

如您所见,它不再像 Jade 一直那样评估 Extends,而是创建

<extends>../../layouts/default</extends>

块也一样。

<block>headIncludes</block>

这是我设置应用程序的方式:

应用程序.js

....
var app = express()
require('./settings').boot(app, config, passport)  

设置.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 看起来有点编译,只是不像预期的那样。有任何想法吗?

4

1 回答 1

0

您需要更新jade到较新的版本 - 至少要使用和0.16.0进行模板继承blockextends

当前版本是0.27.7.


您可能还想更新express,它不再是rcat 3.0.4

于 2012-12-16T04:11:32.883 回答