onebox 1.8.68 → 1.8.69
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.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +1 -112
- data/README.md +0 -1
- data/lib/onebox/engine/asciinema_onebox.rb +3 -3
- data/lib/onebox/engine/cloudapp_onebox.rb +14 -14
- data/lib/onebox/engine/douban_onebox.rb +8 -8
- data/lib/onebox/engine/gfycat_onebox.rb +21 -21
- data/lib/onebox/engine/google_photos_onebox.rb +21 -21
- data/lib/onebox/engine/imgur_onebox.rb +26 -26
- data/lib/onebox/engine/soundcloud_onebox.rb +9 -9
- data/lib/onebox/engine/standard_embed.rb +50 -50
- data/lib/onebox/engine/trello_onebox.rb +5 -5
- data/lib/onebox/engine/whitelisted_generic_onebox.rb +66 -66
- data/lib/onebox/engine/wikimedia_onebox.rb +14 -14
- data/lib/onebox/engine/wistia_onebox.rb +8 -8
- data/lib/onebox/engine/xkcd_onebox.rb +11 -11
- data/lib/onebox/engine/youtube_onebox.rb +78 -78
- data/lib/onebox/file_type_finder.rb +19 -19
- data/lib/onebox/helpers.rb +3 -3
- data/lib/onebox/layout.rb +28 -28
- data/lib/onebox/mixins/git_blob_onebox.rb +1 -1
- data/lib/onebox/preview.rb +31 -31
- data/lib/onebox/sanitize_config.rb +9 -7
- data/lib/onebox/version.rb +1 -1
- data/templates/twitterstatus.mustache +10 -2
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 98a0701ca393ddadda7d9d38abcd9d99b2d9fbdfec7a18643b106adfddf45ad7
|
|
4
|
+
data.tar.gz: 699090849c9ac55d0362b3785f8d4a447c509bd7a47cc4d2ee6ae79ee0f869db
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3f474fc31092624d6d00062167334fcf2a61fb85b2da6075d73ed74ef34ffbc9561fd74d1d2b467410cec9c72c16f1fad863320646980422da544c40c2c16b67
|
|
7
|
+
data.tar.gz: 204da8eaac3fa2fef4fdbb39b0b470807eba0c2fa969bcd4d9168739e07fc5ff2e5d9c868632621ff7bdd879c9a0c6d3adeeb2af935e2d996aff4e137723386c
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
|
@@ -1,112 +1 @@
|
|
|
1
|
-
|
|
2
|
-
TargetRubyVersion: 2.3
|
|
3
|
-
DisabledByDefault: true
|
|
4
|
-
Include:
|
|
5
|
-
- 'onebox.gemspec'
|
|
6
|
-
- 'Rakefile'
|
|
7
|
-
Exclude:
|
|
8
|
-
- 'vendor/**/*'
|
|
9
|
-
|
|
10
|
-
# Prefer &&/|| over and/or.
|
|
11
|
-
Style/AndOr:
|
|
12
|
-
Enabled: true
|
|
13
|
-
|
|
14
|
-
# Do not use braces for hash literals when they are the last argument of a
|
|
15
|
-
# method call.
|
|
16
|
-
Style/BracesAroundHashParameters:
|
|
17
|
-
Enabled: true
|
|
18
|
-
|
|
19
|
-
# Align `when` with `case`.
|
|
20
|
-
Layout/CaseIndentation:
|
|
21
|
-
Enabled: true
|
|
22
|
-
|
|
23
|
-
# Align comments with method definitions.
|
|
24
|
-
Layout/CommentIndentation:
|
|
25
|
-
Enabled: true
|
|
26
|
-
|
|
27
|
-
# No extra empty lines.
|
|
28
|
-
Layout/EmptyLines:
|
|
29
|
-
Enabled: true
|
|
30
|
-
|
|
31
|
-
# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
|
|
32
|
-
Style/HashSyntax:
|
|
33
|
-
Enabled: true
|
|
34
|
-
|
|
35
|
-
# Two spaces, no tabs (for indentation).
|
|
36
|
-
Layout/IndentationWidth:
|
|
37
|
-
Enabled: true
|
|
38
|
-
|
|
39
|
-
Layout/SpaceAfterColon:
|
|
40
|
-
Enabled: true
|
|
41
|
-
|
|
42
|
-
Layout/SpaceAfterComma:
|
|
43
|
-
Enabled: true
|
|
44
|
-
|
|
45
|
-
Layout/SpaceAroundEqualsInParameterDefault:
|
|
46
|
-
Enabled: true
|
|
47
|
-
|
|
48
|
-
Layout/SpaceAroundKeyword:
|
|
49
|
-
Enabled: true
|
|
50
|
-
|
|
51
|
-
Layout/SpaceAroundOperators:
|
|
52
|
-
Enabled: true
|
|
53
|
-
|
|
54
|
-
Layout/SpaceBeforeFirstArg:
|
|
55
|
-
Enabled: true
|
|
56
|
-
|
|
57
|
-
# Defining a method with parameters needs parentheses.
|
|
58
|
-
Style/MethodDefParentheses:
|
|
59
|
-
Enabled: true
|
|
60
|
-
|
|
61
|
-
# Use `foo {}` not `foo{}`.
|
|
62
|
-
Layout/SpaceBeforeBlockBraces:
|
|
63
|
-
Enabled: true
|
|
64
|
-
|
|
65
|
-
# Use `foo { bar }` not `foo {bar}`.
|
|
66
|
-
Layout/SpaceInsideBlockBraces:
|
|
67
|
-
Enabled: true
|
|
68
|
-
|
|
69
|
-
# Use `{ a: 1 }` not `{a:1}`.
|
|
70
|
-
Layout/SpaceInsideHashLiteralBraces:
|
|
71
|
-
Enabled: true
|
|
72
|
-
|
|
73
|
-
Layout/SpaceInsideParens:
|
|
74
|
-
Enabled: true
|
|
75
|
-
|
|
76
|
-
# Detect hard tabs, no hard tabs.
|
|
77
|
-
Layout/Tab:
|
|
78
|
-
Enabled: true
|
|
79
|
-
|
|
80
|
-
# Blank lines should not have any spaces.
|
|
81
|
-
Layout/TrailingBlankLines:
|
|
82
|
-
Enabled: true
|
|
83
|
-
|
|
84
|
-
# No trailing whitespace.
|
|
85
|
-
Layout/TrailingWhitespace:
|
|
86
|
-
Enabled: true
|
|
87
|
-
|
|
88
|
-
Lint/Debugger:
|
|
89
|
-
Enabled: true
|
|
90
|
-
|
|
91
|
-
Lint/BlockAlignment:
|
|
92
|
-
Enabled: true
|
|
93
|
-
|
|
94
|
-
# Align `end` with the matching keyword or starting expression except for
|
|
95
|
-
# assignments, where it should be aligned with the LHS.
|
|
96
|
-
Lint/EndAlignment:
|
|
97
|
-
Enabled: true
|
|
98
|
-
EnforcedStyleAlignWith: variable
|
|
99
|
-
|
|
100
|
-
# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
|
|
101
|
-
Lint/RequireParentheses:
|
|
102
|
-
Enabled: true
|
|
103
|
-
|
|
104
|
-
Layout/MultilineMethodCallIndentation:
|
|
105
|
-
Enabled: true
|
|
106
|
-
EnforcedStyle: indented
|
|
107
|
-
|
|
108
|
-
Layout/AlignHash:
|
|
109
|
-
Enabled: true
|
|
110
|
-
|
|
111
|
-
Bundler/OrderedGems:
|
|
112
|
-
Enabled: false
|
|
1
|
+
inherit_from: https://raw.githubusercontent.com/discourse/discourse/master/.rubocop.yml
|
data/README.md
CHANGED
|
@@ -4,7 +4,6 @@ onebox
|
|
|
4
4
|
[](https://rubygems.org/gems/onebox)
|
|
5
5
|
[](https://codeclimate.com/github/dysania/onebox)
|
|
6
6
|
[](https://travis-ci.org/discourse/onebox)
|
|
7
|
-
[](https://gemnasium.com/discourse/onebox)
|
|
8
7
|
|
|
9
8
|
Onebox is a library for turning media URLs into simple HTML previews of the resource.
|
|
10
9
|
|
|
@@ -18,9 +18,9 @@ module Onebox
|
|
|
18
18
|
|
|
19
19
|
private
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
def match
|
|
22
|
+
@match ||= @url.match(/asciinema\.org\/a\/(?<asciinema_id>[\p{Alnum}_\-]+)$/)
|
|
23
|
+
end
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
end
|
|
@@ -21,37 +21,37 @@ module Onebox
|
|
|
21
21
|
|
|
22
22
|
private
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
def link_html(og)
|
|
25
|
+
escaped_url = ::Onebox::Helpers.normalize_url_for_output(og[:url])
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
<<-HTML
|
|
28
28
|
<a href='#{escaped_url}' target='_blank'>
|
|
29
29
|
#{og[:title]}
|
|
30
30
|
</a>
|
|
31
31
|
HTML
|
|
32
|
-
|
|
32
|
+
end
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
def video_html(og)
|
|
35
|
+
src = og[:url]
|
|
36
|
+
title = og[:title]
|
|
37
|
+
direct_src = ::Onebox::Helpers.normalize_url_for_output("#{src}/#{title}")
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
<<-HTML
|
|
40
40
|
<video width='480' height='360' #{Helpers.title_attr(og)} controls loop>
|
|
41
41
|
<source src='#{direct_src}' type='video/mp4'>
|
|
42
42
|
</video>
|
|
43
43
|
HTML
|
|
44
|
-
|
|
44
|
+
end
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
def image_html(og)
|
|
47
|
+
escaped_url = ::Onebox::Helpers.normalize_url_for_output(og[:url])
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
<<-HTML
|
|
50
50
|
<a href='#{escaped_url}' target='_blank' class='onebox'>
|
|
51
51
|
<img src='#{og[:image]}' #{Helpers.title_attr(og)} alt='CloudApp' width='480'>
|
|
52
52
|
</a>
|
|
53
53
|
HTML
|
|
54
|
-
|
|
54
|
+
end
|
|
55
55
|
end
|
|
56
56
|
end
|
|
57
57
|
end
|
|
@@ -9,14 +9,14 @@ module Onebox
|
|
|
9
9
|
|
|
10
10
|
private
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
def data
|
|
13
|
+
{
|
|
14
|
+
link: link,
|
|
15
|
+
title: raw.css('title').text.gsub("\n", '').strip(),
|
|
16
|
+
image: raw.css('img[rel*="v:"]').first['src'],
|
|
17
|
+
description: raw.css('meta[name=description]').first['content'],
|
|
18
|
+
}
|
|
19
|
+
end
|
|
20
20
|
|
|
21
21
|
end
|
|
22
22
|
end
|
|
@@ -58,30 +58,30 @@ module Onebox
|
|
|
58
58
|
|
|
59
59
|
private
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
def match
|
|
62
|
+
@match ||= @url.match(/^https?:\/\/gfycat\.com\/(gifs\/detail\/)?(?<name>.+)/)
|
|
63
|
+
end
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
def data
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
total_tags = [raw['gfyItem']['tags'], raw['gfyItem']['userTags']].flatten.compact
|
|
68
|
+
tag_links = total_tags.map { |t| "<a href='https://gfycat.com/gifs/search/#{t}'>##{t}</a>" }.join(' ') if total_tags
|
|
69
|
+
autoplay = raw['gfyItem']['webmSize'].to_i < 10485760 ? 'autoplay' : ''
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
71
|
+
{
|
|
72
|
+
name: raw['gfyItem']['gfyName'],
|
|
73
|
+
title: raw['gfyItem']['title'] || 'No Title',
|
|
74
|
+
author: raw['gfyItem']['userName'],
|
|
75
|
+
tags: tag_links,
|
|
76
|
+
url: @url,
|
|
77
|
+
posterUrl: raw['gfyItem']['posterUrl'],
|
|
78
|
+
webmUrl: raw['gfyItem']['webmUrl'],
|
|
79
|
+
mp4Url: raw['gfyItem']['mp4Url'],
|
|
80
|
+
width: raw['gfyItem']['width'],
|
|
81
|
+
height: raw['gfyItem']['height'],
|
|
82
|
+
autoplay: autoplay
|
|
83
|
+
}
|
|
84
|
+
end
|
|
85
85
|
|
|
86
86
|
end
|
|
87
87
|
end
|
|
@@ -17,23 +17,23 @@ module Onebox
|
|
|
17
17
|
|
|
18
18
|
private
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
def video_html(og)
|
|
21
|
+
escaped_src = ::Onebox::Helpers.normalize_url_for_output(og[:video_secure_url])
|
|
22
|
+
escaped_image_src = ::Onebox::Helpers.normalize_url_for_output(get_secure_link(og[:image]))
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
<<-HTML
|
|
25
25
|
<video width='#{og[:video_width]}' height='#{og[:video_height]}' #{Helpers.title_attr(og)} poster="#{escaped_image_src}" controls loop>
|
|
26
26
|
<source src='#{escaped_src}' type='video/mp4'>
|
|
27
27
|
</video>
|
|
28
28
|
HTML
|
|
29
|
-
|
|
29
|
+
end
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
def album_html(og)
|
|
32
|
+
escaped_url = ::Onebox::Helpers.normalize_url_for_output(url)
|
|
33
|
+
escaped_src = ::Onebox::Helpers.normalize_url_for_output(get_secure_link(og[:image]))
|
|
34
|
+
album_title = Onebox::Helpers::blank?(og[:description]) ? og[:title].strip : "[#{og[:description].strip}] #{og[:title].strip}"
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
<<-HTML
|
|
37
37
|
<div class='onebox google-photos-album'>
|
|
38
38
|
<a href='#{escaped_url}' target='_blank'>
|
|
39
39
|
<span class='outer-box' style='width:#{og[:image_width]}px'>
|
|
@@ -45,24 +45,24 @@ module Onebox
|
|
|
45
45
|
</a>
|
|
46
46
|
</div>
|
|
47
47
|
HTML
|
|
48
|
-
|
|
48
|
+
end
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
def image_html(og)
|
|
51
|
+
escaped_url = ::Onebox::Helpers.normalize_url_for_output(url)
|
|
52
|
+
escaped_src = ::Onebox::Helpers.normalize_url_for_output(get_secure_link(og[:image]))
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
<<-HTML
|
|
55
55
|
<a href='#{escaped_url}' target='_blank' class="onebox">
|
|
56
56
|
<img src='#{escaped_src}' #{Helpers.title_attr(og)} alt='Google Photos' height='#{og[:image_height]}' width='#{og[:image_width]}'>
|
|
57
57
|
</a>
|
|
58
58
|
HTML
|
|
59
|
-
|
|
59
|
+
end
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
def get_secure_link(link)
|
|
62
|
+
secure_link = URI(link)
|
|
63
|
+
secure_link.scheme = 'https'
|
|
64
|
+
secure_link.to_s
|
|
65
|
+
end
|
|
66
66
|
end
|
|
67
67
|
end
|
|
68
68
|
end
|
|
@@ -17,23 +17,23 @@ module Onebox
|
|
|
17
17
|
|
|
18
18
|
private
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
def video_html(og)
|
|
21
|
+
escaped_src = ::Onebox::Helpers.normalize_url_for_output(og[:video_secure_url])
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
<<-HTML
|
|
24
24
|
<video width='#{og[:video_width]}' height='#{og[:video_height]}' #{Helpers.title_attr(og)} controls loop>
|
|
25
25
|
<source src='#{escaped_src}' type='video/mp4'>
|
|
26
26
|
<source src='#{escaped_src.gsub('mp4', 'webm')}' type='video/webm'>
|
|
27
27
|
</video>
|
|
28
28
|
HTML
|
|
29
|
-
|
|
29
|
+
end
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
def album_html(og)
|
|
32
|
+
escaped_url = ::Onebox::Helpers.normalize_url_for_output(url)
|
|
33
|
+
escaped_src = ::Onebox::Helpers.normalize_url_for_output(get_secure_link(og[:image]))
|
|
34
|
+
album_title = "[Album] #{Onebox::Helpers.truncate(og[:title].strip, 80)}"
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
<<-HTML
|
|
37
37
|
<div class='onebox imgur-album'>
|
|
38
38
|
<a href='#{escaped_url}' target='_blank'>
|
|
39
39
|
<span class='outer-box' style='width:#{og[:image_width]}px'>
|
|
@@ -45,31 +45,31 @@ module Onebox
|
|
|
45
45
|
</a>
|
|
46
46
|
</div>
|
|
47
47
|
HTML
|
|
48
|
-
|
|
48
|
+
end
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
def is_album?
|
|
51
|
+
response = Onebox::Helpers.fetch_response("https://api.imgur.com/oembed.json?url=#{url}") rescue "{}"
|
|
52
|
+
oembed_data = Onebox::Helpers.symbolize_keys(::MultiJson.load(response))
|
|
53
|
+
imgur_data_id = Nokogiri::HTML(oembed_data[:html]).xpath("//blockquote").attr("data-id")
|
|
54
|
+
imgur_data_id.to_s[/a\//]
|
|
55
|
+
end
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
def image_html(og)
|
|
58
|
+
escaped_url = ::Onebox::Helpers.normalize_url_for_output(url)
|
|
59
|
+
escaped_src = ::Onebox::Helpers.normalize_url_for_output(get_secure_link(og[:image]))
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
<<-HTML
|
|
62
62
|
<a href='#{escaped_url}' target='_blank' class="onebox">
|
|
63
63
|
<img src='#{escaped_src}' #{Helpers.title_attr(og)} alt='Imgur' height='#{og[:image_height]}' width='#{og[:image_width]}'>
|
|
64
64
|
</a>
|
|
65
65
|
HTML
|
|
66
|
-
|
|
66
|
+
end
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
def get_secure_link(link)
|
|
69
|
+
secure_link = URI(link)
|
|
70
|
+
secure_link.scheme = 'https'
|
|
71
|
+
secure_link.to_s
|
|
72
|
+
end
|
|
73
73
|
|
|
74
74
|
end
|
|
75
75
|
end
|
|
@@ -19,16 +19,16 @@ module Onebox
|
|
|
19
19
|
|
|
20
20
|
private
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
end
|
|
22
|
+
def oembed_data
|
|
23
|
+
@oembed_data ||= begin
|
|
24
|
+
oembed_url = "https://soundcloud.com/oembed.json?url=#{url}"
|
|
25
|
+
oembed_url << "&maxheight=166" unless url["/sets/"]
|
|
26
|
+
response = Onebox::Helpers.fetch_response(oembed_url) rescue "{}"
|
|
27
|
+
Onebox::Helpers.symbolize_keys(::MultiJson.load(response))
|
|
28
|
+
rescue
|
|
29
|
+
{}
|
|
31
30
|
end
|
|
31
|
+
end
|
|
32
32
|
|
|
33
33
|
end
|
|
34
34
|
end
|