onebox 1.7.2 → 1.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/onebox/engine.rb +2 -0
- data/lib/onebox/engine/bandcamp_onebox.rb +1 -1
- data/lib/onebox/engine/five_hundred_px_onebox.rb +17 -0
- data/lib/onebox/engine/flickr_onebox.rb +17 -0
- data/lib/onebox/engine/soundcloud_onebox.rb +1 -1
- data/lib/onebox/engine/standard_embed.rb +5 -3
- data/lib/onebox/engine/wikipedia_onebox.rb +11 -11
- data/lib/onebox/helpers.rb +2 -8
- data/lib/onebox/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67ec2675eb6687bee752534aef6d1e610545717b
|
4
|
+
data.tar.gz: cd82452275130c85076cb9078f25650ac9c73444
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 557f8fbdfd7e33e247b5cd82ffc89f1484b57ba075e6c1ea412382be1e846c9aaa08e14777dec3799b5ce76dc61881a01909665087b21c4bd1775aa84f18f65b
|
7
|
+
data.tar.gz: 77c61683b419f729ba6d3b506b8c3bd960ae40f5b52662fb8d6e150605caea7f33e83c8aac7a3fdf9f82f4d1c92c045a571e7df2d5633c4457691e0067b735ae
|
data/lib/onebox/engine.rb
CHANGED
@@ -171,3 +171,5 @@ require_relative "engine/asciinema_onebox"
|
|
171
171
|
require_relative "engine/mixcloud_onebox"
|
172
172
|
require_relative "engine/bandcamp_onebox"
|
173
173
|
require_relative "engine/coub_onebox"
|
174
|
+
require_relative "engine/flickr_onebox"
|
175
|
+
require_relative "engine/five_hundred_px_onebox"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class FiveHundredPxOnebox
|
4
|
+
include Engine
|
5
|
+
include StandardEmbed
|
6
|
+
|
7
|
+
matches_regexp(/^https?:\/\/500px\.com\/photo\/\d+\//)
|
8
|
+
always_https
|
9
|
+
|
10
|
+
def to_html
|
11
|
+
og = get_opengraph
|
12
|
+
"<img src='#{og[:image]}' width='#{og[:image_width]}' height='#{og[:image_height]}' #{Helpers.title_attr(og)}>"
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Onebox
|
2
|
+
module Engine
|
3
|
+
class FlickrOnebox
|
4
|
+
include Engine
|
5
|
+
include StandardEmbed
|
6
|
+
|
7
|
+
matches_regexp(/^https?:\/\/www\.flickr\.com\/photos\//)
|
8
|
+
always_https
|
9
|
+
|
10
|
+
def to_html
|
11
|
+
og = get_opengraph
|
12
|
+
"<img src='#{og[:image]}' width='#{og[:image_width]}' height='#{og[:image_height]}' #{Helpers.title_attr(og)}>"
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "cgi"
|
2
|
+
|
1
3
|
module Onebox
|
2
4
|
module Engine
|
3
5
|
module StandardEmbed
|
@@ -93,14 +95,14 @@ module Onebox
|
|
93
95
|
html_doc.css('meta').each do |m|
|
94
96
|
if (m["property"] && m["property"][/^og:(.+)$/i]) || (m["name"] && m["name"][/^og:(.+)$/i])
|
95
97
|
value = (m["content"] || m["value"]).to_s
|
96
|
-
og[$1.tr('-:','_').to_sym] ||= value unless Onebox::Helpers::blank?(value)
|
98
|
+
og[$1.tr('-:','_').to_sym] ||= CGI.escapeHTML(value) unless Onebox::Helpers::blank?(value)
|
97
99
|
end
|
98
100
|
end
|
99
101
|
|
100
102
|
# Attempt to retrieve the title from the meta tag
|
101
103
|
title_element = html_doc.at_css('title')
|
102
104
|
if title_element && title_element.text
|
103
|
-
og[:title] ||= title_element.text unless Onebox::Helpers.blank?(title_element.text)
|
105
|
+
og[:title] ||= CGI.escapeHTML(title_element.text) unless Onebox::Helpers.blank?(title_element.text)
|
104
106
|
end
|
105
107
|
|
106
108
|
og
|
@@ -114,7 +116,7 @@ module Onebox
|
|
114
116
|
html_doc.css('meta').each do |m|
|
115
117
|
if (m["property"] && m["property"][/^twitter:(.+)$/i]) || (m["name"] && m["name"][/^twitter:(.+)$/i])
|
116
118
|
value = (m["content"] || m["value"]).to_s
|
117
|
-
twitter[$1.tr('-:','_').to_sym] ||= value unless Onebox::Helpers::blank?(value)
|
119
|
+
twitter[$1.tr('-:','_').to_sym] ||= CGI.escapeHTML(value) unless Onebox::Helpers::blank?(value)
|
118
120
|
end
|
119
121
|
end
|
120
122
|
|
@@ -5,7 +5,7 @@ module Onebox
|
|
5
5
|
include LayoutSupport
|
6
6
|
include HTML
|
7
7
|
|
8
|
-
matches_regexp(/^https
|
8
|
+
matches_regexp(/^https?:\/\/.*\.wikipedia\.(com|org)/)
|
9
9
|
always_https
|
10
10
|
|
11
11
|
private
|
@@ -22,23 +22,23 @@ module Onebox
|
|
22
22
|
end
|
23
23
|
|
24
24
|
unless m_url_hash.nil?
|
25
|
-
section_header_title = raw.xpath("//span[@id='#{m_url_hash_name}']")
|
25
|
+
section_header_title = raw.xpath("//span[@id='#{m_url_hash_name}']")
|
26
26
|
|
27
|
-
if section_header_title.empty?
|
27
|
+
if section_header_title.empty?
|
28
28
|
paras = raw.search("p") #default get all the paras
|
29
|
-
else
|
29
|
+
else
|
30
30
|
section_title_text = section_header_title.inner_text
|
31
31
|
section_header = section_header_title[0].parent #parent element of the section span element should be an <h3> node
|
32
32
|
cur_element = section_header
|
33
|
-
|
33
|
+
|
34
34
|
# p|text|div covers the general case. We assume presence of atleast 1 P node. if section has no P node we may end up with a P node from the next section.
|
35
35
|
# div tag is commonly used as an assets wraper in an article section. often as the first element holding an image.
|
36
36
|
# ul support will imporve the output generated for a section with a list as the main content (for example: an Author Bibliography, A musician Discography, etc)
|
37
|
-
first_p_found = nil
|
37
|
+
first_p_found = nil
|
38
38
|
while ( ((next_sibling = cur_element.next_sibling).name =~ /p|text|div|ul/) || first_p_found.nil? ) do #from section header get the next sibling until it is a breaker tag
|
39
39
|
cur_element = next_sibling
|
40
|
-
if (cur_element.name == "p" || cur_element.name == "ul") #we treat a list as we detect a p to avoid showing
|
41
|
-
first_p_found = true
|
40
|
+
if (cur_element.name == "p" || cur_element.name == "ul") #we treat a list as we detect a p to avoid showing
|
41
|
+
first_p_found = true
|
42
42
|
paras.push(cur_element)
|
43
43
|
end
|
44
44
|
end
|
@@ -52,16 +52,16 @@ module Onebox
|
|
52
52
|
while text.length < Onebox::LayoutSupport.max_text && cnt <= 3
|
53
53
|
break if cnt >= paras.size
|
54
54
|
text << " " unless cnt == 0
|
55
|
-
|
55
|
+
|
56
56
|
if paras[cnt].name =="ul" #Handle UL tag. Generate a textual ordered list (1.item | 2.item | 3.item). Unfourtently no newline allowed in output
|
57
57
|
li_index=1
|
58
58
|
list_items = []
|
59
59
|
paras[cnt].children.css("li").each {|li| list_items.push "#{li_index}." + li.inner_text ; li_index+=1}
|
60
60
|
paragraph = (list_items.join " |\n ")[0..Onebox::LayoutSupport.max_text]
|
61
61
|
else
|
62
|
-
paragraph = paras[cnt].inner_text[0..Onebox::LayoutSupport.max_text]
|
62
|
+
paragraph = paras[cnt].inner_text[0..Onebox::LayoutSupport.max_text]
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
paragraph.gsub!(/\[\d+\]/mi, "")
|
66
66
|
text << paragraph
|
67
67
|
cnt += 1
|
data/lib/onebox/helpers.rb
CHANGED
@@ -4,14 +4,8 @@ module Onebox
|
|
4
4
|
return {} if hash.nil?
|
5
5
|
|
6
6
|
hash.inject({}){|result, (key, value)|
|
7
|
-
new_key =
|
8
|
-
|
9
|
-
else key
|
10
|
-
end
|
11
|
-
new_value = case value
|
12
|
-
when Hash then symbolize_keys(value)
|
13
|
-
else value
|
14
|
-
end
|
7
|
+
new_key = key.is_a?(String) ? key.to_sym : key
|
8
|
+
new_value = value.is_a?(Hash) ? symbolize_keys(value) : value
|
15
9
|
result[new_key] = new_value
|
16
10
|
result
|
17
11
|
}
|
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.7.
|
4
|
+
version: 1.7.3
|
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-01-
|
13
|
+
date: 2017-01-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: multi_json
|
@@ -321,6 +321,8 @@ files:
|
|
321
321
|
- lib/onebox/engine/bandcamp_onebox.rb
|
322
322
|
- lib/onebox/engine/coub_onebox.rb
|
323
323
|
- lib/onebox/engine/douban_onebox.rb
|
324
|
+
- lib/onebox/engine/five_hundred_px_onebox.rb
|
325
|
+
- lib/onebox/engine/flickr_onebox.rb
|
324
326
|
- lib/onebox/engine/gfycat_onebox.rb
|
325
327
|
- lib/onebox/engine/giphy_onebox.rb
|
326
328
|
- lib/onebox/engine/github_blob_onebox.rb
|