= Auto html
Rails plugin for transforming urls to appropriate resource (image, link, YouTube, Vimeo video,...).
Check out the {live demo}[http://auto-html.rors.org].
== Synopsis
auto_html plugin is the perfect choice if you don't want to bother visitors with rich HTML editor or markup code, but you still want to allow them to embed video, images, links and more on your site, purely by pasting URL.
Let's say you have model Comment with attribute body. Create another column in table Comments called body_html. Now have something like this:
class Comment < ActiveRecord::Base
auto_html_for :body do
html_escape
image
youtube :width => 400, :height => 250
link :target => "_blank", :rel => "nofollow"
simple_format
end
end
... and you'll have this behaviour:
Comment.create(:body => 'Hey check out this cool video: http://www.youtube.com/watch?v=WdsGihou8J4')
=> #Hey check out this cool video:
'>
Note that order of invoking filters is important, ie. you want html_escape as first and link amongst last, so that it doesn't transform youtube URL to plain link.
Now all you have to do is to display it in template without escaping, since plugin took care of that:
<% for comment in @comments %>