Javascript 选择正确的 UI 模板工具——dust.js?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10194921/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Choosing the right UI templating tool - dust.js?
提问by Ed .
I work on a large Java based web application, it has been built up over the past 5 or so years - the UI needs an overhaul / to be largely re-written. We are investigating the available UI tools/libraries/frameworks to use and have come across dust.jsas an option for templating.
我在开发一个基于 Java 的大型 Web 应用程序,它是在过去 5 年左右构建的 - UI 需要大修/需要大量重写。我们正在调查可用的 UI 工具/库/框架来使用,并且遇到了作为模板选项的dust.js。
The questions:I'm interested in hearing what users of dust.jsthink of it:
- Has it been successful?
- Is it easy to use?
- Is it sufficiently documented?
- Is community support good? (only 6 questions on ST tagged 'dust.js'!)
- What are the pros and cons when compared to other templating tools such as Underscore's templating, Google Closure Templates, Handlebarsand Mustache.
- Are there any problems using it with an MV* structure framework, e.g Backbone.js(online book)?
- 成功了吗?
- 这个容易用吗?
- 文件是否充分?
- 社区支持好不好?(ST上只有 6 个问题标记为“dust.js”!)
- 相对于其他模板等工具在哪些利弊下划线的模板,谷歌Closure模板,把手和小胡子。
- 将它与 MV* 结构框架一起使用是否有任何问题,例如Backbone.js(在线书籍)?
Some background:
一些背景:
Why are we interested in dust.js:The following LinkedInblog posts first drew our attention to it:
- Leaving JSPs in the dust: moving LinkedIn to dust.js client-side templates
The client-side templating throwdown: mustache, handlebars, dust.js, and more
The second of the two posts very nicely answers question 5, but asides from LinkedIn, very few results from Google detail the templating system or imply that it is a popular choice. In addition, the post mentions that they have extended the functionality and hope to one day contribute to the original project. I'm concerned that until they do that, we may also need to extend functionality.
Having said this, LinkedIn's original requirements for a templating system are very close to ours (see below) and they have clearly done some very thorough investigations before choosing.
Our requirements:
- DRY: We ideally want to use the templating system on the server (Java based) and client-side, or just client-side if we opt for LinkedIn's complete approach;
Instead of using a JSP, GSP, or ERB to assemble a page server side and send back HTML, we have the server send back just the dynamic data as JSON and have the page assembled in the browser using a static client-side template served from a CDN"
- Fully internationalised
- Good community support
- Sufficiency easy to use / pick up
- Works happily with jQueryand Backbone.js
- Well documented
- DRY: We ideally want to use the templating system on the server (Java based) and client-side, or just client-side if we opt for LinkedIn's complete approach;
为什么我们对dust.js 感兴趣:以下LinkedIn博客文章首先引起了我们的注意:
- 将 JSP 抛之脑后:将 LinkedIn 迁移到dust.js 客户端模板
客户端模板问题:mustache、handlebars、dust.js 等
这两篇文章中的第二篇很好地回答了问题 5,但除了 LinkedIn 之外,谷歌的结果很少详细说明模板系统或暗示它是一个受欢迎的选择。此外,该帖子提到他们已经扩展了功能,并希望有一天能为原始项目做出贡献。我担心在他们这样做之前,我们可能还需要扩展功能。
话虽如此,LinkedIn对模板系统的原始要求与我们的非常接近(见下文),他们在选择之前显然做了一些非常彻底的调查。
我们的要求:
- DRY:理想情况下,我们希望在服务器(基于 Java)和客户端使用模板系统,如果我们选择 LinkedIn 的完整方法,则仅在客户端使用;
Instead of using a JSP, GSP, or ERB to assemble a page server side and send back HTML, we have the server send back just the dynamic data as JSON and have the page assembled in the browser using a static client-side template served from a CDN"
- 完全国际化
- 良好的社区支持
- 充足 易于使用/拿起
- 与jQuery和Backbone.js一起愉快地工作
- 有据可查
- DRY:理想情况下,我们希望在服务器(基于 Java)和客户端使用模板系统,如果我们选择 LinkedIn 的完整方法,则仅在客户端使用;
回答by g13n
Dust.js is a good option. It is better than some of the other templating frameworks because it does not constrain that the data should be in a file, or in a string, etc.
Dust.js 是一个不错的选择。它比其他一些模板框架更好,因为它不限制数据应该在文件中,或者在字符串中,等等。
Also it is being actively maintained https://github.com/linkedin/dustjs.
它也在积极维护https://github.com/linkedin/dustjs。
Has it been successful?
Yes, I know at least LinkedIn is using it and also contributing improvements/patches, etc.
Is it easy to use?
I have tried using it and it is as easy as Mustache or Handlebars.js.
Is it sufficiently documented?
Is community support good? (only 6 questions on ST tagged 'dust.js'!)
If you are comparing Mustache or Handlebars.js, dust.js does not have as many users, but I believe if you have an issue and post it on the LinkedIn repo they would definitely respond. I will too since I'm watching it :-)
What are the pros and cons when compared to other templating tools such as Underscore's templating, Google Closure Templates, Handlebars and Mustache.
As for pros, you can check when you should consider using dust.js here https://github.com/linkedin/dustjs#readme.
As for cons, there aren't enough users for dust.js compared to popular ones like Mustache or Handlebars.js. That said, the other libraries like Google Closure suffer the same problem.
But like I mentioned before, dust.js is designed very well compared to other frameworks IMHO.
Are there any problems using it with an MV* structure framework, e.g Backbone.js (online book)?
I have not used it with other MVC frameworks, but I don't think it should be a problem at all.
成功了吗?
是的,我知道至少 LinkedIn 正在使用它,并且还在贡献改进/补丁等。
这个容易用吗?
我试过使用它,它就像 Mustache 或 Handlebars.js 一样简单。
文件是否充分?
社区支持好不好?(ST 上只有 6 个问题标记为“dust.js”!)
如果您比较 Mustache 或 Handlebars.js,dust.js 的用户并不多,但我相信如果您有问题并将其发布在 LinkedIn 存储库上,他们肯定会做出回应。我也会,因为我正在看它:-)
与 Underscore 的模板、Google Closure Templates、Handlebars 和 Mustache 等其他模板工具相比,其优缺点是什么?
至于专业人士,您可以在这里查看何时应该考虑使用dust.js https://github.com/linkedin/dustjs#readme。
至于缺点,与 Mustache 或 Handlebars.js 等流行的相比,dust.js 的用户不够多。也就是说,像 Google Closure 这样的其他库也遇到了同样的问题。
但就像我之前提到的,与其他框架恕我直言相比,dust.js 的设计非常好。
将它与 MV* 结构框架一起使用是否有任何问题,例如 Backbone.js(在线书籍)?
我没有将它与其他 MVC 框架一起使用,但我认为它根本不应该是一个问题。
Hope that helps.
希望有帮助。
回答by Anton Mochalin
I'm doing a freelance project now for quite a big and established niche IT company and they've chosen dust.js for their HTML5 mobile app framework. And yes, LinkedIn is a big and successful company.
Sort of. Nothing really difficult but I needed to get accustomed to it. I worked with Freemarker on Java - Freemarker seemed quite a bit easier to use because of a lot of built-in power features. However, many may find dust.js nice - it has its clear logic, very lightweight syntax - there are things in dust.js to really like for many.
Freemarker for Java was documented much better. dust.js's GitHub page is very OK for starters but, for example, I couldn't find the description of all the dust.js filters there and needed to search on Google for it - however, that search easily provided me with the info I needed.
Didn't see much community support but the library is really lightweight and clear - a couple of Google searches was all I needed to gather all the necessary info.
Didn't use other JS templating tools.
The company I mentioned in the answer to the 1st question has built a lightweight HTML5 framework using dust.js together with both jQuery and Backbone.js. I'm doing the project for them using that framework and tapping to both jQuery and Backbone.js functionality all the time - nothing to complain about. dust.js is a little bit like Backbone.js - lightweight and not imposing much restrictions on your coding style or other libraries you use. Using it you will see that there is some preferrable form of JS objects you use to feed it with the data but it's easy to get accustomed to (I mean if you need lists of something in your views it's better to feed dust.js with lists and not JS object hashes which at the same time are natural at describing separate entities).
我现在正在为一家相当大的成熟的利基 IT 公司做一个自由项目,他们选择了dust.js 作为他们的 HTML5 移动应用程序框架。是的,LinkedIn 是一家成功的大公司。
有点。没什么特别难的,但我需要习惯它。我在 Java 上使用 Freemarker - Freemarker 似乎更容易使用,因为有很多内置的强大功能。然而,许多人可能会觉得dust.js 很好——它有清晰的逻辑,非常轻量级的语法——dust.js 中有很多人非常喜欢的东西。
Freemarker for Java 的文档要好得多。对于初学者来说,dust.js 的 GitHub 页面非常好,但是,例如,我在那里找不到所有dust.js 过滤器的描述,需要在 Google 上搜索它 - 但是,该搜索很容易为我提供了我的信息需要。
没有看到太多社区支持,但该库非常轻量级和清晰 - 我只需要几次谷歌搜索就可以收集所有必要的信息。
没有使用其他 JS 模板工具。
我在第一个问题的回答中提到的公司已经使用dust.js 以及jQuery 和Backbone.js 构建了一个轻量级的HTML5 框架。我正在使用该框架为他们做项目,并一直利用 jQuery 和 Backbone.js 功能 - 没有什么可抱怨的。dust.js 有点像 Backbone.js - 轻量级并且不会对您的编码风格或您使用的其他库施加太多限制。使用它你会发现有一些更可取的 JS 对象形式,你用来向它提供数据,但很容易习惯(我的意思是,如果你需要在你的视图中列出一些东西,最好用列表提供给dust.js而不是 JS 对象哈希,它同时在描述单独的实体时很自然)。
One thing about performance - you can develop your app with "full" version and then compile your templates for production (using for example node.js + dust.js npm module - grunt can be useful here) to be used with "core" version. In this case you could get quite a boost in real-world performance - putting all the templates together and minifying them will free the client browser from fetching the templates from server every time it needs them. "Full" and "core" are not about commercial/free - the core version just doesn't have the template compiler and is to be used with pre-compiled templates.
关于性能的一件事 - 您可以使用“完整”版本开发您的应用程序,然后编译用于生产的模板(例如使用 node.js +dust.js npm 模块 - grunt 在这里很有用)与“核心”版本一起使用. 在这种情况下,您可以获得相当大的实际性能提升 - 将所有模板放在一起并缩小它们将使客户端浏览器在每次需要它们时从服务器获取模板。“完整”和“核心”与商业/免费无关 - 核心版本只是没有模板编译器,而是与预编译模板一起使用。