Sha256: 7c94d20f6369533a08874c95291ae23a6cc3da12898d4566a01461adf5a85740
Contents?: true
Size: 915 Bytes
Versions: 1
Compression:
Stored size: 915 Bytes
Contents
AutoHtml.add_filter(:youtube).with(:width => 420, :height => 315, :frameborder => 0, :wmode => nil, :autoplay => false, :hide_related => false) do |text, options| regex = /https?:\/\/(www.)?(youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/watch\?feature=player_embedded&v=)([A-Za-z0-9_-]*)(\&\S+)?(\?\S+)?/ text.gsub(regex) do youtube_id = $3 width = options[:width] height = options[:height] frameborder = options[:frameborder] wmode = options[:wmode] autoplay = options[:autoplay] hide_related = options[:hide_related] src = "//www.youtube.com/embed/#{youtube_id}" params = [] params << "wmode=#{wmode}" if wmode params << "autoplay=1" if autoplay params << "rel=0" if hide_related src += "?#{params.join '&'}" unless params.empty? %{<iframe width="#{width}" height="#{height}" src="#{src}" frameborder="#{frameborder}" allowfullscreen></iframe>} end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
auto_html-1.6.1 | lib/auto_html/filters/youtube.rb |