Meteor 中的玉石模板 [英] Jade templating in Meteor

查看:22
本文介绍了Meteor 中的玉石模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Meteor 常见问题解答中 http://meteor.com/faq/how-do-i-package-a-new-templating-system 有一些关于添加一个不同的(不同于默认的 Handlebars)模板系统的信息.Jade 是文档中其他地方明确指出的唯一其他示例.

In the Meteor FAQs http://meteor.com/faq/how-do-i-package-a-new-templating-system there is some information about adding a different (than the default Handlebars) templating system. Jade is the only other example explicitly called out elsewhere in the docs.

那么有人已经在研究 Jade 了吗?如果没有,我可以开始吗?还是现在还为时过早?例如:

So is somebody already working on Jade? If not, is it feasible for me to start? Or is it still too early? e.g. :

包 API 正在迅速变化并且没有记录,因此您不能制作您自己的包裹.即将推出.

The package API is rapidly changing and isn't documented, so you can't make your own packages just yet. Coming soon.

在我目前的 Ember.js 项目中,我一直在努力喜欢 Handlebars,但对我来说,没有什么比 Jade 更优雅了.

I've been trying to love Handlebars in my current Ember.js project, but for me nothing is as elegant as Jade.

推荐答案

我们希望看到 Jade 集成.使用 packages/handlebars 作为模板.

We would love to see Jade integration. Use packages/handlebars as a template.

基本策略是将模板引擎的输出连接到 Meteor.ui.render 中,这就是我们实现实时页面更新的方式.只要您的模板返回 HTML,就会起作用.每当 Jade 模板引用 Meteor.Collection 文档或 Session 变量时,Meteor 都会注册该依赖项,以便知道在数据更改时重新渲染模板.

The basic strategy is to wire the output of the template engine into Meteor.ui.render which is how we implement live page updates. As long as your template returns HTML, that'll work. Any time a Jade template references a Meteor.Collection document or Session variable, Meteor will register that dependency so that knows to rerender the template when the data changes.

不过,更好的是还使用 Meteor.ui.chunkMeteor.ui.listChunk.这些将限制 Meteor 在发生变化时必须重新计算的数量.例如,如果您在 Handlebars-speak 中使用 {{#each}} 呈现文档列表,则当新文档进入结果集时,没有理由重新计算整个模板.我们只为新文档渲染一个 HTML 块,并将其插入到 DOM 中.这就是 listChunk 的作用.

Even better, though, is to also use Meteor.ui.chunk and Meteor.ui.listChunk. These will limit the amount of recalculation Meteor has to do when there's a change. For example, if you are rendering a list of documents using {{#each}} in Handlebars-speak, there's no reason to recalculate the whole template when a new document enters the result set. We just render one HTML chunk for the new document, and insert that right into the DOM. That's listChunk in action.

所以你可能会发现在 Jade 中检测只是 if/unlessfor/each你还有很长的路要走.

So you'll likely find that instrumenting just if/unless and for/each in Jade gets you a long way there.

请注意,包开发不像系统的其他部分那样有文档记录.因此,请随时提出更具体的问题.

Just be aware, package development is not as documented as the other parts of the system. So don't hesitate to ask more specific questions as you go.

这篇关于Meteor 中的玉石模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆