tre*_*tor 5 templates node.js express dust.js
一个简单的问题:为什么 express.js 不能与dust.js 一起运行?
我知道它没有得到官方支持,但是dust.js 甚至在我的node.js 版本上也有问题。
由于 require.path 问题,节点甚至无法启动。
server:testapp treejanitor$ node --version
v0.6.12
Run Code Online (Sandbox Code Playgroud)
将应用程序引擎设置为灰尘时出现问题。(快递中的app.js)
var dust = require('dust');
...
app.set('view engine', 'dust');
Run Code Online (Sandbox Code Playgroud)
我在这里展示控制台是为了给你我简单的模块列表。
搜索相同问题的人也可能会剪切/粘贴错误。
server:hummr treejanitor$ npm list
application-name@0.0.1 /Users/treejanitor/git/testapp/testapp
??? consolidate@0.3.0 extraneous
??? dust@0.3.0
??? express@2.5.8
? ??? connect@1.8.7
? ? ??? formidable@1.0.9
? ??? mime@1.2.4
? ??? mkdirp@0.3.0
? ??? qs@0.4.2
??? jade@0.25.0
??? commander@0.5.2
??? mkdirp@0.3.0
server:testapp treejanitor$ supervisor app.js
DEBUG: Error: require.paths is removed. Use node_modules folders, or the NODE_PATH environment variable instead.
at Function.<anonymous> (module.js:378:11)
at Object.<anonymous> (/Users/treejanitor/git/testapp/testapp/node_modules/dust/lib/server.js:6:8)
Run Code Online (Sandbox Code Playgroud)
我尝试了以下尝试但没有成功:
Dust.js load template from filesystem in Node.js
注意:我尝试了 express (3.0) 的 alpha 版本,但没有帮助。
consolidate.js 和该示例中的所有模块也是如此。
我对 node+express+dust 感兴趣的一些原因:
LinkedIn 选择了dustjs
Twitter 的 Bootstrap 框架
我曾经讨论过Express@3.0
通过consolidate.js
模块在 Node.js 0.6.x 上设置 Dust.js。你可以在这里阅读
但是,您可能希望使用LinkedIn 的 Dust.js 分支,它支持 Node.js 0.6.x 开箱即用,并提供其他改进。
Consolidate.js
已经支持那个 fork,但你仍然需要Express@3.0
工作。
所以这就是窍门——我想我应该分享我的发现。
它需要找到这个金块 - 如果您有兴趣,请在页面中搜索dust-x。
http://nodejs.debuggable.com/2012-03-23.txt
要解决问题,请在您的 Express 应用程序中
cd node_modules
git clone git://github.com/laurie71/dust-x.git
git clone https://github.com/caolan/dustjs.git
Run Code Online (Sandbox Code Playgroud)
Dust.js 的分支解决了 Node.js 的 require.paths 问题
https://github.com/caolan/dustjs
灰尘的“包装器”使其可用作模板引擎
(您仍然需要将dust.js安装为模块)
https://github.com/laurie71/dust-x
示例用法
https://gist.github.com/2174537
最重要的一点:
var dustx = require('dust-x');
...
// Configuration
app.configure(function(){
app.set('views', __dirname + '/views');
app.register('.dust', dustx/*({})*/);
app.set('view engine', 'dust');
// app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express['static'](__dirname + '/public'));
});
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我认为我可以手动修复 server.js 中的dust.js 问题,但我想向真正分叉dust.js 并公开提供解决方案的人表示敬意。
PS:我对在 stackoverflow 上发帖还很陌生,所以如果我违反了一些礼仪,请告诉我。我在常见问题解答中看到鼓励回答自己的问题,所以我想尝试一下。
特别是,我知道我的格式可能很弱。在答案中,我实际上更喜欢显示完整的链接,而不是指南建议的 URL 嵌入,因为它揭示了包含站点的结构。当网站 URL 深入您的大脑时,您就有更多机会将该网站作为下一次访问的参考。而且 URL 也相当短。;^)非常感谢您的建议。
“控制台”的通常格式化方式是什么?作为代码?