Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating filters for 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!

like image 562
Miriam H. Avatar asked Jun 06 '12 06:06

Miriam H.


1 Answers

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 

And call auto_html(input) { change_colours } in your model. The empty hash will take any options you care to pass to the filter.

like image 131
Leo Avatar answered Sep 22 '22 17:09

Leo