onebox 1.8.4 → 1.8.5
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/README.md +65 -65
- data/lib/onebox/engine.rb +1 -0
- data/lib/onebox/engine/flickr_onebox.rb +3 -7
- data/lib/onebox/engine/flickr_shortened_onebox.rb +14 -0
- data/lib/onebox/engine/giphy_onebox.rb +1 -2
- data/lib/onebox/engine/opengraph_image.rb +13 -0
- data/lib/onebox/engine/steam_store_onebox.rb +1 -1
- data/lib/onebox/engine/twitter_status_onebox.rb +1 -1
- data/lib/onebox/engine/whitelisted_generic_onebox.rb +3 -1
- data/lib/onebox/engine/xkcd_onebox.rb +1 -1
- data/lib/onebox/sanitize_config.rb +26 -4
- data/lib/onebox/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e6396e2c853cabff86cb24b13b78d1bc5593b63
|
4
|
+
data.tar.gz: 13b5abf77b2af2c082c89136c9244759193fbd7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd3d129640983ed1d96e8b769c24e0575d66810ef01713e5c22f84ffbd70d0370162e789652a876f769c12c73e9fdfcd9c035ee9467bc4083125f38ce4b72cb0
|
7
|
+
data.tar.gz: af3d5855ef0b77552f5c9b964dead3610872a509a9c72f3441b87d442268bcbf567dd226a61b837aaf5204ea68464fd12129010dcf79b6b3884f9df8d2d330a3
|
data/README.md
CHANGED
@@ -76,7 +76,7 @@ Development Preview Interface
|
|
76
76
|
=============================
|
77
77
|
|
78
78
|
The onebox gem comes with a development server for previewing the results
|
79
|
-
of your changes. You can run it by running `rake server` after checking
|
79
|
+
of your changes. You can run it by running `bundle exec rake server` after checking
|
80
80
|
out the project. You can then try out URLs.
|
81
81
|
|
82
82
|
The server doesn't reload code changes automatically (PRs accepted!) so
|
@@ -92,88 +92,88 @@ Adding Support for a new URL
|
|
92
92
|
|
93
93
|
2. Create new onebox engine
|
94
94
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
95
|
+
``` ruby
|
96
|
+
# in lib/onebox/engine/name_onebox.rb
|
97
|
+
|
98
|
+
module Onebox
|
99
|
+
module Engine
|
100
|
+
class NameOnebox
|
101
|
+
include LayoutSupport
|
102
|
+
include HTML
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
def data
|
107
|
+
{
|
108
|
+
url: @url,
|
109
|
+
name: raw.css("h1").inner_text,
|
110
|
+
image: raw.css("#main-image").first["src"],
|
111
|
+
description: raw.css("#postBodyPS").inner_text
|
112
|
+
}
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
```
|
118
118
|
|
119
119
|
3. Create new onebox spec using [FakeWeb](https://github.com/chrisk/fakeweb)
|
120
120
|
|
121
|
-
|
122
|
-
|
123
|
-
|
121
|
+
``` ruby
|
122
|
+
# in spec/lib/onebox/engine/name_spec.rb
|
123
|
+
require "spec_helper"
|
124
124
|
|
125
|
-
|
126
|
-
|
127
|
-
|
125
|
+
describe Onebox::Engine::NameOnebox do
|
126
|
+
let(:link) { "http://example.com" }
|
127
|
+
let(:html) { described_class.new(link).to_html }
|
128
128
|
|
129
|
-
|
130
|
-
|
131
|
-
|
129
|
+
before do
|
130
|
+
fake(link, response("name.response"))
|
131
|
+
end
|
132
132
|
|
133
|
-
|
134
|
-
|
135
|
-
|
133
|
+
it "has the video's title" do
|
134
|
+
expect(html).to include("title")
|
135
|
+
end
|
136
136
|
|
137
|
-
|
138
|
-
|
139
|
-
|
137
|
+
it "has the video's still shot" do
|
138
|
+
expect(html).to include("photo.jpg")
|
139
|
+
end
|
140
140
|
|
141
|
-
|
142
|
-
|
143
|
-
|
141
|
+
it "has the video's description" do
|
142
|
+
expect(html).to include("description")
|
143
|
+
end
|
144
144
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
145
|
+
it "has the URL to the resource" do
|
146
|
+
expect(html).to include(link)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
```
|
150
150
|
|
151
151
|
4. Create new mustache template
|
152
152
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
153
|
+
``` html
|
154
|
+
# in templates/name.mustache
|
155
|
+
<div class="onebox">
|
156
|
+
<a href="{{url}}">
|
157
|
+
<h1>{{name}}</h1>
|
158
|
+
<h2 class="host">example.com</h2>
|
159
|
+
<img src="{{image}}" />
|
160
|
+
<p>{{description}}</p>
|
161
|
+
</a>
|
162
|
+
</div>
|
163
|
+
```
|
164
164
|
|
165
165
|
5. Create new fixture from HTML response for your FakeWeb request(s)
|
166
166
|
|
167
|
-
|
168
|
-
|
169
|
-
|
167
|
+
``` bash
|
168
|
+
curl --output spec/fixtures/oneboxname.response -L -X -GET http://example.com
|
169
|
+
```
|
170
170
|
|
171
171
|
6. Require in Engine module
|
172
172
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
173
|
+
``` ruby
|
174
|
+
# in lib/onebox/engine.rb
|
175
|
+
require_relative "engine/name_onebox"
|
176
|
+
```
|
177
177
|
|
178
178
|
|
179
179
|
Whitelisted Generic Onebox caveats
|
data/lib/onebox/engine.rb
CHANGED
@@ -174,5 +174,6 @@ require_relative "engine/mixcloud_onebox"
|
|
174
174
|
require_relative "engine/bandcamp_onebox"
|
175
175
|
require_relative "engine/coub_onebox"
|
176
176
|
require_relative "engine/flickr_onebox"
|
177
|
+
require_relative "engine/flickr_shortened_onebox"
|
177
178
|
require_relative "engine/five_hundred_px_onebox"
|
178
179
|
require_relative "engine/pdf_onebox"
|
@@ -1,18 +1,14 @@
|
|
1
|
+
require_relative './opengraph_image'
|
2
|
+
|
1
3
|
module Onebox
|
2
4
|
module Engine
|
3
5
|
class FlickrOnebox
|
4
6
|
include Engine
|
5
7
|
include StandardEmbed
|
8
|
+
include OpengraphImage
|
6
9
|
|
7
10
|
matches_regexp(/^https?:\/\/www\.flickr\.com\/photos\//)
|
8
11
|
always_https
|
9
|
-
|
10
|
-
def to_html
|
11
|
-
og = get_opengraph
|
12
|
-
escaped_src = ::Onebox::Helpers.normalize_url_for_output(og[:image])
|
13
|
-
"<img src='#{escaped_src}' width='#{og[:image_width]}' height='#{og[:image_height]}' #{Helpers.title_attr(og)}>"
|
14
|
-
end
|
15
|
-
|
16
12
|
end
|
17
13
|
end
|
18
14
|
end
|
@@ -10,11 +10,10 @@ module Onebox
|
|
10
10
|
def to_html
|
11
11
|
oembed = get_oembed
|
12
12
|
escaped_url = ::Onebox::Helpers.normalize_url_for_output(oembed[:url])
|
13
|
-
escaped_src = ::Onebox::Helpers.normalize_url_for_output(oembed[:image])
|
14
13
|
|
15
14
|
<<-HTML
|
16
15
|
<a href="#{escaped_url}" target="_blank">
|
17
|
-
<img src="#{
|
16
|
+
<img src="#{escaped_url}" width="#{oembed[:width]}" height="#{oembed[:height]}" #{Helpers.title_attr(oembed)}>
|
18
17
|
</a>
|
19
18
|
HTML
|
20
19
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
module OpengraphImage
|
4
|
+
|
5
|
+
def to_html
|
6
|
+
og = get_opengraph
|
7
|
+
escaped_src = ::Onebox::Helpers.normalize_url_for_output(og[:image])
|
8
|
+
"<img src='#{escaped_src}' width='#{og[:image_width]}' height='#{og[:image_height]}' #{Helpers.title_attr(og)}>"
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -22,7 +22,7 @@ module Onebox
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def to_html
|
25
|
-
iframe_url = @url.gsub(
|
25
|
+
iframe_url = @url[/https?:\/\/store\.steampowered\.com\/app\/\d+/].gsub("/app/", "/widget/")
|
26
26
|
escaped_src = ::Onebox::Helpers.normalize_url_for_output(iframe_url)
|
27
27
|
|
28
28
|
<<-HTML
|
@@ -5,7 +5,7 @@ module Onebox
|
|
5
5
|
include LayoutSupport
|
6
6
|
include HTML
|
7
7
|
|
8
|
-
matches_regexp /^https?:\/\/(mobile\.|www\.)?twitter\.com\/.+?\/status(es)?\/\d
|
8
|
+
matches_regexp /^https?:\/\/(mobile\.|www\.)?twitter\.com\/.+?\/status(es)?\/\d+(\/(video|photo)\/\d?+)?+\/?$/
|
9
9
|
always_https
|
10
10
|
|
11
11
|
private
|
@@ -56,11 +56,12 @@ module Onebox
|
|
56
56
|
espn.go.com
|
57
57
|
etsy.com
|
58
58
|
findery.com
|
59
|
-
flickr.com
|
60
59
|
folksy.com
|
61
60
|
forbes.com
|
62
61
|
foxnews.com
|
63
62
|
funnyordie.com
|
63
|
+
gfycat.com
|
64
|
+
gifs.com
|
64
65
|
groupon.com
|
65
66
|
howtogeek.com
|
66
67
|
huffingtonpost.ca
|
@@ -102,6 +103,7 @@ module Onebox
|
|
102
103
|
speakerdeck.com
|
103
104
|
spotify.com
|
104
105
|
squidoo.com
|
106
|
+
streamable.com
|
105
107
|
techcrunch.com
|
106
108
|
ted.com
|
107
109
|
thefreedictionary.com
|
@@ -6,20 +6,42 @@ class Sanitize
|
|
6
6
|
ONEBOX ||= freeze_config merge(RELAXED,
|
7
7
|
elements: RELAXED[:elements] + %w[audio embed iframe source video],
|
8
8
|
|
9
|
-
attributes:
|
9
|
+
attributes: {
|
10
|
+
'a' => RELAXED[:attributes]['a'] + %w(target),
|
10
11
|
'audio' => %w[controls],
|
11
12
|
'embed' => %w[height src type width],
|
12
13
|
'iframe' => %w[allowfullscreen frameborder height scrolling src width],
|
13
14
|
'source' => %w[src type],
|
14
15
|
'video' => %w[controls height loop width],
|
15
16
|
'div' => [:data], # any data-* attributes
|
16
|
-
|
17
|
+
},
|
17
18
|
|
18
|
-
|
19
|
+
add_attributes: {
|
20
|
+
'iframe' => {
|
21
|
+
'seamless' => 'seamless',
|
22
|
+
'sandbox' => 'allow-same-origin allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox',
|
23
|
+
}
|
24
|
+
},
|
25
|
+
|
26
|
+
transformers: (RELAXED[:transformers] || []) + [
|
27
|
+
lambda do |env|
|
28
|
+
next unless env[:node_name] == 'a'
|
29
|
+
a_tag = env[:node]
|
30
|
+
a_tag['href'] ||= '#'
|
31
|
+
if a_tag['href'] =~ %r{^(?:[a-z]+:)?//}
|
32
|
+
a_tag['target'] = '_blank'
|
33
|
+
a_tag['rel'] = 'nofollow noopener'
|
34
|
+
else
|
35
|
+
a_tag.remove_attribute('target')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
],
|
39
|
+
|
40
|
+
protocols: {
|
19
41
|
'embed' => { 'src' => HTTP_PROTOCOLS },
|
20
42
|
'iframe' => { 'src' => HTTP_PROTOCOLS },
|
21
43
|
'source' => { 'src' => HTTP_PROTOCOLS },
|
22
|
-
|
44
|
+
},
|
23
45
|
)
|
24
46
|
end
|
25
47
|
end
|
data/lib/onebox/version.rb
CHANGED
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.8.
|
4
|
+
version: 1.8.5
|
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: 2017-
|
13
|
+
date: 2017-05-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: multi_json
|
@@ -337,6 +337,7 @@ files:
|
|
337
337
|
- lib/onebox/engine/douban_onebox.rb
|
338
338
|
- lib/onebox/engine/five_hundred_px_onebox.rb
|
339
339
|
- lib/onebox/engine/flickr_onebox.rb
|
340
|
+
- lib/onebox/engine/flickr_shortened_onebox.rb
|
340
341
|
- lib/onebox/engine/gfycat_onebox.rb
|
341
342
|
- lib/onebox/engine/giphy_onebox.rb
|
342
343
|
- lib/onebox/engine/github_blob_onebox.rb
|
@@ -353,6 +354,7 @@ files:
|
|
353
354
|
- lib/onebox/engine/imgur_onebox.rb
|
354
355
|
- lib/onebox/engine/json.rb
|
355
356
|
- lib/onebox/engine/mixcloud_onebox.rb
|
357
|
+
- lib/onebox/engine/opengraph_image.rb
|
356
358
|
- lib/onebox/engine/pastebin_onebox.rb
|
357
359
|
- lib/onebox/engine/pdf_onebox.rb
|
358
360
|
- lib/onebox/engine/pubmed_onebox.rb
|
@@ -498,7 +500,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
498
500
|
version: '0'
|
499
501
|
requirements: []
|
500
502
|
rubyforge_project:
|
501
|
-
rubygems_version: 2.
|
503
|
+
rubygems_version: 2.6.7
|
502
504
|
signing_key:
|
503
505
|
specification_version: 4
|
504
506
|
summary: A gem for turning URLs into previews.
|