Miriam H.
Miriam H.

Reputation: 681

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!

Upvotes: 7

Views: 474

Answers (1)

Leo
Leo

Reputation: 4447

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.

Upvotes: 6

Related Questions