我在一个快速应用程序中使用dustjs作为模板引擎,并且想知道是否有人在Express中的服务器端模板中成功使用了contextDump帮助器?我跟着整合的例子来整合灰尘和快速,它运作良好。帮助器在那里,因为我能够使用eq帮助器进行简单的测试并且它可以工作。但是当试图抛弃上下文时,我没有在任何地方看到它。这是一个示例模板:
{>layout/}
{<content}
<ul>
{#users}
<li>{username} - <a href="/users/{id}/tasks/create">Create New Task</a>
<ul>
{#user.tasks}
<li>{title} - <a href="/users/{user.id}/tasks/{task.id}/destroy">Delete Task</a> |
<a href="/users/{user.id}/tasks/{task.id}/update">Update Task</a></li>
{/user.tasks}
</ul>
</li>
{/users}
</ul>
{/content}
{@contextDump to="console"/}
这是我的app.js:
var express = require('express');
var app = express();
var http = require('http');
var path = require('path');
var db = require ('./models');
var dust = require('dustjs-linkedin');
var cons = require('consolidate');
// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('models', db);
//configure dust
app.set('view engine', 'dust');
app.set('template_engine', 'dust');
app.engine('dust', cons.dust);
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(express.cookieParser('your secret here'));
app.use(express.session());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
//require routes
require('./routes')(app);
require('./routes/user')(app);
require('./routes/task')(app);
db
.sequelize
.sync({ force: true })
.complete(function (err) {
if (err) {
throw err;
} else {
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
}
});
这里是package.json:
{
"name": "application-name",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app.js"
},
"dependencies": {
"express": "3.4.6",
"sequelize": "~2.0.0-beta.5",
"mysql": "~2.0.0-rc2",
"lodash": "~2.4.1",
"async": "~0.2.9",
"dustjs-linkedin": "~2.2.2",
"dustjs-helpers": "~1.1.1",
"consolidate": "~0.10.0"
}
}
谢谢!