0.01
No commit activity in last 3 years
No release in over 3 years
Convert a Url to image or video embed
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Convert a Url to image or video embed.

Supports:

  • Youtube
  • Vimeo
  • *.jpg/png/gif
  • easy to add more
  • give size settings and restrict providers

Install

sudo gem install url_to_media_tag

Or

rails plugin install git://github.com/grosser/url_to_media_tag.git

Usage

Convert

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

settings

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

Find

urls = text.scan(%r{https?://[^\s]*})

Replace

text_with_embed = text.gsub(%r{https?://[^\s]*}){|url| UrlToMediaTag.convert(url) }

Alternative

  • auto_html If you want more fancy stuff like auto-linking + strip-tags + active-record-integration (and more dependencies / C-extensions)

TODO

  • let users choose which providers to convert

Author

Filter logic borrowed from Dejan Simic`s auto_html MIT-LICENSE

Michael Grosser
michael@grosser.it
Hereby placed under public domain, do what you want, just do not hold me accountable...