onebox 1.8.17 → 1.8.18

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: 58d985b6655d6ee7f304e6421f986b9b209e70df
4
- data.tar.gz: 9512550a24da0e89a59a96ad2ad6785441aaedf7
3
+ metadata.gz: 2e7e216d163d7adc99ee432d4bc16e639fa621f4
4
+ data.tar.gz: 9c9224c516ef324d858dfab29e37d68e80e0b23a
5
5
  SHA512:
6
- metadata.gz: 2b633f0dd91a6c2aed8c400eb32b63750c8b2ae6a36ae1f8fb594ad8666768b530bc8b9b28b8e3c6dcb8a49c6c310af417b3d9a91649d0125a21d5d2a8237bb9
7
- data.tar.gz: 8e18edd0c6269cb98a5ccacdfe7cc1cafcaa5d68ef27a5cae8ff9b79cfc5c7125b33d6a04336f32275c522260fb0c52941b5c342671aa7b38e788c40c12b6f1a
6
+ metadata.gz: 2501d3ae5025b97e8efb9133f6dedb91e21d7c0ee4d6775f8a0cc736798cc7109980f93b6dd70ebe6906713934674f071db7acf556e06054d9a0d9d5575fcd54
7
+ data.tar.gz: 07c2a809870856370d0062e34285ccfe14baa24e3c24eb83689b7884c9cd0accbf1239008930826ef077fbaeb769c8429f66cf17e060fccab4aabcd493ae7e21
@@ -24,7 +24,10 @@ module Onebox
24
24
  def get_pdf_info
25
25
  uri = URI.parse(@url)
26
26
  size = Onebox::Helpers.fetch_content_length(@url)
27
- return {filesize: Onebox::Helpers.pretty_filesize(size.to_i), name: File.basename(uri.path)}
27
+ return {
28
+ filesize: size ? Onebox::Helpers.pretty_filesize(size.to_i) : nil,
29
+ name: File.basename(uri.path)
30
+ }
28
31
  rescue
29
32
  nil
30
33
  end
@@ -58,7 +58,8 @@ module Onebox
58
58
  response = (Onebox::Helpers.fetch_response(url, nil, nil, headers) rescue nil)
59
59
  doc = Nokogiri::HTML(response)
60
60
 
61
- unless skip_canonical_link
61
+ ignore_canonical = doc.at('meta[property="og:ignore_canonical"]')
62
+ unless ignore_canonical && ignore_canonical['content'].to_s == 'true'
62
63
  # prefer canonical link
63
64
  canonical_link = doc.at('//link[@rel="canonical"]/@href')
64
65
  if canonical_link && "#{URI(canonical_link).host}#{URI(canonical_link).path}" != "#{URI(url).host}#{URI(url).path}"
@@ -124,10 +125,6 @@ module Onebox
124
125
 
125
126
  twitter
126
127
  end
127
-
128
- def skip_canonical_link
129
- WhitelistedGenericOnebox.probable_discourse(URI(url))
130
- end
131
128
  end
132
129
  end
133
130
  end
data/lib/onebox/layout.rb CHANGED
@@ -20,7 +20,7 @@ module Onebox
20
20
  end
21
21
 
22
22
  @md5 = Digest::MD5.new
23
- @view = View.new(name, record)
23
+ @view = View.new(name, @record)
24
24
  @template_name = "_layout"
25
25
  @template_path = load_paths.last
26
26
  end
@@ -1,3 +1,3 @@
1
1
  module Onebox
2
- VERSION = "1.8.17"
2
+ VERSION = "1.8.18"
3
3
  end
data/lib/onebox/web.rb CHANGED
@@ -12,6 +12,8 @@ module Onebox
12
12
  set :public_folder, Proc.new { "#{root}/assets" }
13
13
  set :views, Proc.new { "#{root}/views" }
14
14
  configure :development do
15
+ register Sinatra::Reloader
16
+ also_reload 'lib/**/*.rb'
15
17
  enable :logging
16
18
  end
17
19
 
@@ -88,6 +88,7 @@ And that too in just over an year, way to go! [boom]">
88
88
  <meta name="twitter:title" content="Congratulations, most stars in 2013 GitHub Octoverse!" />
89
89
  <meta property="og:description" content="Ah, cool. I was not sure how to see that since GitHub changed around the way project top stats looked. Thanks for that link and thank you -- and everyone else who is contributing to the project!" />
90
90
  <meta name="twitter:description" content="Ah, cool. I was not sure how to see that since GitHub changed around the way project top stats looked. Thanks for that link and thank you -- and everyone else who is contributing to the project!" />
91
+ <meta property="og:ignore_canonical" content="true" />
91
92
 
92
93
 
93
94
 
@@ -4,8 +4,12 @@ describe Onebox::Engine::PdfOnebox do
4
4
  let(:link) { "https://acrobatusers.com/assets/uploads/public_downloads/2217/adobe-acrobat-xi-merge-pdf-files-tutorial-ue.pdf" }
5
5
  let(:html) { described_class.new(link).to_html }
6
6
 
7
+ let(:no_content_length_link) { "https://dspace.lboro.ac.uk/dspace-jspui/bitstream/2134/14294/3/greiffenhagen-ca_and_consumption.pdf" }
8
+ let(:no_filesize_html) { described_class.new(no_content_length_link).to_html }
9
+
7
10
  before do
8
11
  FakeWeb.register_uri(:head, link, :content_length => "335562")
12
+ FakeWeb.register_uri(:head, no_content_length_link, :content_length => nil)
9
13
  end
10
14
 
11
15
  describe "#to_html" do
@@ -16,5 +20,9 @@ describe Onebox::Engine::PdfOnebox do
16
20
  it "includes filesize" do
17
21
  expect(html).to include("327.70 KB")
18
22
  end
23
+
24
+ it "doesn’t include filesize when unknown" do
25
+ expect(no_filesize_html).to_not include("<p class='filesize'>")
26
+ end
19
27
  end
20
28
  end
@@ -69,5 +69,11 @@ describe Onebox::Layout do
69
69
  html = described_class.new("amazon", record, cache).to_html
70
70
  expect(html).to include(%|"foo"|)
71
71
  end
72
+
73
+ it "rewrites relative image path" do
74
+ record = { image: "/image.png", link: "https://discourse.org" }
75
+ klass = described_class.new("whitelistedgeneric", record, cache)
76
+ expect(klass.view.record[:image]).to include("https://discourse.org")
77
+ end
72
78
  end
73
79
  end
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.17
4
+ version: 1.8.18
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-08-03 00:00:00.000000000 Z
13
+ date: 2017-08-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: multi_json
@@ -524,7 +524,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
524
524
  version: '0'
525
525
  requirements: []
526
526
  rubyforge_project:
527
- rubygems_version: 2.6.12
527
+ rubygems_version: 2.6.8
528
528
  signing_key:
529
529
  specification_version: 4
530
530
  summary: A gem for turning URLs into previews.