gpt4 book ai didi

ruby-on-rails - 火腿 + mustache

转载 作者:太空宇宙 更新时间:2023-11-03 17:56:56 25 4
gpt4 key购买 nike

我正在尝试使用 Haml + Mustache 创建一个博客,但是字段“description”有一个 CKEditor,因此该字段总是包含 html 标签,但 Mustache 不会呈现为 html,即使放置“description.html_safe” .

我的 helper :

def post_for_mustache(post)
{
post: {
category: {
url: category_order_path(:category => post.category.to_param),
name: post.category.name
},
url: category_post_path(:category => post.category.to_param,
:slug => post.to_param),
title: post.title,
comment_enabled: post.comment_enabled,
description: post.description.html_safe,
title_escape: URI.escape(post.title),
url_escape: URI.escape(category_post_url(:category => post.category.to_param,
:slug => post.to_param)),
}
}
end

我的 mustache 初始化程序:

module MustacheTemplateHandler
def self.call(template)
haml = "Haml::Engine.new(#{template.source.inspect}).render"
if template.locals.include? 'mustache'
"Mustache.render(#{haml}, mustache).html_safe"
else
haml.html_safe
end
end
end
ActionView::Template.register_template_handler(:mustache, MustacheTemplateHandler)

最佳答案

我猜你在你的 mustache 里做这样的事情:

{{description}}

如果description包含HTML,你需要说:

{{{description}}}

来自fine manual :

Variables
[...]
All variables are HTML escaped by default. If you want to return unescaped HTML, use the triple mustache: {{{name}}}.

因此 {{description}} 将是 Mustache 编码的 HTML,但 {{{descriptipn}}} 将按原样使用 description .

关于ruby-on-rails - 火腿 + mustache ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11783409/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com