link_thumbnailer 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ # 1.0.2
2
+
3
+ - Feature: User can now set options at runtime by passing valid options to ```generate``` method
4
+ - Bug fix when doing ```rails g link_thumbnailer:install``` by explicitly specifying the scope of Rails
5
+
6
+ # 1.0.1
7
+
8
+ - Refactor LinkThumbnailer#generate method to have a cleaner code
9
+
10
+ # 1.0.0
11
+
12
+ - Update readme
13
+ - Add PreviewController for easy integration with user's app
14
+ - Add link_thumbnailer routes for easy integration with user's app
15
+ - Refactor some code
16
+ - Change 'to_a' method to 'to_hash' in object model
17
+
1
18
  # 0.0.6
2
19
 
3
20
  - Update readme
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # LinkThumbnailer
2
2
 
3
+ [![Code Climate](https://codeclimate.com/github/gottfrois/link_thumbnailer.png)](https://codeclimate.com/github/gottfrois/link_thumbnailer)
4
+
3
5
  Ruby gem generating image thumbnails from a given URL. Rank them and give you back an object containing images and website informations. Works like Facebook link previewer.
4
6
 
5
- Demo Application is [here](https://github.com/gottfrois/link_thumbnailer_demo) !
7
+ Demo Application is [here](http://link-thumbnailer-demo.herokuapp.com/) !
6
8
 
7
9
  ## Installation
8
10
 
@@ -80,9 +82,9 @@ You can check whether this object is valid or not (set mandatory attributes in t
80
82
  object.valid?
81
83
  => true
82
84
 
83
- You also can set `limit` and `top` options at runtime:
85
+ You also can set options at runtime:
84
86
 
85
- object = LinkThumbnailer.generate('http://foo.com', :top => 10, :limit => 20)
87
+ object = LinkThumbnailer.generate('http://foo.com', top: 10, limit: 20, redirect_limit: 5)
86
88
 
87
89
  ## Preview Controller
88
90
 
@@ -92,7 +94,7 @@ Take a look at the demo application [here](https://github.com/gottfrois/link_thu
92
94
 
93
95
  Basically, all you have to do in your view is something like this:
94
96
 
95
- <%= form_tag '/link/preview', :method => 'post', :remote => true do %>
97
+ <%= form_tag '/link/preview', method: :post, remote: true do %>
96
98
  <%= text_field_tag :url %>
97
99
  <%= submit_tag 'Preview' %>
98
100
  <% end %>
@@ -101,7 +103,7 @@ Don't forget to add this anywhere in your `routes.rb` file:
101
103
 
102
104
  use_link_thumbnailer
103
105
 
104
- Note: You won't have to bother with this if you did runned the installer using:
106
+ Note: You won't have to bother with this if you did run the installer using:
105
107
 
106
108
  $ rails g link_thumbnailer:install
107
109
 
@@ -149,6 +151,7 @@ Implemented:
149
151
 
150
152
  Coming soon:
151
153
 
154
+ - Use the gem [ruby-readability](https://github.com/iterationlabs/ruby-readability) to parse images and website information
152
155
  - Cache results on filesystem
153
156
 
154
157
  ## Contributing
@@ -1,6 +1,6 @@
1
1
  module LinkThumbnailer
2
2
  module Generators
3
- class InstallGenerator < Rails::Generators::Base
3
+ class InstallGenerator < ::Rails::Generators::Base
4
4
 
5
5
  source_root File.expand_path('../../templates', __FILE__)
6
6
 
@@ -1,3 +1,3 @@
1
1
  module LinkThumbnailer
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -44,35 +44,49 @@ module LinkThumbnailer
44
44
  end
45
45
 
46
46
  def generate(url, options = {})
47
+ set_options(options)
48
+ instantiate_classes
49
+
50
+ doc = self.doc_parser.parse(self.fetcher.fetch(url), url)
51
+
52
+ self.object[:url] = doc.source_url
53
+ opengraph(doc) || custom(doc)
54
+ end
55
+
56
+ private
57
+
58
+ def set_options(options)
47
59
  LinkThumbnailer.configure {|config|
48
- config.top = options[:top].to_i if options[:top]
49
- config.limit = options[:limit].to_i if options[:limit]
60
+ config.mandatory_attributes = options[:mandatory_attributes] if options[:mandatory_attributes]
61
+ config.strict = options[:strict] if options[:strict]
62
+ config.redirect_limit = options[:redirect_limit].to_i if options[:redirect_limit]
63
+ config.blacklist_urls = options[:blacklist_urls] if options[:blacklist_urls]
64
+ config.rmagick_attributes = options[:rmagick_attributes] if options[:rmagick_attributes]
65
+ config.limit = options[:limit].to_i if options[:limit]
66
+ config.top = options[:top].to_i if options[:top]
50
67
  }
68
+ end
51
69
 
70
+ def instantiate_classes
52
71
  self.object = LinkThumbnailer::Object.new
53
72
  self.fetcher = LinkThumbnailer::Fetcher.new
54
73
  self.doc_parser = LinkThumbnailer::DocParser.new
55
74
  self.img_url_filters = [LinkThumbnailer::ImgUrlFilter.new]
56
75
  self.img_parser = LinkThumbnailer::ImgParser.new(self.fetcher, self.img_url_filters)
76
+ end
57
77
 
58
- doc_string = self.fetcher.fetch(url)
59
- doc = self.doc_parser.parse(doc_string, url)
60
-
61
- self.object[:url] = doc.source_url
62
-
63
- # Try Opengraph first
78
+ def opengraph(doc)
64
79
  self.object = LinkThumbnailer::Opengraph.parse(self.object, doc)
65
-
66
80
  return self.object if self.object.valid?
81
+ nil
82
+ end
67
83
 
68
- # Else try manually
69
-
84
+ def custom(doc)
70
85
  self.object[:title] = doc.title
71
86
  self.object[:description] = doc.description
72
87
  self.object[:images] = self.img_parser.parse(doc.img_abs_urls.dup)
73
-
74
- return nil unless self.object.valid?
75
- self.object
88
+ return self.object if self.object.valid?
89
+ nil
76
90
  end
77
91
 
78
92
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: link_thumbnailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-31 00:00:00.000000000 Z
12
+ date: 2013-03-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri