Rails 最终用户模板引擎:Liquid、Mustache 与其他?
我正在创建一项服务,希望允许最终用户编辑网页的 HTML 模板,从而允许访问包含在模板中的特定“变量”。
我知道液体就是为此目的而设计的,是安全的(至少相对而言),并且在大量生产中使用。然而,我发现与 Mustache 这样的语言相比,这种语言对于最终用户来说相当复杂。
Mustache 听起来不错,但我担心安全性......它曾经用于最终用户模板吗?
基本上我正在寻找一个可以与 Rails 一起为最终用户使用的模板引擎,即:
- 安全 - 不允许用户执行代码......至少在服务器上不允许。用户将被允许插入客户端 JavaScript。
- 功能强大 - 允许最终用户使用提供的“变量”并在 #1 的上下文中创建他们可以想象的几乎任何网页
- 简单 - 语法清晰且易于最终用户应用
- 如果支持的话 奖励积分用 javascript 和其他语言呈现模板语法。
液体满足1& 2,但不是 3-4。小胡子符合 2-4,但我不确定 #1,这是没有商量余地的。
非常感谢任何见解、经验或评论。
I am creating a service in which I want to allow end-users to edit HTML templates for web pages that allows for access to specific "variables" for inclusion in the template.
I know that liquid was designed for this very purpose, is secure (at least relatively), and is in heavy production use. However, I find the language to be fairly complex for end-users as compared to something like Mustache.
Mustache sounds great, but I am concerned about security... has it ever been used for end-user templates?
Basically I am looking for a templating engine I can use w/ Rails for end-users that is:
- Secure - will not allow the execution of code by the user... at least not on the server. Users will be allowed to insert client-side javascript.
- Powerful - allows end-users to create pretty much any web page they can imagine using the supplied "variables" and within the context of #1
- Simple - the syntax is clear and easy for end-users to apply
- Bonus points if there is support for rendering the template syntax in javascript and other languages.
Liquid meets 1 & 2, but not 3-4. Mustache meets 2-4, but I'm not sure about #1 and that is non-negotiable.
Greatly appreciate any insights, experiences, or comments.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Mustache 非常适合插值,如果您使用它进行 Javascript 评估,我无法想象它会让您面临服务器端漏洞。这是最简单、最强大的选择。我不知道非程序员是否会理解它,但我确信它比 Liquid 更简单。
另一种选择是使用现有的更简单的用户标记集(如 BBcode)或富文本编辑库(如 TinyMCE)。这些功能大大减少,但对于普通人来说更容易使用。
Mustache is fantastic for interpolation and I can't imagine it ever exposing you to server-side vulnerabilities if you're using it for Javascript evaluation. It's the simplest, most powerful option. I don't know that non-programmers would understand it, but I'm sure it's simpler than Liquid.
Another option would be to use an existing simpler user markup set like BBcode or a rich-text editing library like TinyMCE. These are much reduced in functionality, but are easier to use for average people.