onebox 1.5.45 → 1.5.47

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e998911edf06c4987d5e9fb5655db49332b1cf3e
4
- data.tar.gz: c5c5efd4450eafe4e028226ed2aedd9e0268787c
3
+ metadata.gz: 8bad22bcad833d28f87b0faef3ae2cc7be1ae572
4
+ data.tar.gz: 00f0f7bc597bc49f64e0c193929f9b30f84195c2
5
5
  SHA512:
6
- metadata.gz: a7f74b6b0874a4fced20ab115bafcab8cb10788d8e6f1b2d3c5a0c2daab098d99acefae73b47ffa61c853f88015054d47d1d8600f5eeb9cce7daa07db04e6032
7
- data.tar.gz: 609eff1c52bfa7d03b944ce7579542ceabaaafc33876abefa01765fb62ea68a3ce32a1d7f37b157208fcb0a32dd51ac920aa2d68b7db699e897d71b0c806d0e6
6
+ metadata.gz: 1c895c0b051d23f05dd667559df39e523daad6c5594bac40b29524fc6df255d8f4eb490a8c877984d1c8a9edd5dbf077f7e3b6ed05ed83cc7087f7584ab9cb06
7
+ data.tar.gz: b98d19fd3c090c67d0967289e988b3f0aa820dd3483011d0b3cd10a6656b03fb7b1f8cf76059f05298923fac21f5a7607bf941f8c8e1dd2d2e09a00f9443ca2d
@@ -2,68 +2,36 @@ module Onebox
2
2
  module Engine
3
3
  class GoogleDocsOnebox
4
4
  include Engine
5
+ include LayoutSupport
5
6
 
6
- class << self
7
- def supported_endpoints
8
- %w(spreadsheets document forms presentation)
9
- end
10
-
11
- def embed_widths
12
- @embed_widths ||= {
13
- spreadsheets: 800,
14
- document: 800,
15
- presentation: 960,
16
- forms: 760,
17
- }
18
- end
19
-
20
- def embed_heights
21
- @embed_heights ||= {
22
- spreadsheets: 600,
23
- document: 600,
24
- presentation: 749,
25
- forms: 500,
26
- }
27
- end
7
+ def self.supported_endpoints
8
+ %w(spreadsheets document forms presentation)
9
+ end
28
10
 
29
- def short_types
30
- @shorttypes ||= {
31
- spreadsheets: :sheets,
32
- document: :docs,
33
- presentation: :slides,
34
- forms: :forms,
35
- }
36
- end
11
+ def self.short_types
12
+ @shorttypes ||= {
13
+ spreadsheets: :sheets,
14
+ document: :docs,
15
+ presentation: :slides,
16
+ forms: :forms,
17
+ }
37
18
  end
38
19
 
39
20
  matches_regexp /^(https?:)?\/\/(docs\.google\.com)\/(?<endpoint>(#{supported_endpoints.join('|')}))\/d\/((?<key>[\w-]*)).+$/
40
21
  always_https
41
22
 
42
- def to_html
43
- if document?
44
- "<iframe class='gdocs-onebox document-onebox' src='https://docs.google.com/document/d/#{key}/pub?embedded=true' style='border: 0' width='#{width}' height='#{height}' frameborder='0' scrolling='yes'>#{placeholder_html}</iframe>"
45
- elsif spreadsheet?
46
- "<iframe class='gdocs-onebox spreadsheet-onebox' src='https://docs.google.com/spreadsheet/ccc?key=#{key}&usp=sharing&rm=minimal' style='border: 0' width='#{width}' height='#{height}' frameborder='0' scrolling='yes'>#{placeholder_html}</iframe>"
47
- elsif presentation?
48
- "<iframe class='gdocs-onebox presentation-onebox' src='https://docs.google.com/presentation/d/#{key}/embed?start=false&loop=false&delayms=3000' frameborder='0' width='#{width}' height='#{height}' allowfullscreen='true' mozallowfullscreen='true' webkitallowfullscreen='true'>#{placeholder_html}</iframe>"
49
- elsif forms?
50
- "<iframe class='gdocs-onebox forms-onebox' src='https://docs.google.com/forms/d/#{key}/viewform?embedded=true' width='#{width}' height='#{height}' frameborder='0' marginheight='0' marginwidth='0' scrolling='yes'>#{placeholder_html}</iframe>"
51
- end
52
- end
23
+ protected
53
24
 
54
- def placeholder_html
55
- <<HTML
56
- <div placeholder><div class='gdocs-onebox gdocs-onebox-splash' style='display:table-cell;vertical-align:middle;width:#{width}px;height:#{height}px'>
57
- <div style='text-align:center;'>
58
- <div class='gdocs-onebox-logo g-#{shorttype}-logo'></div>
59
- <p>Google #{shorttype.capitalize}</p>
60
- <p><a href="https://docs.google.com/#{doc_type}/d/#{key}">#{key}</a></p>
61
- </div></div></div>
62
- HTML
25
+ def data
26
+ og_data = get_og_data
27
+ result = { link: link,
28
+ title: og_data[:title],
29
+ description: og_data[:description],
30
+ type: shorttype
31
+ }
32
+ result
63
33
  end
64
34
 
65
- protected
66
-
67
35
  def doc_type
68
36
  @doc_type ||= match[:endpoint].to_sym
69
37
  end
@@ -72,37 +40,23 @@ HTML
72
40
  GoogleDocsOnebox.short_types[doc_type]
73
41
  end
74
42
 
75
- def width
76
- GoogleDocsOnebox.embed_widths[doc_type]
77
- end
78
-
79
- def height
80
- GoogleDocsOnebox.embed_heights[doc_type]
81
- end
82
-
83
- def spreadsheet?
84
- doc_type == :spreadsheets
85
- end
86
-
87
- def document?
88
- doc_type == :document
89
- end
90
-
91
- def presentation?
92
- doc_type == :presentation
93
- end
94
-
95
- def forms?
96
- doc_type == :forms
97
- end
98
-
99
- def key
100
- match[:key]
101
- end
102
-
103
43
  def match
104
44
  @match ||= @url.match(@@matcher)
105
45
  end
46
+
47
+ def get_og_data
48
+ response = Onebox::Helpers.fetch_response(url)
49
+ html = Nokogiri::HTML(response.body)
50
+ og_data = {}
51
+ html.css('meta').each do |m|
52
+ if m.attribute('property') && m.attribute('property').to_s.match(/^og:/i)
53
+ m_content = m.attribute('content').to_s.strip
54
+ m_property = m.attribute('property').to_s.gsub('og:', '')
55
+ og_data[m_property.to_sym] = m_content
56
+ end
57
+ end
58
+ og_data
59
+ end
106
60
  end
107
61
  end
108
- end
62
+ end
@@ -1,3 +1,3 @@
1
1
  module Onebox
2
- VERSION = "1.5.45"
2
+ VERSION = "1.5.47"
3
3
  end
@@ -4,64 +4,32 @@ describe Onebox::Engine::GoogleDocsOnebox do
4
4
  context "Spreadsheets" do
5
5
  let(:matcher) { described_class.new("https://docs.google.com/spreadsheets/d/SHEET_KEY/pubhtml") }
6
6
 
7
- it "should have spreadsheet class in html" do
8
- expect(matcher.to_html).to include "spreadsheet-onebox"
9
- end
10
-
11
7
  it "should be a spreadsheet" do
12
- expect(matcher.send(:spreadsheet?)).to be true
13
- end
14
-
15
- it "Should detect key" do
16
- expect(matcher.send(:key)).to eq 'SHEET_KEY'
8
+ expect(matcher.send(:shorttype)).to eq (:sheets)
17
9
  end
18
10
  end
19
11
 
20
12
  context "Documents" do
21
13
  let(:matcher) { described_class.new("https://docs.google.com/document/d/DOC_KEY/pub") }
22
14
 
23
- it "should have document class in html" do
24
- expect(matcher.to_html).to include "document-onebox"
25
- end
26
-
27
15
  it "should be a document" do
28
- expect(matcher.send(:document?)).to be true
29
- end
30
-
31
- it "Should detect key" do
32
- expect(matcher.send(:key)).to eq 'DOC_KEY'
16
+ expect(matcher.send(:shorttype)).to eq (:docs)
33
17
  end
34
18
  end
35
19
 
36
20
  context "Presentaions" do
37
21
  let(:matcher) { described_class.new("https://docs.google.com/presentation/d/PRESENTATION_KEY/pub") }
38
22
 
39
- it "should have presentation class in html" do
40
- expect(matcher.to_html).to include "presentation-onebox"
41
- end
42
-
43
23
  it "should be a presentation" do
44
- expect(matcher.send(:presentation?)).to be true
45
- end
46
-
47
- it "Should detect key" do
48
- expect(matcher.send(:key)).to eq 'PRESENTATION_KEY'
24
+ expect(matcher.send(:shorttype)).to eq (:slides)
49
25
  end
50
26
  end
51
27
 
52
28
  context "Forms" do
53
29
  let(:matcher) { described_class.new("https://docs.google.com/forms/d/FORMS_KEY/viewform") }
54
30
 
55
- it "should have forms class in html" do
56
- expect(matcher.to_html).to include "forms-onebox"
57
- end
58
-
59
31
  it "should be a form" do
60
- expect(matcher.send(:forms?)).to be true
61
- end
62
-
63
- it "Should detect key" do
64
- expect(matcher.send(:key)).to eq 'FORMS_KEY'
32
+ expect(matcher.send(:shorttype)).to eq (:forms)
65
33
  end
66
34
  end
67
35
  end
@@ -0,0 +1,5 @@
1
+ <div class='googledocs-onebox-logo g-{{type}}-logo'></div>
2
+
3
+ <h3><a href='{{{link}}}' target="_blank">{{title}}</a></h3>
4
+
5
+ <p>{{description}}</p>
@@ -1,5 +1,5 @@
1
1
  {{#image}}<img src="{{image}}" class="thumbnail"/>{{/image}}
2
2
 
3
- <h3><a href='{{{link}}}' target="_blank">{{title}}</a></h3>
3
+ <h3><a href='{{{link}}}' target="_blank">{{title}}</a></h3>
4
4
 
5
5
  <p>{{description}}</p>
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.5.45
4
+ version: 1.5.47
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: 2016-08-08 00:00:00.000000000 Z
13
+ date: 2016-08-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: multi_json
@@ -404,6 +404,7 @@ files:
404
404
  - templates/githubgist.mustache
405
405
  - templates/githubissue.mustache
406
406
  - templates/githubpullrequest.mustache
407
+ - templates/googledocs.mustache
407
408
  - templates/googleplayapp.mustache
408
409
  - templates/pastebin.mustache
409
410
  - templates/pubmed.mustache