Sha256: ccc4f74fc1987563866e19ece87d402a4ab70f0835556cef751b1994e63deff7

Contents?: true

Size: 1.23 KB

Versions: 5

Compression:

Stored size: 1.23 KB

Contents

module Convert
  module Converters

    # Convert vimeo movie URL to embedded iframe
    def vimeo(string, options = {})
      # Original: 440 248
      options = {
        :width => 590,
        :height => 335,
        :show_title => false,
        :show_byline => false,
        :show_portrait => false,
        :allow_fullscreen => true
      }.merge(options)

      @regex = /https?:\/\/(www.)?vimeo\.com\/([A-Za-z0-9._%-]*)((\?|#)\S+)?/

      string.gsub(@regex) do
        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]
        allow_fullscreen = " allowfullscreen" if options[:allow_fullscreen]
        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="//player.vimeo.com/video/#{vimeo_id}#{query_string}" width="#{width}" height="#{height}" frameborder="#{frameborder}"#{allow_fullscreen}></iframe>}
      end
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
convert-0.1.7 lib/converters/vimeo.rb
convert-0.1.6 lib/converters/vimeo.rb
convert-0.1.5 lib/converters/vimeo.rb
convert-0.1.4 lib/converters/vimeo.rb
convert-0.1.3 lib/converters/vimeo.rb