Sha256: 261359154b2574bf4079e8cbfbaa33db2343e95bcf6f89b31fd8ee2eaa65fe22

Contents?: true

Size: 980 Bytes

Versions: 2

Compression:

Stored size: 980 Bytes

Contents

AutoHtml.add_filter(:youtube_image).with(:width => 320, :height => 315, :style => 'medium', :target => 'blank', :border => '0') do |text, options|
  styles = { 'default' => 'default', 'high' => 'hqdefault',
             'medium' => 'mqdefault', 'normal' => 'sddefault',
             'max' => 'maxresdefault' }
  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 = $4
    video_url = "https://www.youtube.com/watch?v=#{youtube_id}"
    target = options[:target]
    width = options[:width]
    height = options[:height]
    border = options[:border]
    style = styles[options[:style]] rescue styles['default']
    src = "//img.youtube.com/vi/#{youtube_id}/#{style}.jpg"
    %{<div class="thumbnail youtube"><a href="#{video_url}" target="_#{target}"><img src="#{src}" width="#{width}" height="#{height}" border="#{border}"></a></div>}
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
auto_html-whistlerbrk-2.0.0.pre lib/auto_html/filters/youtube_image.rb
auto_html-1.6.4 lib/auto_html/filters/youtube_image.rb