onebox 1.3.4 → 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e6ec4c0001a218e8b9590098e44d4da52954a40
4
- data.tar.gz: 127f485029751a7c358377e2f43724292076ddf1
3
+ metadata.gz: a2fd6f8d2e4bae8fb9b2cdc34a5926bfb7a0d933
4
+ data.tar.gz: d28f32d3c1007902967c3a29d499ffb8ae94a5bc
5
5
  SHA512:
6
- metadata.gz: 333c536b339750392727c685c71d38c7eac70fde2af1f1dcef2b0a31c761d7f461170fdcd38e4658f32c6c7f9351e93ad0dbde3807cebfe1a30dc0102eac8eab
7
- data.tar.gz: 4d7ec47617b283561e80f6b57499e75d6be6a50fe7e50888de6694458c15cca51cfc097aa001e177f32c936ddd89553f55e2218e9d59263106ec5835a0766c20
6
+ metadata.gz: f6cbc44f26e2eb709937db4233e033de53326e80ebafbfc04e86eaadb218f93f8f6bfe3fbe0d86183f102a817fe43ff6544ed8a52fbe063a9a445d82988aa977
7
+ data.tar.gz: 9f8bcdcdea07104b3f1966cc99c5fc1a24eaef4af3744880595f7fdbdd5811ff9ce848caa9d23c515eba2090ef9c00ea87b13561e0571eef55cd308d8c1bbf0f
data/README.md CHANGED
@@ -171,8 +171,8 @@ Installing
171
171
 
172
172
  Add this line to your application's Gemfile:
173
173
 
174
- gem "onebox". "~> 1.2"
175
-
174
+ gem "onebox", "~> 1.2"
175
+
176
176
  And then execute:
177
177
 
178
178
  $ bundle
@@ -11,14 +11,14 @@ module Onebox
11
11
 
12
12
  def to_s
13
13
  return "" unless engine
14
- engine.to_html || ""
14
+ process_html(engine_html)
15
15
  rescue *Onebox::Preview.web_exceptions
16
16
  ""
17
17
  end
18
18
 
19
19
  def placeholder_html
20
20
  return "" unless engine
21
- engine.placeholder_html || ""
21
+ process_html(engine.placeholder_html)
22
22
  rescue *Onebox::Preview.web_exceptions
23
23
  ""
24
24
  end
@@ -33,6 +33,35 @@ module Onebox
33
33
 
34
34
  private
35
35
 
36
+ def engine_html
37
+ engine.to_html
38
+ end
39
+
40
+ def process_html(html)
41
+ return "" unless html
42
+
43
+ if @options[:max_width]
44
+ doc = Nokogiri::HTML::fragment(html)
45
+ if doc
46
+ doc.css('[width]').each do |e|
47
+ width = e['width'].to_i
48
+
49
+ if width > @options[:max_width]
50
+ height = e['height'].to_i
51
+ if (height > 0)
52
+ ratio = (height.to_f / width.to_f)
53
+ e['height'] = (@options[:max_width] * ratio).floor
54
+ end
55
+ e['width'] = @options[:max_width]
56
+ end
57
+ end
58
+ return doc.to_html
59
+ end
60
+ end
61
+
62
+ html
63
+ end
64
+
36
65
  def engine
37
66
  return nil unless @engine_class
38
67
  @engine ||= @engine_class.new(@url, cache)
@@ -1,3 +1,3 @@
1
1
  module Onebox
2
- VERSION = "1.3.4"
2
+ VERSION = "1.3.5"
3
3
  end
@@ -12,7 +12,8 @@ describe Onebox::Preview do
12
12
  FakeWeb.register_uri(:get, "http://www.amazon.com/error-connecting", exception: Errno::ECONNREFUSED)
13
13
  end
14
14
 
15
- let(:preview) { described_class.new("http://www.amazon.com/product") }
15
+ let(:preview_url) { "http://www.amazon.com/product" }
16
+ let(:preview) { described_class.new(preview_url) }
16
17
 
17
18
  describe "#to_s" do
18
19
  it "returns some html if given a valid url" do
@@ -45,6 +46,37 @@ describe Onebox::Preview do
45
46
  end
46
47
  end
47
48
 
49
+ describe "max_width" do
50
+ let(:iframe_html) { '<iframe src="//player.vimeo.com/video/96017582" width="1280" height="720" frameborder="0" title="GO BIG OR GO HOME" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>' }
51
+
52
+ it "doesn't change dimensions without an option" do
53
+ iframe = described_class.new(preview_url)
54
+ iframe.expects(:engine_html).returns(iframe_html)
55
+
56
+ result = iframe.to_s
57
+ expect(result).to include("width=\"1280\"")
58
+ expect(result).to include("height=\"720\"")
59
+ end
60
+
61
+ it "doesn't change dimensions if it is smaller than `max_width`" do
62
+ iframe = described_class.new(preview_url, max_width: 2000)
63
+ iframe.expects(:engine_html).returns(iframe_html)
64
+
65
+ result = iframe.to_s
66
+ expect(result).to include("width=\"1280\"")
67
+ expect(result).to include("height=\"720\"")
68
+ end
69
+
70
+ it "changes dimensions if larger than `max_width`" do
71
+ iframe = described_class.new(preview_url, max_width: 900)
72
+ iframe.expects(:engine_html).returns(iframe_html)
73
+
74
+ result = iframe.to_s
75
+ expect(result).to include("width=\"900\"")
76
+ expect(result).to include("height=\"506\"")
77
+ end
78
+ end
79
+
48
80
  describe "#engine" do
49
81
  it "returns an engine" do
50
82
  expect(preview.send(:engine)).to be_an(Onebox::Engine)
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.3.4
4
+ version: 1.3.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: 2014-05-30 00:00:00.000000000 Z
13
+ date: 2014-06-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: multi_json
@@ -400,3 +400,4 @@ test_files:
400
400
  - spec/lib/onebox_spec.rb
401
401
  - spec/spec_helper.rb
402
402
  - spec/support/html_spec_helper.rb
403
+ has_rdoc: