Sha256: 40b9ae8a30bc803b5f5ba6be361b0dc6205aba4c52e9e49adea13d66dabd4bad
Contents?: true
Size: 1.41 KB
Versions: 1
Compression:
Stored size: 1.41 KB
Contents
module UrlToMediaTag VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip DEFAULTS = { :width => 640, :height => 480 } def self.convert(url, options={}) options = DEFAULTS.merge(options) case url # youtube when /http:\/\/(www.)?youtube\.com\/watch\?v=([A-Za-z0-9._%-]*)(\&\S+)?|http:\/\/(www.)?youtu\.be\/([A-Za-z0-9._%-]*)?/ youtube_id = $2 || $5 width = options[:width] height = options[:height] frameborder = options[:frameborder] %{<iframe class="youtube-player" type="text/html" width="#{width}" height="#{height}" src="http://www.youtube.com/embed/#{youtube_id}" frameborder="#{frameborder}"></iframe>} # vimeo when /http:\/\/(www.)?vimeo\.com\/([A-Za-z0-9._%-]*)((\?|#)\S+)?/ vimeo_id = $2 width = options[:width] height = options[:height] show_title = "title=0" unless options[:show_title] show_byline = "byline=0" unless options[:show_byline] show_portrait = "portrait=0" unless options[:show_portrait] frameborder = options[:frameborder] || 0 query_string_variables = [show_title, show_byline, show_portrait].compact.join("&") query_string = "?" + query_string_variables unless query_string_variables.empty? %{<iframe src="http://player.vimeo.com/video/#{vimeo_id}#{query_string}" width="#{width}" height="#{height}" frameborder="#{frameborder}"></iframe>} end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
url_to_media_tag-0.1.0 | lib/url_to_media_tag.rb |