ruby-readability 0.5.5 → 0.5.6

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.
data/CHANGES.markdown CHANGED
@@ -1,3 +1,7 @@
1
1
  Oct 1, 2012:
2
2
 
3
3
  - Merged in austinrfnd's `author` handling code.
4
+
5
+ Dec 13, 2012
6
+
7
+ - Use fastimage instead of mini_magick for JRuby compat.
data/Gemfile CHANGED
@@ -1,7 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in ruby-readability.gemspec
4
- gem 'mini_magick', '3.3'
3
+ gem 'fastimage', '~> 1.2.13'
5
4
 
6
5
  group :test do
7
6
  gem "fakeweb", "~> 1.3.0"
data/README.markdown CHANGED
@@ -49,7 +49,7 @@ Readability comes with a command-line tool for experimentation in bin/readabilit
49
49
 
50
50
  ## Images
51
51
 
52
- You can get a list of images in the content area with `.images`. This feature requires that the `mini_magick` gem be installed
52
+ You can get a list of images in the content area with `.images`. This feature requires that the `fastimage` gem be installed
53
53
 
54
54
  rbody = Readability::Document.new(body, :tags => %w[div p img a], :attributes => %w[src href], :remove_empty_nodes => false)
55
55
  rbody.images
data/lib/readability.rb CHANGED
@@ -55,9 +55,9 @@ module Readability
55
55
 
56
56
  def images(content=nil, reload=false)
57
57
  begin
58
- require 'mini_magick'
58
+ require 'fastimage'
59
59
  rescue LoadError
60
- raise "Please install mini_magick in order to use the #images feature."
60
+ raise "Please install fastimage in order to use the #images feature."
61
61
  end
62
62
 
63
63
  @best_candidate_has_image = false if reload
@@ -76,12 +76,16 @@ module Readability
76
76
  url = element["src"].value
77
77
  height = element["height"].nil? ? 0 : element["height"].value.to_i
78
78
  width = element["width"].nil? ? 0 : element["width"].value.to_i
79
- format = File.extname(url).gsub(".", "")
80
- image = {:width => width, :height => height, :format => format}
81
- image = load_image(url) if url =~ /\Ahttps?:\/\//i && (height.zero? || width.zero?)
82
-
83
- next unless image
84
-
79
+
80
+ if url =~ /\Ahttps?:\/\//i && (height.zero? || width.zero?)
81
+ image = get_image_size(url)
82
+ next unless image
83
+ else
84
+ image = {:width => width, :height => height}
85
+ end
86
+
87
+ image[:format] = File.extname(url).gsub(".", "")
88
+
85
89
  if tested_images.include?(url)
86
90
  debug("Image was tested: #{url}")
87
91
  next
@@ -98,9 +102,11 @@ module Readability
98
102
  (list_images.empty? and content != @html) ? images(@html, true) : list_images
99
103
  end
100
104
 
101
- def load_image(url)
105
+ def get_image_size(url)
102
106
  begin
103
- MiniMagick::Image.open(url)
107
+ w, h = FastImage.size(url)
108
+ raise "Couldn't get size." if w.nil? || h.nil?
109
+ {width: w, height: h}
104
110
  rescue => e
105
111
  debug("Image error: #{e}")
106
112
  nil
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "ruby-readability"
6
- s.version = '0.5.5'
6
+ s.version = '0.5.6'
7
7
  s.authors = ["Andrew Cantino", "starrhorne", "libc", "Kyle Maxwell"]
8
8
  s.email = ["andrew@iterationlabs.com"]
9
9
  s.homepage = "http://github.com/iterationlabs/ruby-readability"
@@ -30,11 +30,17 @@ describe Readability do
30
30
  FakeWeb::Registry.instance.clean_registry
31
31
  FakeWeb.register_uri(:get, "http://img.thesun.co.uk/multimedia/archive/01416/dim_1416768a.jpg",
32
32
  :body => File.read(File.dirname(__FILE__) + "/fixtures/images/dim_1416768a.jpg"))
33
+
34
+ FakeWeb.register_uri(:get, "http://img.thesun.co.uk/multimedia/archive/00703/sign_up_emails_682__703711a.gif",
35
+ :body => File.read(File.dirname(__FILE__) + "/fixtures/images/sign_up_emails_682__703711a.gif"))
36
+
37
+ FakeWeb.register_uri(:get, "http://img.thesun.co.uk/multimedia/archive/00703/sign_up_emails_682__703712a.gif",
38
+ :body => File.read(File.dirname(__FILE__) + "/fixtures/images/sign_up_emails_682__703712a.gif"))
33
39
  end
34
40
 
35
41
  it "should show one image, but outside of the best candidate" do
36
42
  @doc = Readability::Document.new(@thesum)
37
- @doc.images.should == ["http://img.thesun.co.uk/multimedia/archive/01416/dim_1416768a.jpg"]
43
+ @doc.images.should == ["http://img.thesun.co.uk/multimedia/archive/01416/dim_1416768a.jpg", "http://img.thesun.co.uk/multimedia/archive/00703/sign_up_emails_682__703711a.gif", "http://img.thesun.co.uk/multimedia/archive/00703/sign_up_emails_682__703712a.gif"]
38
44
  @doc.best_candidate_has_image.should == false
39
45
  end
40
46
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-readability
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.5.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2012-10-02 00:00:00.000000000 Z
15
+ date: 2012-12-18 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rspec
@@ -116,6 +116,8 @@ files:
116
116
  - spec/fixtures/bbc.html
117
117
  - spec/fixtures/cant_read.html
118
118
  - spec/fixtures/images/dim_1416768a.jpg
119
+ - spec/fixtures/images/sign_up_emails_682__703711a.gif
120
+ - spec/fixtures/images/sign_up_emails_682__703712a.gif
119
121
  - spec/fixtures/nytimes.html
120
122
  - spec/fixtures/sample.html
121
123
  - spec/fixtures/samples/blogpost_with_links-fragments.rb
@@ -151,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
153
  version: '0'
152
154
  requirements: []
153
155
  rubyforge_project: ruby-readability
154
- rubygems_version: 1.8.21
156
+ rubygems_version: 1.8.23
155
157
  signing_key:
156
158
  specification_version: 3
157
159
  summary: Port of arc90's readability project to ruby
@@ -159,6 +161,8 @@ test_files:
159
161
  - spec/fixtures/bbc.html
160
162
  - spec/fixtures/cant_read.html
161
163
  - spec/fixtures/images/dim_1416768a.jpg
164
+ - spec/fixtures/images/sign_up_emails_682__703711a.gif
165
+ - spec/fixtures/images/sign_up_emails_682__703712a.gif
162
166
  - spec/fixtures/nytimes.html
163
167
  - spec/fixtures/sample.html
164
168
  - spec/fixtures/samples/blogpost_with_links-fragments.rb