为 auto_html 创建过滤器 [英] Creating filters for auto_html
本文介绍了为 auto_html 创建过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为 auto_html 创建一个自定义过滤器.我把过滤器放在哪里才能使用它?文档没有涉及任何这些.谢谢!
I want to create a custom filter for auto_html. Where do I put the filter so I can use it? The documentation doesn't touch on any of that. Thanks!
推荐答案
我采取的方法是将代码添加到初始化文件中,例如:
The approach I took was to add the code to an initializer file such as:
/path/to/your/application/config/initializers/auto_html.rb
然后你可以写一些类似的东西:
Then you can just write something like:
AutoHtml.add_filter(:change_colours).with({}) do |text, options|
text.gsub("#FF0000", "#00FF00")
end
并在您的模型中调用 auto_html(input) { change_colours }
.空散列将采用您关心的任何选项传递给过滤器.
And call auto_html(input) { change_colours }
in your model. The empty hash will take any options you care to pass to the filter.
这篇关于为 auto_html 创建过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文