简体   繁体   English

Ruby和Javascript的模板引擎

[英]Template engine for Ruby and Javascript

We are building a web page with hashtag navigation. 我们正在构建带有标签导航的网页。 There is lots of data, which comes in as JSON and we use client-side templates (jQuery) to render it. 有很多数据以JSON形式出现,我们使用客户端模板(jQuery)进行呈现。 So what are the options for reusable templates on both client-side and server-side (Ruby on rails)? 那么在客户端和服务器端(Ruby on Rails)上可重用模板有哪些选择? Because we would like to have an option to fallback to a non-hashtag url and in this case server should render the data. 因为我们希望有一个回退到非标签网址的选项,在这种情况下,服务器应该呈现数据。

I've seen Mustache.js, but it has poor support for iterating (can't get index) or nested templates and haml-js is not an option because it uses custom tags for loops. 我见过Mustache.js,但是它对迭代(无法获取索引)或嵌套模板的支持不佳,并且haml-js并不是一个选择,因为它使用自定义标记进行循环。

There are also couple of workarounds with using javascript engine on server side, but I'm not sure this will be a good decision. 在服务器端使用javascript引擎也有几种解决方法,但是我不确定这是否是一个好的决定。

Any suggetions? 有什么建议吗? Thanks. 谢谢。

There are a few projects that claim to make this possible. 有一些项目声称可以做到这一点。 The latest one that I've heard of is Ice . 我听说过的最新的是 Its README mentions a few others that you might want to check out too. 它的自述文件还提到了其他一些您可能也想查看的内容。 I haven't personally tried any of these, so I can't give you a recommendation as to how well they work, but I'd love to hear about your experiences with them as I might be attempting this in the near future as well. 我还没有亲自尝试过这些方法,因此无法向您推荐它们的工作效果,但是我很想听听您的经验,因为我可能会在不久的将来尝试这样做。 。

After analyzing all the ones I could find, I concluded that this one is most attractive: 在分析了我能找到的所有内容之后,我得出结论,这是最有吸引力的:

https://github.com/cowboyd/handlebars.rb https://github.com/cowboyd/handlebars.rb

Because the lastest commit is 4 months ago, which is more recent than any other I could find, because it's using V8 and the real Handlebars.js source, and it has some good design considerations and a good ruby interface. 因为最近一次提交是在4个月前,所以比我能找到的任何提交都要晚,因为它使用的是V8和真实的Handlebars.js源代码,并且具有一些良好的设计注意事项和良好的ruby界面。

If I choose to go this route I will be using handlebars.rb 如果我选择走这条路线,我将使用handlebars.rb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM