Class: Onebox::Engine::YoutubeOnebox

Inherits:
Object
  • Object
show all
Includes:
Onebox::Engine, StandardEmbed
Defined in:
lib/onebox/engine/youtube_onebox.rb

Constant Summary

Constants included from Onebox::Engine

DEFAULT

Instance Attribute Summary

Attributes included from Onebox::Engine

#errors, #timeout, #uri, #url

Instance Method Summary collapse

Methods included from StandardEmbed

add_oembed_provider, add_opengraph_provider, #always_https?, oembed_providers, opengraph_providers, #raw

Methods included from Onebox::Engine

all_iframe_origins, engines, included, #initialize, #options, #options=, origins_to_regexes

Instance Method Details

#placeholder_htmlObject



16
17
18
19
20
21
22
23
24
# File 'lib/onebox/engine/youtube_onebox.rb', line 16

def placeholder_html
  og = get_opengraph.data

  if video_id || list_id
    "<img src='#{og[:image]}' width='#{WIDTH}' height='#{HEIGHT}' title='#{og[:title]}'>"
  else
    to_html
  end
end

#to_htmlObject



26
27
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
# File 'lib/onebox/engine/youtube_onebox.rb', line 26

def to_html
  if video_id
    "      <iframe width=\"\#{WIDTH}\"\n              height=\"\#{HEIGHT}\"\n              src=\"https://www.youtube.com/embed/\#{video_id}?\#{embed_params}\"\n              frameborder=\"0\"\n              allowfullscreen>\n      </iframe>\n    HTML\n  elsif list_id\n    <<-HTML\n      <iframe width=\"\#{WIDTH}\"\n              height=\"\#{HEIGHT}\"\n              src=\"https://www.youtube.com/embed/videoseries?list=\#{list_id}&wmode=transparent&rel=0&autohide=1&showinfo=1&enablejsapi=1\"\n              frameborder=\"0\"\n              allowfullscreen>\n      </iframe>\n    HTML\n  else\n    # for channel pages\n    html = Onebox::Engine::AllowlistedGenericOnebox.new(@url, @timeout).to_html\n    return if Onebox::Helpers.blank?(html)\n    html.gsub!(/['\"]\\/\\//, \"https://\")\n    html\n  end\nend\n"

#video_titleObject



54
55
56
# File 'lib/onebox/engine/youtube_onebox.rb', line 54

def video_title
  @video_title ||= get_opengraph.data[:title]
end