Module: VimeoEmbed

Defined in:
lib/vimeo_embed.rb,
lib/vimeo_embed/base.rb,
lib/vimeo_embed/engine.rb,
lib/vimeo_embed/railtie.rb,
lib/vimeo_embed/version.rb,
lib/vimeo_embed/video_details.rb,
lib/vimeo_embed/model_additions.rb

Defined Under Namespace

Modules: ModelAdditions Classes: Base, Engine, Railtie, VideoDetails

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.get_video_id(url) ⇒ Object



11
12
13
14
# File 'lib/vimeo_embed.rb', line 11

def self.get_video_id(url)
  url.strip!
  return url.gsub(/https?:\/\/?(?:www\.)?vimeo\.com\/?(\d+)/i, '\1')
end

.simple(video_url, width, height) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/vimeo_embed.rb', line 63

def self.simple(video_url, width, height)
  begin
    if video_url.to_s != ' '
      video_id = get_video_id(video_url)
      if video_id.present?
        return %Q{<div class="vimeo_embed_video"><iframe title="Vimeo player" width="#{ width }" height="#{ height }" src="http://player.vimeo.com/video/#{ video_id }" frameborder="0" allowfullscreen></iframe></div>}
      else
        return video_url
      end
    end
  rescue Exception => e
    Rails.logger.debug e.message
  end
end

.thumbnail_and_description(video_url, width, height) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/vimeo_embed.rb', line 28

def self.thumbnail_and_description(video_url, width, height)
  begin
    if video_url.to_s != ' '
      video_id = get_video_id(video_url)
      if video_id.present?
        video_details = VimeoEmbed::VideoDetails.info(video_id)
        return %Q{<div class="vimeo_embed_video">
          <div class="vimeo_embed_partial_video">
            <div class="vimeo_embed_thumbnail">
              <img src="#{video_details[0]["thumbnail_small"] ? video_details[0]["thumbnail_small"] : ""}" />
            </div>
            <div class="vimeo_embed_details">
              <div class="vimeo_embed_title">
               <strong>
                 #{video_details[0]["title"] ? video_details[0]["title"] : ""}
               </strong>
              </div>
              <div class="vimeo_embed_description">
                #{video_details[0]["description"] ? video_details[0]["description"].truncate(185) : ""}
              </div>
            </div>
          </div>
          <div class="vimeo_embed_main_video" style="display:none;">
            <iframe title="Vimeo player" width="#{ width }" height="#{ height }" src="http://player.vimeo.com/video/#{ video_id }" frameborder="0" allowfullscreen></iframe>
          </div>
        </div>}
      else
        return video_url
      end
    end
  rescue Exception => e
    Rails.logger.debug e.message
  end
end

.vimeo_embed(data, options = {:with_description => true, :height => 200, :width => 300}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vimeo_embed.rb', line 16

def self.vimeo_embed(data, options = {:with_description => true, :height => 200, :width => 300})
  if data.match(/https?:\/\/?(?:www\.)?vimeo\.com/)
    data = data.gsub(/<a?[^<]+ href="https?:\/\/?(?:www\.)?vimeo\.com\/\d+"?[^<]+>([^<]+)<\/a>/i, '\1')
    if options[:with_description]
      data = data.gsub(/(https?:\/\/?(?:www\.)?vimeo\.com\/\d+)/i, thumbnail_and_description("#{$1}", options[:width], options[:height]))
    else
      data = data.gsub(/(https?:\/\/?(?:www\.)?vimeo\.com\/\d+)/i, simple("#{$1}", options[:width], options[:height]))
    end
  end
  return data
end