流星玉模板 [英] Jade templating in Meteor

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

问题描述

在流星常见问题解答"中 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项目中爱把手,但对我来说,没有什么比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必须执行的重新计算量.例如,如果要使用讲手把的{{#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.

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

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