Class: HTML::Pipeline::VimeoFilter

Inherits:
TextFilter
  • Object
show all
Defined in:
lib/html/pipeline/vimeo/vimeo_filter.rb

Overview

HTML Filter for Vimeo links.

Context options:

:vimeo_width  - width of player
:vimeo_height  - height of player
:vimeo_show_title  - show video title
:vimeo_show_byline  - show user's byline
:vimeo_show_potrait  - show user's portrait
:vimeo_allow_fullscreen  - allow fullscreen
:vimeo_frameborder  - frame border of player

This filter does not write additional information to the context.

Instance Method Summary collapse

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/html/pipeline/vimeo/vimeo_filter.rb', line 18

def call
  regex = /(\s|^)https?:\/\/(www.)?vimeo\.com\/([A-Za-z0-9._%-]*)((\?|#)\S+)?/
  @text.gsub(regex) do
    vimeo_id = $3
    width  = context[:vimeo_width] || 440
    height = context[:vimeo_height] || 248
    show_title      = "title=0"    unless context[:vimeo_show_title]
         = "byline=0"   unless context[:vimeo_show_byline]
    show_portrait   = "portrait=0" unless context[:vimeo_show_portrait]
    allow_fullscreen = " webkitallowfullscreen mozallowfullscreen allowfullscreen" if context[:vimeo_allow_fullscreen]
    frameborder     = context[:vimeo_frameborder] || 0
    query_string_variables = [show_title, , show_portrait].compact.join("&")
    query_string    = "?" + query_string_variables unless query_string_variables.empty?

    %{<iframe src="//player.vimeo.com/video/#{vimeo_id}#{query_string}" width="#{width}" height="#{height}" frameborder="#{frameborder}"#{allow_fullscreen}></iframe>}
  end
end