onebox 2.2.12 → 2.2.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +0 -4
  3. data/lib/onebox/engine.rb +1 -1
  4. data/lib/onebox/engine/allowlisted_generic_onebox.rb +11 -9
  5. data/lib/onebox/engine/amazon_onebox.rb +3 -1
  6. data/lib/onebox/engine/asciinema_onebox.rb +0 -1
  7. data/lib/onebox/engine/audioboom_onebox.rb +5 -2
  8. data/lib/onebox/engine/bandcamp_onebox.rb +8 -8
  9. data/lib/onebox/engine/cloudapp_onebox.rb +12 -12
  10. data/lib/onebox/engine/coub_onebox.rb +0 -1
  11. data/lib/onebox/engine/facebook_media_onebox.rb +8 -7
  12. data/lib/onebox/engine/five_hundred_px_onebox.rb +0 -1
  13. data/lib/onebox/engine/flickr_onebox.rb +14 -15
  14. data/lib/onebox/engine/giphy_onebox.rb +0 -1
  15. data/lib/onebox/engine/github_blob_onebox.rb +4 -0
  16. data/lib/onebox/engine/github_commit_onebox.rb +2 -3
  17. data/lib/onebox/engine/github_gist_onebox.rb +1 -2
  18. data/lib/onebox/engine/github_issue_onebox.rb +16 -18
  19. data/lib/onebox/engine/github_pullrequest_onebox.rb +7 -4
  20. data/lib/onebox/engine/gitlab_blob_onebox.rb +4 -0
  21. data/lib/onebox/engine/google_calendar_onebox.rb +1 -1
  22. data/lib/onebox/engine/google_docs_onebox.rb +7 -7
  23. data/lib/onebox/engine/google_drive_onebox.rb +7 -7
  24. data/lib/onebox/engine/google_maps_onebox.rb +0 -2
  25. data/lib/onebox/engine/google_photos_onebox.rb +14 -14
  26. data/lib/onebox/engine/google_play_app_onebox.rb +3 -7
  27. data/lib/onebox/engine/instagram_onebox.rb +2 -2
  28. data/lib/onebox/engine/kaltura_onebox.rb +8 -6
  29. data/lib/onebox/engine/opengraph_image.rb +0 -1
  30. data/lib/onebox/engine/pubmed_onebox.rb +3 -2
  31. data/lib/onebox/engine/replit_onebox.rb +0 -1
  32. data/lib/onebox/engine/sketchfab_onebox.rb +8 -8
  33. data/lib/onebox/engine/slides_onebox.rb +10 -10
  34. data/lib/onebox/engine/soundcloud_onebox.rb +0 -1
  35. data/lib/onebox/engine/stack_exchange_onebox.rb +2 -1
  36. data/lib/onebox/engine/standard_embed.rb +2 -2
  37. data/lib/onebox/engine/steam_store_onebox.rb +6 -5
  38. data/lib/onebox/engine/trello_onebox.rb +2 -2
  39. data/lib/onebox/engine/twitch_clips_onebox.rb +1 -3
  40. data/lib/onebox/engine/twitch_stream_onebox.rb +1 -2
  41. data/lib/onebox/engine/twitch_video_onebox.rb +0 -2
  42. data/lib/onebox/engine/typeform_onebox.rb +7 -6
  43. data/lib/onebox/engine/vimeo_onebox.rb +9 -7
  44. data/lib/onebox/engine/wikimedia_onebox.rb +1 -2
  45. data/lib/onebox/engine/wikipedia_onebox.rb +12 -8
  46. data/lib/onebox/engine/youku_onebox.rb +7 -7
  47. data/lib/onebox/engine/youtube_onebox.rb +14 -13
  48. data/lib/onebox/file_type_finder.rb +0 -1
  49. data/lib/onebox/helpers.rb +2 -2
  50. data/lib/onebox/mixins/git_blob_onebox.rb +5 -3
  51. data/lib/onebox/mixins/github_body.rb +30 -0
  52. data/lib/onebox/mixins/twitch_onebox.rb +0 -1
  53. data/lib/onebox/preview.rb +1 -2
  54. data/lib/onebox/version.rb +1 -1
  55. data/templates/github/github_body.mustache +3 -0
  56. data/templates/githubissue.mustache +7 -9
  57. data/templates/githubpullrequest.mustache +4 -16
  58. metadata +4 -2
@@ -5,7 +5,7 @@ module Onebox
5
5
  class GoogleCalendarOnebox
6
6
  include Engine
7
7
 
8
- matches_regexp /^(https?:)?\/\/((www|calendar)\.google\.[\w.]{2,}|goo\.gl)\/calendar\/.+$/
8
+ matches_regexp(/^(https?:)?\/\/((www|calendar)\.google\.[\w.]{2,}|goo\.gl)\/calendar\/.+$/)
9
9
  always_https
10
10
  requires_iframe_origins "https://calendar.google.com"
11
11
 
@@ -19,19 +19,19 @@ module Onebox
19
19
  }
20
20
  end
21
21
 
22
- matches_regexp /^(https?:)?\/\/(docs\.google\.com)\/(?<endpoint>(#{supported_endpoints.join('|')}))\/d\/((?<key>[\w-]*)).+$/
22
+ matches_regexp(/^(https?:)?\/\/(docs\.google\.com)\/(?<endpoint>(#{supported_endpoints.join('|')}))\/d\/((?<key>[\w-]*)).+$/)
23
23
  always_https
24
24
 
25
25
  protected
26
26
 
27
27
  def data
28
28
  og_data = get_og_data
29
- result = { link: link,
30
- title: og_data[:title] || "Google #{shorttype.to_s.capitalize}",
31
- description: Onebox::Helpers.truncate(og_data[:description], 250) || "This #{shorttype.to_s.chop.capitalize} is private",
32
- type: shorttype
33
- }
34
- result
29
+ {
30
+ link: link,
31
+ title: og_data[:title] || "Google #{shorttype.to_s.capitalize}",
32
+ description: Onebox::Helpers.truncate(og_data[:description], 250) || "This #{shorttype.to_s.chop.capitalize} is private",
33
+ type: shorttype
34
+ }
35
35
  end
36
36
 
37
37
  def doc_type
@@ -7,7 +7,7 @@ module Onebox
7
7
  include StandardEmbed
8
8
  include LayoutSupport
9
9
 
10
- matches_regexp /^(https?:)?\/\/(drive\.google\.com)\/file\/d\/(?<key>[\w-]*)\/.+$/
10
+ matches_regexp(/^(https?:)?\/\/(drive\.google\.com)\/file\/d\/(?<key>[\w-]*)\/.+$/)
11
11
  always_https
12
12
 
13
13
  protected
@@ -18,12 +18,12 @@ module Onebox
18
18
  title = "#{og_data.title} (video)" if og_data.type =~ /^video[\/\.]/
19
19
  description = og_data.description || "Google Drive file."
20
20
 
21
- result = { link: link,
22
- title: title,
23
- description: Onebox::Helpers.truncate(description, 250),
24
- image: og_data.image
25
- }
26
- result
21
+ {
22
+ link: link,
23
+ title: title,
24
+ description: Onebox::Helpers.truncate(description, 250),
25
+ image: og_data.image
26
+ }
27
27
  end
28
28
  end
29
29
  end
@@ -22,7 +22,6 @@ module Onebox
22
22
  end
23
23
 
24
24
  always_https
25
-
26
25
  requires_iframe_origins("https://maps.google.com", "https://google.com")
27
26
 
28
27
  # Matches shortened Google Maps URLs
@@ -176,7 +175,6 @@ module Onebox
176
175
  http.finish rescue nil
177
176
  end
178
177
  end
179
-
180
178
  end
181
179
  end
182
180
  end
@@ -46,27 +46,27 @@ module Onebox
46
46
  album_title = og.description.nil? ? og.title : "[#{og.description}] #{og.title}"
47
47
 
48
48
  <<-HTML
49
- <div class='onebox google-photos-album'>
50
- <a href='#{escaped_url}' target='_blank' rel='noopener'>
51
- <span class='outer-box' style='width:#{og.image_width}px'>
52
- <span class='inner-box'>
53
- <span class='album-title'>#{Onebox::Helpers.truncate(album_title, 80)}</span>
54
- </span>
49
+ <div class='onebox google-photos-album'>
50
+ <a href='#{escaped_url}' target='_blank' rel='noopener'>
51
+ <span class='outer-box' style='width:#{og.image_width}px'>
52
+ <span class='inner-box'>
53
+ <span class='album-title'>#{Onebox::Helpers.truncate(album_title, 80)}</span>
55
54
  </span>
56
- <img src='#{og.get_secure_image}' #{og.title_attr} height='#{og.image_height}' width='#{og.image_width}'>
57
- </a>
58
- </div>
59
- HTML
55
+ </span>
56
+ <img src='#{og.get_secure_image}' #{og.title_attr} height='#{og.image_height}' width='#{og.image_width}'>
57
+ </a>
58
+ </div>
59
+ HTML
60
60
  end
61
61
 
62
62
  def image_html(og)
63
63
  escaped_url = ::Onebox::Helpers.normalize_url_for_output(url)
64
64
 
65
65
  <<-HTML
66
- <a href='#{escaped_url}' target='_blank' rel='noopener' class="onebox">
67
- <img src='#{og.get_secure_image}' #{og.title_attr} alt='Google Photos' height='#{og.image_height}' width='#{og.image_width}'>
68
- </a>
69
- HTML
66
+ <a href='#{escaped_url}' target='_blank' rel='noopener' class="onebox">
67
+ <img src='#{og.get_secure_image}' #{og.title_attr} alt='Google Photos' height='#{og.image_height}' width='#{og.image_width}'>
68
+ </a>
69
+ HTML
70
70
  end
71
71
  end
72
72
  end
@@ -11,24 +11,20 @@ module Onebox
11
11
  MAX_DESCRIPTION_CHARS: 500
12
12
  }
13
13
 
14
- matches_regexp Regexp.new("^https?://play\\.(?:(?:\\w)+\\.)?(google)\\.com(?:/)?/store/apps/")
14
+ matches_regexp(/^https?:\/\/play\.(?:(?:\w)+\.)?(google)\.com(?:\/)?\/store\/apps\//)
15
15
  always_https
16
16
 
17
17
  private
18
18
 
19
19
  def data
20
20
  price = raw.css("meta[itemprop=price]").first["content"] rescue "Free"
21
- result = {
21
+ {
22
22
  link: link,
23
23
  title: raw.css("meta[property='og:title']").first["content"].gsub(" - Apps on Google Play", ""),
24
24
  image: ::Onebox::Helpers.normalize_url_for_output(raw.css("meta[property='og:image']").first["content"]),
25
25
  description: raw.css("meta[name=description]").first["content"][0..DEFAULTS[:MAX_DESCRIPTION_CHARS]].chop + "...",
26
- price: price
26
+ price: price == "0" ? "Free" : price
27
27
  }
28
- if result[:price] == "0"
29
- result[:price] = "Free"
30
- end
31
- result
32
28
  end
33
29
  end
34
30
  end
@@ -36,10 +36,10 @@ module Onebox
36
36
 
37
37
  def get_oembed_url
38
38
  if access_token != ''
39
- oembed_url = "https://graph.facebook.com/v9.0/instagram_oembed?url=#{clean_url}&access_token=#{access_token}"
39
+ "https://graph.facebook.com/v9.0/instagram_oembed?url=#{clean_url}&access_token=#{access_token}"
40
40
  else
41
41
  # The following is officially deprecated by Instagram, but works in some limited circumstances.
42
- oembed_url = "https://api.instagram.com/oembed/?url=#{clean_url}"
42
+ "https://api.instagram.com/oembed/?url=#{clean_url}"
43
43
  end
44
44
  end
45
45
  end
@@ -14,7 +14,7 @@ module Onebox
14
14
  og = get_opengraph
15
15
 
16
16
  <<~HTML
17
- <img src="#{og.image_secure_url}" width="#{og.video_width}" height="#{og.video_height}" >
17
+ <img src="#{og.image_secure_url}" width="#{og.video_width}" height="#{og.video_height}">
18
18
  HTML
19
19
  end
20
20
 
@@ -22,11 +22,13 @@ module Onebox
22
22
  og = get_opengraph
23
23
 
24
24
  <<~HTML
25
- <iframe src="#{og.video_secure_url}"
26
- width="#{og.video_width}" height="#{og.video_height}"
27
- frameborder='0'
28
- allowfullscreen >
29
- </iframe>
25
+ <iframe
26
+ src="#{og.video_secure_url}"
27
+ width="#{og.video_width}"
28
+ height="#{og.video_height}"
29
+ frameborder='0'
30
+ allowfullscreen
31
+ ></iframe>
30
32
  HTML
31
33
  end
32
34
  end
@@ -8,7 +8,6 @@ module Onebox
8
8
  og = get_opengraph
9
9
  "<img src='#{og.image}' width='#{og.image_width}' height='#{og.image_height}' class='onebox' #{og.title_attr}>"
10
10
  end
11
-
12
11
  end
13
12
  end
14
13
  end
@@ -6,7 +6,7 @@ module Onebox
6
6
  include Engine
7
7
  include LayoutSupport
8
8
 
9
- matches_regexp Regexp.new("^https?://(?:(?:\\w)+\\.)?(www.ncbi.nlm.nih)\\.gov(?:/)?/pubmed/\\d+")
9
+ matches_regexp(/^https?:\/\/(?:(?:\w)+\.)?(www.ncbi.nlm.nih)\.gov(?:\/)?\/pubmed\/\d+/)
10
10
 
11
11
  private
12
12
 
@@ -35,7 +35,8 @@ module Onebox
35
35
  end
36
36
 
37
37
  def data
38
- xml = get_xml()
38
+ xml = get_xml
39
+
39
40
  {
40
41
  title: xml.css("ArticleTitle").text,
41
42
  authors: authors_of_xml(xml),
@@ -20,7 +20,6 @@ module Onebox
20
20
  def to_html
21
21
  get_oembed.html
22
22
  end
23
-
24
23
  end
25
24
  end
26
25
  end
@@ -15,20 +15,20 @@ module Onebox
15
15
  src = og.video_url.gsub("autostart=1", "")
16
16
 
17
17
  <<-HTML
18
- <iframe src="#{src}"
19
- width="#{og.video_width}"
20
- height="#{og.video_height}"
21
- scrolling="no"
22
- frameborder="0"
23
- allowfullscreen>
24
- </iframe>
18
+ <iframe
19
+ src="#{src}"
20
+ width="#{og.video_width}"
21
+ height="#{og.video_height}"
22
+ scrolling="no"
23
+ frameborder="0"
24
+ allowfullscreen
25
+ ></iframe>
25
26
  HTML
26
27
  end
27
28
 
28
29
  def placeholder_html
29
30
  "<img src='#{get_opengraph.image}'>"
30
31
  end
31
-
32
32
  end
33
33
  end
34
34
  end
@@ -11,15 +11,16 @@ module Onebox
11
11
 
12
12
  def to_html
13
13
  <<-HTML
14
- <iframe src="https://slides.com#{uri.path}/embed?style=light"
15
- width="576"
16
- height="420"
17
- scrolling="no"
18
- frameborder="0"
19
- webkitallowfullscreen
20
- mozallowfullscreen
21
- allowfullscreen>
22
- </iframe>
14
+ <iframe
15
+ src="https://slides.com#{uri.path}/embed?style=light"
16
+ width="576"
17
+ height="420"
18
+ scrolling="no"
19
+ frameborder="0"
20
+ webkitallowfullscreen
21
+ mozallowfullscreen
22
+ allowfullscreen
23
+ ></iframe>
23
24
  HTML
24
25
  end
25
26
 
@@ -27,7 +28,6 @@ module Onebox
27
28
  escaped_src = ::Onebox::Helpers.normalize_url_for_output(raw[:image])
28
29
  "<img src='#{escaped_src}'>"
29
30
  end
30
-
31
31
  end
32
32
  end
33
33
  end
@@ -28,7 +28,6 @@ module Onebox
28
28
  oembed_url += "&maxheight=166" unless url["/sets/"]
29
29
  oembed_url
30
30
  end
31
-
32
31
  end
33
32
  end
34
33
  end
@@ -37,7 +37,7 @@ module Onebox
37
37
  end
38
38
 
39
39
  def data
40
- return @data if @data
40
+ return @data if defined?(@data)
41
41
 
42
42
  result = raw['items'][0]
43
43
  if result
@@ -48,6 +48,7 @@ module Onebox
48
48
  result['is_answer'] = result.key?('answer_id')
49
49
  result['is_question'] = result.key?('question_id')
50
50
  end
51
+
51
52
  @data = result
52
53
  end
53
54
  end
@@ -37,7 +37,7 @@ module Onebox
37
37
  end
38
38
 
39
39
  def raw
40
- return @raw if @raw
40
+ return @raw if defined?(@raw)
41
41
 
42
42
  og = get_opengraph
43
43
  twitter = get_twitter
@@ -67,7 +67,7 @@ module Onebox
67
67
  protected
68
68
 
69
69
  def html_doc
70
- return @html_doc if @html_doc
70
+ return @html_doc if defined?(@html_doc)
71
71
 
72
72
  headers = nil
73
73
  headers = { 'Cookie' => options[:cookie] } if options[:cookie]
@@ -28,11 +28,12 @@ module Onebox
28
28
  escaped_src = ::Onebox::Helpers.normalize_url_for_output(iframe_url)
29
29
 
30
30
  <<-HTML
31
- <iframe src='#{escaped_src}'
32
- frameborder='0'
33
- width='100%'
34
- height='190'>
35
- </iframe>
31
+ <iframe
32
+ src='#{escaped_src}'
33
+ frameborder='0'
34
+ width='100%'
35
+ height='190'
36
+ ></iframe>
36
37
  HTML
37
38
  end
38
39
  end
@@ -16,7 +16,7 @@ module Onebox
16
16
  height = match[:type] == 'b' ? 400 : 200
17
17
 
18
18
  <<-HTML
19
- <iframe src=\"#{link}\" width=\"100%\" height=\"#{height}\" frameborder=\"0\" style=\"border:0\"></iframe>
19
+ <iframe src="#{link}" width="100%" height="#{height}" frameborder="0" style="border:0"></iframe>
20
20
  HTML
21
21
  end
22
22
 
@@ -26,7 +26,7 @@ module Onebox
26
26
 
27
27
  private
28
28
  def match
29
- return @match if @match
29
+ return @match if defined?(@match)
30
30
 
31
31
  @match = @url.match(%{trello\.com/(?<type>[^/]+)/(?<key>[^/]+)/?\W*})
32
32
 
@@ -3,12 +3,11 @@
3
3
  require_relative '../mixins/twitch_onebox'
4
4
 
5
5
  class Onebox::Engine::TwitchClipsOnebox
6
-
7
6
  def self.twitch_regexp
8
7
  /^https?:\/\/clips\.twitch\.tv\/([a-zA-Z0-9_]+\/?[^#\?\/]+)/
9
8
  end
10
- include Onebox::Mixins::TwitchOnebox
11
9
 
10
+ include Onebox::Mixins::TwitchOnebox
12
11
  requires_iframe_origins "https://clips.twitch.tv"
13
12
 
14
13
  def query_params
@@ -18,5 +17,4 @@ class Onebox::Engine::TwitchClipsOnebox
18
17
  def base_url
19
18
  "clips.twitch.tv/embed?"
20
19
  end
21
-
22
20
  end
@@ -3,14 +3,13 @@
3
3
  require_relative '../mixins/twitch_onebox'
4
4
 
5
5
  class Onebox::Engine::TwitchStreamOnebox
6
-
7
6
  def self.twitch_regexp
8
7
  /^https?:\/\/(?:www\.|go\.)?twitch\.tv\/(?!directory)([a-zA-Z0-9_]{4,25})$/
9
8
  end
9
+
10
10
  include Onebox::Mixins::TwitchOnebox
11
11
 
12
12
  def query_params
13
13
  "channel=#{twitch_id}"
14
14
  end
15
-
16
15
  end
@@ -3,7 +3,6 @@
3
3
  require_relative '../mixins/twitch_onebox'
4
4
 
5
5
  class Onebox::Engine::TwitchVideoOnebox
6
-
7
6
  def self.twitch_regexp
8
7
  /^https?:\/\/(?:www\.)?twitch\.tv\/videos\/([0-9]+)/
9
8
  end
@@ -13,5 +12,4 @@ class Onebox::Engine::TwitchVideoOnebox
13
12
  def query_params
14
13
  "video=v#{twitch_id}"
15
14
  end
16
-
17
15
  end
@@ -13,12 +13,13 @@ module Onebox
13
13
  typeform_src = build_typeform_src
14
14
 
15
15
  <<~HTML
16
- <iframe src="#{typeform_src}"
17
- width="100%"
18
- height="600px"
19
- scrolling="no"
20
- frameborder="0">
21
- </iframe>
16
+ <iframe
17
+ src="#{typeform_src}"
18
+ width="100%"
19
+ height="600px"
20
+ scrolling="no"
21
+ frameborder="0"
22
+ ></iframe>
22
23
  HTML
23
24
  end
24
25