Convert an Youtube/Vimeo/Image... Url to image or video embed.
Convert a Url to image or video embed.
Supports:
sudo gem install url_to_media_tag
Or
rails plugin install git://github.com/grosser/url_to_media_tag.git
UrlToMediaTag.convert('http://www.youtube.com/watch?v=kW-dS4otEZU') # -> <iframe ...>
UrlToMediaTag.convert(url, :width => 480, :height => 320) # -> <iframe ...>
UrlToMediaTag.convert('http://foo.com/xxx.jpg') # -> <img
UrlToMediaTag.convert('no-url') # -> nil
More specific settings overwrite others
UrlToMediaTag.convert(url, :width => '400px', :settings => {:image => {:width => '100%'}, :vimeo => {:show_title => true})
any -> :width => '400px'
image -> :width => '100%'
vimeo -> :width => '400px', :show_title => true
Videos get default settings
:width => 640,
:height => 480,
:class => "url-to-media-tag-video",
:frameborder => 0
urls = text.scan(%r{https?://[^\s]*})
text_with_embed = text.gsub(%r{https?://[^\s]*}){|url| UrlToMediaTag.convert(url) }
Filter logic borrowed from Dejan Simic`s auto_html MIT-LICENSE
Michael Grosser [email protected] Hereby placed under public domain, do what you want, just do not hold me accountable...