我正试图用Haml+Mustache创建一个博客,但字段“description”有一个CKEditor,因此该字段总是包含html标记,但Mustache即使放入“description.html_safe”也不会呈现为html。
我的助手:
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)