Sha256: 088f32d7738dc7277e03de98aa0dfbfa3914085775d69480c2ca47b3d1de58b0

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

module Onebox
  module Engine
    class VimeoOnebox
      include Engine
      include StandardEmbed

      # only match private Vimeo video links
      matches_regexp(/^https?:\/\/(www\.)?vimeo\.com\/\d+\/[^\/]+?$/)
      always_https

      WIDTH  ||= 640
      HEIGHT ||= 360

      def placeholder_html
        image_src = og_data.image_secure_url || og_data.image_url
        "<img src='#{image_src}' width='#{WIDTH}' height='#{HEIGHT}' #{og_data.title_attr}>"
      end

      def to_html
        video_src = og_data.video_secure_url || og_data.video_url
        if video_src.nil?
          id = uri.path[/\/(\d+)/, 1]
          video_src = "https://player.vimeo.com/video/#{id}"
        end
        video_src = video_src.gsub('autoplay=1', '').chomp("?")
        <<-HTML
          <iframe width="#{WIDTH}"
                  height="#{HEIGHT}"
                  src="#{video_src}"
                  data-original-href="#{link}"
                  frameborder="0"
                  allowfullscreen>
          </iframe>
        HTML
      end

      private

      def og_data
        @og_data = get_opengraph
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
onebox-1.8.89 lib/onebox/engine/vimeo_onebox.rb