class AutoHtml::Vimeo
Vimeo
filter
Public Class Methods
new(width: 420, height: 315, allow_fullscreen: true)
click to toggle source
# File lib/auto_html/vimeo.rb, line 8 def initialize(width: 420, height: 315, allow_fullscreen: true) @width = width @height = height @allow_fullscreen = allow_fullscreen end
Public Instance Methods
call(text)
click to toggle source
# File lib/auto_html/vimeo.rb, line 14 def call(text) text.gsub(vimeo_pattern) do vimeo_id = Regexp.last_match(2) src = src_url(vimeo_id) tag(:iframe, { src: src }.merge(iframe_attributes)) { '' } end end
Private Instance Methods
fullscreen_attributes()
click to toggle source
# File lib/auto_html/vimeo.rb, line 41 def fullscreen_attributes { webkitallowfullscreen: 'yes', mozallowfullscreen: 'yes', allowfullscreen: 'yes' } end
iframe_attributes()
click to toggle source
# File lib/auto_html/vimeo.rb, line 32 def iframe_attributes {}.tap do |attrs| attrs[:width] = @width attrs[:height] = @height attrs[:frameborder] = 0 attrs.merge!(fullscreen_attributes) if @allow_fullscreen end end
src_url(vimeo_id)
click to toggle source
# File lib/auto_html/vimeo.rb, line 28 def src_url(vimeo_id) "//player.vimeo.com/video/#{vimeo_id}" end
vimeo_pattern()
click to toggle source
# File lib/auto_html/vimeo.rb, line 24 def vimeo_pattern @vimeo_pattern ||= %r{https?://(www.)?vimeo\.com/([A-Za-z0-9._%-]*)((\?|#)\S+)?} end