【发布时间】:2015-02-17 17:20:25
【问题描述】:
我想使用 gulp 将文件中的数据(最终我将动态生成数据,或按照these instructions 使用数据文件)渲染到玉中。这就是我所拥有的,但我知道我犯了一个愚蠢的错误(我还不是玉专家),因为我在编译的 html 中遇到运行时错误或undefined。欢迎指教
config.js
module.exports = {
rotm: [
{title: "title 1", comment: "comment 1"},
{title: "title 2", comment: "comment 1"},
{title: "title 3", comment: "comment 1"},
{title: "title 4", comment: "comment 1"}
]
};
gulp.coffee
config = require "./config.js"
gulp.task 'jade', ->
gulp.src paths.jade
.pipe run.changed "./", extension : ".jade"
.pipe run.plumber()
.pipe run.jade pretty : true, data : config
.pipe run.rename extname : ".hbs"
.pipe gulp.dest ""
.pipe reload stream : true, once : true
home.jade
each r in rotm
h1 {{r.title}}
p.comment {r.comment}
结果
<h1>{r.title}</h1>
<p class="comment">{r.comment}</p>
<h1>{r.title}</h1>
<p class="comment">{r.comment}</p>
<h1>{r.title}</h1>
<p class="comment">{r.comment}</p>
<h1>{r.title}</h1>
【问题讨论】:
-
data : config.rotm->data : config? -
这是正确的吗?我从来没有像你尝试过的那样使用
gulp-jade,但是repository 上的指南说你应该使用gulp-data。或者@Heikki 也有意义,因为您在home.jade中迭代rotm,但数据只是存储在rotm中的数组,而不是rotm本身。 -
@Heikki:更新了您输入的问题,这给了我一些输出 - 显示。