最好的策略使用与Backbone.js的HAML模板 [英] Best strategy to use HAML template with Backbone.js

查看:121
本文介绍了最好的策略使用与Backbone.js的HAML模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

林进入Backbone.js的构造的JavaScript code为我的项目,我爱HAML对后端(导轨)的模板,所以我还想用它为骨干视图模板。我知道有几个HAML端口以Javascript中,像
https://github.com/creationix/haml-js 和骨干支持JST和轻松的胡子。

Im getting into Backbone.js to structure the javascript code for my project and I love HAML for templating on the backend(rails), so Id like to use it for Backbone Views templating. I know there is several HAML ports to Javascript, like https://github.com/creationix/haml-js and backbone supports JST and mustache with ease.

最新最好的方式来使用HAML模板代替。

Whats the best way to use haml templating instead.

是否有任何缺点在客户端上使用HAML?性能方面,额外的脚本加载时间(照顾由资产打包工具,如jammit)

Are there any downsides to using HAML on the client side? Performance, extra script load time(taken care by asset packaging tools like jammit)

推荐答案

我知道你已经提到它,但我会建议使用HAML-JS与Jammit。只要有haml.js在你的JavaScript和你assets.yml添加 template_function:Haml的以及包括在一个包您的模板文件。例如。

I know you already mentioned it but I would suggest using haml-js with Jammit. Simply include haml.js in your javascripts and in your assets.yml add template_function: Haml as well as including your template files in to a package. e.g.

  javascript_templates:
    - app/views/**/*.jst.haml

然后在你的意见,你可以包含这个包( = include_javascripts:javascript_templates )和Jammit将在任何.jst.haml文件打包到窗口.JST ['文件/路径'] 。 (如果您查看网页的源文件,你应该看到℃的JavaScript文件;脚本的src =/资产/ javascript_templates.jst类型=文/ JavaScript的>< / SCRIPT>

Then in your views you can include this package (= include_javascripts :javascript_templates) and Jammit will package any .jst.haml files in to window.JST['file/path']. (If you view page source you should see a javascript file like <script src="/assets/javascript_templates.jst" type="text/javascript"></script>)

要使用这些模板只需调用这些JSTs Jammit创造之一。即。

To use these templates simply call one of those JSTs Jammit created. i.e.

$('div').html(JST['file/path']({ foo: 'Hello', bar: 'World' }));

和Jammit将使用Haml的-JS模板函数功能,呈现模板。

And Jammit will use the Haml-js template function function to render the template.

请注意:一定要指向Jammit的GitHub库在你的Gemfile获得支持必要的换行符的最新版本引入haml-JS工作

Note: Be sure to point to the github repo of Jammit in your Gemfile to get the latest version that supports newline characters necessary for haml-js to work.

这篇关于最好的策略使用与Backbone.js的HAML模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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