onebox 2.2.8 → 2.2.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) 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 +34 -12
  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/gfycat_onebox.rb +1 -1
  15. data/lib/onebox/engine/giphy_onebox.rb +0 -1
  16. data/lib/onebox/engine/github_blob_onebox.rb +4 -0
  17. data/lib/onebox/engine/github_commit_onebox.rb +2 -3
  18. data/lib/onebox/engine/github_gist_onebox.rb +1 -2
  19. data/lib/onebox/engine/github_issue_onebox.rb +16 -18
  20. data/lib/onebox/engine/github_pullrequest_onebox.rb +9 -1
  21. data/lib/onebox/engine/gitlab_blob_onebox.rb +4 -0
  22. data/lib/onebox/engine/google_calendar_onebox.rb +1 -1
  23. data/lib/onebox/engine/google_docs_onebox.rb +8 -8
  24. data/lib/onebox/engine/google_drive_onebox.rb +7 -7
  25. data/lib/onebox/engine/google_maps_onebox.rb +0 -2
  26. data/lib/onebox/engine/google_photos_onebox.rb +14 -14
  27. data/lib/onebox/engine/google_play_app_onebox.rb +3 -7
  28. data/lib/onebox/engine/html.rb +5 -1
  29. data/lib/onebox/engine/instagram_onebox.rb +2 -2
  30. data/lib/onebox/engine/kaltura_onebox.rb +8 -6
  31. data/lib/onebox/engine/opengraph_image.rb +0 -1
  32. data/lib/onebox/engine/pastebin_onebox.rb +1 -1
  33. data/lib/onebox/engine/pubmed_onebox.rb +3 -2
  34. data/lib/onebox/engine/replit_onebox.rb +0 -1
  35. data/lib/onebox/engine/sketchfab_onebox.rb +8 -8
  36. data/lib/onebox/engine/slides_onebox.rb +10 -10
  37. data/lib/onebox/engine/soundcloud_onebox.rb +0 -1
  38. data/lib/onebox/engine/stack_exchange_onebox.rb +2 -1
  39. data/lib/onebox/engine/standard_embed.rb +2 -2
  40. data/lib/onebox/engine/steam_store_onebox.rb +6 -5
  41. data/lib/onebox/engine/trello_onebox.rb +2 -2
  42. data/lib/onebox/engine/twitch_clips_onebox.rb +1 -3
  43. data/lib/onebox/engine/twitch_stream_onebox.rb +1 -2
  44. data/lib/onebox/engine/twitch_video_onebox.rb +0 -2
  45. data/lib/onebox/engine/twitter_status_onebox.rb +1 -1
  46. data/lib/onebox/engine/typeform_onebox.rb +7 -6
  47. data/lib/onebox/engine/vimeo_onebox.rb +9 -7
  48. data/lib/onebox/engine/wikimedia_onebox.rb +1 -2
  49. data/lib/onebox/engine/wikipedia_onebox.rb +12 -8
  50. data/lib/onebox/engine/youku_onebox.rb +7 -7
  51. data/lib/onebox/engine/youtube_onebox.rb +46 -17
  52. data/lib/onebox/file_type_finder.rb +0 -1
  53. data/lib/onebox/helpers.rb +25 -14
  54. data/lib/onebox/mixins/git_blob_onebox.rb +5 -3
  55. data/lib/onebox/mixins/github_body.rb +30 -0
  56. data/lib/onebox/mixins/twitch_onebox.rb +0 -1
  57. data/lib/onebox/preview.rb +1 -2
  58. data/lib/onebox/sanitize_config.rb +1 -1
  59. data/lib/onebox/version.rb +1 -1
  60. data/templates/github/github_body.mustache +3 -0
  61. data/templates/githubissue.mustache +7 -9
  62. data/templates/githubpullrequest.mustache +1 -0
  63. metadata +7 -5
@@ -1,13 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative '../mixins/github_body'
4
+
3
5
  module Onebox
4
6
  module Engine
5
7
  class GithubPullRequestOnebox
6
8
  include Engine
7
9
  include LayoutSupport
8
10
  include JSON
11
+ include Onebox::Mixins::GithubBody
12
+
13
+ GITHUB_COMMENT_REGEX = /(<!--.*?-->\r\n)/
9
14
 
10
- matches_regexp Regexp.new("^https?://(?:www\\.)?(?:(?:\\w)+\\.)?(github)\\.com(?:/)?(?:.)*/pull/")
15
+ matches_regexp(/^https?:\/\/(?:www\.)?(?:(?:\w)+\.)?(github)\.com(?:\/)?(?:.)*\/pull/)
11
16
  always_https
12
17
 
13
18
  def url
@@ -31,6 +36,9 @@ module Onebox
31
36
 
32
37
  ulink = URI(link)
33
38
  result['domain'] = "#{ulink.host}/#{ulink.path.split('/')[1]}/#{ulink.path.split('/')[2]}"
39
+
40
+ result['body'], result['excerpt'] = compute_body(result['body'])
41
+
34
42
  result
35
43
  end
36
44
  end
@@ -8,17 +8,21 @@ module Onebox
8
8
  def self.git_regexp
9
9
  /^https?:\/\/(www\.)?gitlab\.com.*\/blob\//
10
10
  end
11
+
11
12
  def self.onebox_name
12
13
  "gitlabblob"
13
14
  end
14
15
 
15
16
  include Onebox::Mixins::GitBlobOnebox
17
+
16
18
  def raw_regexp
17
19
  /gitlab\.com\/(?<user>[^\/]+)\/(?<repo>[^\/]+)\/blob\/(?<sha1>[^\/]+)\/(?<file>[^#]+)(#(L(?<from>[^-]*)(-L(?<to>.*))?))?/mi
18
20
  end
21
+
19
22
  def raw_template(m)
20
23
  "https://gitlab.com/#{m[:user]}/#{m[:repo]}/raw/#{m[:sha1]}/#{m[:file]}"
21
24
  end
25
+
22
26
  def title
23
27
  Sanitize.fragment(Onebox::Helpers.uri_unencode(link).sub(/^https?\:\/\/gitlab\.com\//, ''))
24
28
  end
@@ -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
@@ -47,7 +47,7 @@ module Onebox
47
47
  end
48
48
 
49
49
  def get_og_data
50
- response = Onebox::Helpers.fetch_response(url, 10) rescue nil
50
+ response = Onebox::Helpers.fetch_response(url, redirect_limit: 10) rescue nil
51
51
  html = Nokogiri::HTML(response)
52
52
  og_data = {}
53
53
  html.css('meta').each do |m|
@@ -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
@@ -11,7 +11,11 @@ module Onebox
11
11
  end
12
12
 
13
13
  def raw
14
- @raw ||= Onebox::Helpers.fetch_html_doc(url, http_params)
14
+ @raw ||= Onebox::Helpers.fetch_html_doc(url, http_params, body_cacher)
15
+ end
16
+
17
+ def body_cacher
18
+ self.options&.[](:body_cacher)
15
19
  end
16
20
 
17
21
  def html?
@@ -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
@@ -31,7 +31,7 @@ module Onebox
31
31
 
32
32
  def lines
33
33
  return @lines if @lines
34
- response = Onebox::Helpers.fetch_response("http://pastebin.com/raw/#{paste_key}", 1) rescue ""
34
+ response = Onebox::Helpers.fetch_response("http://pastebin.com/raw/#{paste_key}", redirect_limit: 1) rescue ""
35
35
  @lines = response.split("\n")
36
36
  end
37
37
 
@@ -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