我使用 Mustache 作为一个非常基本的模板引擎,供我的用户创建配置文件。我需要将这些格式化为纯文本而不是 html。
目前,我的 html 模板中的东西工作正常,但我无法将其呈现为纯文本。
我的 html 模板中有以下内容:
 <div id="network" data-json-url="<%= @nas %>">
 <div id="sampleArea2"></div>
 <script id="network_details" type="text/template">
 <%= simple_format(@location.body) %>
 </script>
其中@location.body 是用户可编辑的文本区域:
 option foo {{ location_sausage }}
 option bar '{{ location_sheep }}'
这会输出如下内容:
 option foo barbara
 option bar 'margo'
有没有一种简单的方法可以将其转换为纯文本 - 以前,在胡子之前,我只是在我的控制器中使用过:
 format.text
- 更新 -
以前使用 erb,我做了这样的事情来将视图中的字段呈现为文本:
 <%= (ERB.new(@config.body).result(binding)).html_safe %>
我尝试将其替换为:
 <%= Mustache.render(@config.body).html_safe %>
但是请求中没有获取数据。
欢迎任何建议。