onebox 1.9.20 → 1.9.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -24
- data/lib/onebox.rb +5 -2
- data/lib/onebox/engine.rb +4 -11
- data/lib/onebox/engine/google_maps_onebox.rb +1 -1
- data/lib/onebox/engine/image_onebox.rb +0 -1
- data/lib/onebox/engine/reddit_image_onebox.rb +1 -1
- data/lib/onebox/engine/video_onebox.rb +5 -0
- data/lib/onebox/engine/youtube_onebox.rb +1 -1
- data/lib/onebox/layout.rb +2 -6
- data/lib/onebox/layout_support.rb +1 -1
- data/lib/onebox/mixins/git_blob_onebox.rb +6 -6
- data/lib/onebox/preview.rb +1 -3
- data/lib/onebox/version.rb +1 -1
- data/onebox.gemspec +0 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28fed1b823b219fc6c2a79da05780d57b31a267b01d511ddace59e56a74c25f5
|
4
|
+
data.tar.gz: fe64ab418c72f1cc58fd84692cf3033ef68488cea9c4918c575a0fcd016ab443
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efa8c02adf4fdfab9e50ce3a8827eb57184189f5f36beb186495e9978f9c6f33b969c51020485f3a97bd85c09ffb71b0398bec7e9ae853177f5f4a0c1c11ffd6
|
7
|
+
data.tar.gz: 6f5ae220a2523ce9f100e3e83eeea9ad3c2ddfcbc488e1f29cd486017c4fd95df058e15d9ff6d4c3752fc8d546e22ab13e79f8db340841fb19c199ee0300541e
|
data/README.md
CHANGED
@@ -46,30 +46,6 @@ preview = Onebox.preview(url)
|
|
46
46
|
"#{preview}" == preview.to_s #=> true
|
47
47
|
```
|
48
48
|
|
49
|
-
Onebox has its own caching system but you can also provide (or turn off) your own system:
|
50
|
-
|
51
|
-
``` ruby
|
52
|
-
require "onebox"
|
53
|
-
|
54
|
-
url = "http://www.amazon.com/gp/product/B005T3GRNW/ref=s9_simh_gw_p147_d0_i2"
|
55
|
-
preview = Onebox.preview(url, cache: Rails.cache)
|
56
|
-
"#{preview}" == preview.to_s #=> true
|
57
|
-
```
|
58
|
-
|
59
|
-
In addition you can set your own options with this handy interface:
|
60
|
-
|
61
|
-
``` ruby
|
62
|
-
require "onebox"
|
63
|
-
|
64
|
-
Onebox.options = {
|
65
|
-
cache: Rails.cache
|
66
|
-
}
|
67
|
-
|
68
|
-
url = "http://www.amazon.com/gp/product/B005T3GRNW/ref=s9_simh_gw_p147_d0_i2"
|
69
|
-
preview = Onebox.preview(url)
|
70
|
-
"#{preview}" == preview.to_s #=> true
|
71
|
-
```
|
72
|
-
|
73
49
|
Ruby Support
|
74
50
|
------------
|
75
51
|
|
data/lib/onebox.rb
CHANGED
@@ -6,7 +6,6 @@ require "multi_json"
|
|
6
6
|
require "nokogiri"
|
7
7
|
require "mustache"
|
8
8
|
require "ostruct"
|
9
|
-
require "moneta"
|
10
9
|
require "cgi"
|
11
10
|
require "net/http"
|
12
11
|
require "digest"
|
@@ -15,7 +14,6 @@ require_relative "onebox/sanitize_config"
|
|
15
14
|
|
16
15
|
module Onebox
|
17
16
|
DEFAULTS = {
|
18
|
-
cache: Moneta.new(:Memory, expires: true, serializer: :json),
|
19
17
|
connect_timeout: 5,
|
20
18
|
timeout: 10,
|
21
19
|
max_download_kb: (10 * 1024), # 10MB
|
@@ -29,6 +27,11 @@ module Onebox
|
|
29
27
|
@@options = DEFAULTS
|
30
28
|
|
31
29
|
def self.preview(url, options = Onebox.options)
|
30
|
+
# onebox does not have native caching
|
31
|
+
unless Onebox::Helpers.blank?(options[:cache])
|
32
|
+
warn "Onebox no longer has inbuilt caching so `cache` option will be ignored."
|
33
|
+
end
|
34
|
+
|
32
35
|
Preview.new(url, options)
|
33
36
|
end
|
34
37
|
|
data/lib/onebox/engine.rb
CHANGED
@@ -13,7 +13,6 @@ module Onebox
|
|
13
13
|
end
|
14
14
|
|
15
15
|
attr_reader :url, :uri
|
16
|
-
attr_reader :cache
|
17
16
|
attr_reader :timeout
|
18
17
|
|
19
18
|
DEFAULT = {}
|
@@ -28,10 +27,12 @@ module Onebox
|
|
28
27
|
@options
|
29
28
|
end
|
30
29
|
|
31
|
-
def initialize(link,
|
30
|
+
def initialize(link, timeout = nil)
|
32
31
|
@options = DEFAULT
|
33
32
|
class_name = self.class.name.split("::").last.to_s
|
34
|
-
|
33
|
+
|
34
|
+
# Set the engine options extracted from global options.
|
35
|
+
self.options = Onebox.options[class_name] || {}
|
35
36
|
|
36
37
|
@url = link
|
37
38
|
@uri = URI(link)
|
@@ -39,7 +40,6 @@ module Onebox
|
|
39
40
|
@uri.scheme = 'https'
|
40
41
|
@url = @uri.to_s
|
41
42
|
end
|
42
|
-
@cache = cache || Onebox.options.cache
|
43
43
|
@timeout = timeout || Onebox.options.timeout
|
44
44
|
end
|
45
45
|
|
@@ -63,13 +63,6 @@ module Onebox
|
|
63
63
|
|
64
64
|
private
|
65
65
|
|
66
|
-
def record
|
67
|
-
url_result = url
|
68
|
-
result = cache.fetch(url_result) { data }
|
69
|
-
cache[url_result] = result if cache.respond_to?(:key?)
|
70
|
-
result
|
71
|
-
end
|
72
|
-
|
73
66
|
# raises error if not defined in onebox engine
|
74
67
|
# in each onebox, uses either Nokogiri or StandardEmbed to get raw HTML from url
|
75
68
|
def raw
|
@@ -38,7 +38,7 @@ module Onebox
|
|
38
38
|
# Matches URLs for the old Google Maps domain which we occasionally get redirected to
|
39
39
|
matches_regexp :canonical, %r"^(?:https?:)?//maps\.google(?:\.(?:\w{2,}))+/maps\?"
|
40
40
|
|
41
|
-
def initialize(url,
|
41
|
+
def initialize(url, timeout = nil)
|
42
42
|
super
|
43
43
|
resolve_url!
|
44
44
|
rescue Net::HTTPServerException, Timeout::Error, Net::HTTPError, Errno::ECONNREFUSED, RuntimeError => err
|
@@ -26,7 +26,7 @@ module Onebox
|
|
26
26
|
</aside>
|
27
27
|
HTML
|
28
28
|
else
|
29
|
-
html = Onebox::Engine::WhitelistedGenericOnebox.new(@url, @
|
29
|
+
html = Onebox::Engine::WhitelistedGenericOnebox.new(@url, @timeout).to_html
|
30
30
|
return if Onebox::Helpers.blank?(html)
|
31
31
|
html
|
32
32
|
end
|
@@ -12,6 +12,11 @@ module Onebox
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def to_html
|
15
|
+
# Fix Dropbox image links
|
16
|
+
if @url[/^https:\/\/www.dropbox.com\/s\//]
|
17
|
+
@url.sub!("https://www.dropbox.com", "https://dl.dropboxusercontent.com")
|
18
|
+
end
|
19
|
+
|
15
20
|
escaped_url = ::Onebox::Helpers.normalize_url_for_output(@url)
|
16
21
|
<<-HTML
|
17
22
|
<div class="onebox video-onebox">
|
@@ -45,7 +45,7 @@ module Onebox
|
|
45
45
|
HTML
|
46
46
|
else
|
47
47
|
# for channel pages
|
48
|
-
html = Onebox::Engine::WhitelistedGenericOnebox.new(@url, @
|
48
|
+
html = Onebox::Engine::WhitelistedGenericOnebox.new(@url, @timeout).to_html
|
49
49
|
return if Onebox::Helpers.blank?(html)
|
50
50
|
html.gsub!(/['"]\/\//, "https://")
|
51
51
|
html
|
data/lib/onebox/layout.rb
CHANGED
@@ -8,12 +8,10 @@ module Onebox
|
|
8
8
|
|
9
9
|
VERSION = "1.0.0"
|
10
10
|
|
11
|
-
attr_reader :cache
|
12
11
|
attr_reader :record
|
13
12
|
attr_reader :view
|
14
13
|
|
15
|
-
def initialize(name, record
|
16
|
-
@cache = cache
|
14
|
+
def initialize(name, record)
|
17
15
|
@record = Onebox::Helpers.symbolize_keys(record)
|
18
16
|
|
19
17
|
# Fix any relative paths
|
@@ -28,9 +26,7 @@ module Onebox
|
|
28
26
|
end
|
29
27
|
|
30
28
|
def to_html
|
31
|
-
|
32
|
-
cache[checksum] = result if cache.respond_to?(:key?)
|
33
|
-
result
|
29
|
+
render(details)
|
34
30
|
end
|
35
31
|
|
36
32
|
private
|
@@ -25,9 +25,9 @@ module Onebox
|
|
25
25
|
}
|
26
26
|
|
27
27
|
module InstanceMethods
|
28
|
-
def initialize(link,
|
29
|
-
super link,
|
30
|
-
#merge engine options from global Onebox.options interface
|
28
|
+
def initialize(link, timeout = nil)
|
29
|
+
super link, timeout
|
30
|
+
# merge engine options from global Onebox.options interface
|
31
31
|
# self.options = Onebox.options["GithubBlobOnebox"] # self.class.name.split("::").last.to_s
|
32
32
|
# self.options = Onebox.options[self.class.name.split("::").last.to_s] #We can use this a more generic approach. extract the engine class name automatically
|
33
33
|
|
@@ -174,9 +174,9 @@ module Onebox
|
|
174
174
|
|
175
175
|
cr = calc_range(m, contents_lines_size) #calculate the range of lines for output
|
176
176
|
selected_one_liner = cr[:selected_one_liner] #if url is a one-liner calc_range will return it
|
177
|
-
from
|
178
|
-
to
|
179
|
-
@truncated
|
177
|
+
from = cr[:from]
|
178
|
+
to = cr[:to]
|
179
|
+
@truncated = cr[:truncated]
|
180
180
|
range_provided = cr[:range_provided]
|
181
181
|
@cr_results = cr
|
182
182
|
|
data/lib/onebox/preview.rb
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
module Onebox
|
4
4
|
class Preview
|
5
|
-
attr_reader :cache
|
6
5
|
|
7
6
|
# see https://bugs.ruby-lang.org/issues/14688
|
8
7
|
client_exception = defined?(Net::HTTPClientException) ? Net::HTTPClientException : Net::HTTPServerException
|
@@ -11,7 +10,6 @@ module Onebox
|
|
11
10
|
def initialize(link, parameters = Onebox.options)
|
12
11
|
@url = link
|
13
12
|
@options = parameters
|
14
|
-
@cache = options.cache
|
15
13
|
@engine_class = Matcher.new(@url).oneboxed
|
16
14
|
end
|
17
15
|
|
@@ -72,7 +70,7 @@ module Onebox
|
|
72
70
|
return nil unless @engine_class
|
73
71
|
return @engine if @engine
|
74
72
|
|
75
|
-
@engine = @engine_class.new(@url
|
73
|
+
@engine = @engine_class.new(@url)
|
76
74
|
@engine.options = @options
|
77
75
|
@engine
|
78
76
|
end
|
data/lib/onebox/version.rb
CHANGED
data/onebox.gemspec
CHANGED
@@ -23,7 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_runtime_dependency 'multi_json', '~> 1.11'
|
24
24
|
spec.add_runtime_dependency 'mustache'
|
25
25
|
spec.add_runtime_dependency 'nokogiri', '~> 1.7'
|
26
|
-
spec.add_runtime_dependency 'moneta', '~> 1.0'
|
27
26
|
spec.add_runtime_dependency 'htmlentities', '~> 4.3'
|
28
27
|
spec.add_runtime_dependency 'sanitize'
|
29
28
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onebox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.9.
|
4
|
+
version: 1.9.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joanna Zeta
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2019-
|
13
|
+
date: 2019-11-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: multi_json
|
@@ -54,20 +54,6 @@ dependencies:
|
|
54
54
|
- - "~>"
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: '1.7'
|
57
|
-
- !ruby/object:Gem::Dependency
|
58
|
-
name: moneta
|
59
|
-
requirement: !ruby/object:Gem::Requirement
|
60
|
-
requirements:
|
61
|
-
- - "~>"
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
version: '1.0'
|
64
|
-
type: :runtime
|
65
|
-
prerelease: false
|
66
|
-
version_requirements: !ruby/object:Gem::Requirement
|
67
|
-
requirements:
|
68
|
-
- - "~>"
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
version: '1.0'
|
71
57
|
- !ruby/object:Gem::Dependency
|
72
58
|
name: htmlentities
|
73
59
|
requirement: !ruby/object:Gem::Requirement
|