gravtastic 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,118 @@
1
+ # Gravtastic
2
+
3
+ <small>The super fantastic way of getting Gravatars. By [Chris](http://chrislloyd.com.au).</small>
4
+
5
+ In less than 5 minutes you can add Gravatars to your Ruby project. It works in Rails, Merb _and_ plain ol' Ruby.
6
+
7
+ The best way to learn more about Gravtastic is to [look at the source](http://github.com/chrislloyd/gravtastic/blob/master/lib/gravtastic.rb). It's one file, about 80 LOC and really pretty simple. If that isn't for you, then follow the instructions below!
8
+
9
+ ## Install
10
+
11
+ sudo gem install gravtastic
12
+
13
+ ## Usage
14
+
15
+ Add this to your `environment.rb`:
16
+
17
+ config.gem 'gravtastic', :version => '>= 2.1.0'
18
+
19
+ Next, say that you want a Gravatar for your model:
20
+
21
+ class User < ActiveRecord::Base
22
+ is_gravtastic!
23
+ end
24
+
25
+ And you are done! In your views you can now use the `#gravatar_url` method:
26
+
27
+ <%= image_tag @user.gravatar_url %>
28
+
29
+ If you want to change the image, you can do this:
30
+
31
+ <%= image_tag @user.gravatar_url(:rating => 'R', :secure => true) %>
32
+
33
+ That will show R rated Gravatars over a secure connection. If you find yourself repeating that all around your app, you can set the Gravatar defaults. In your model, just change the `is_gravtastic!` line to something like this:
34
+
35
+ is_gravtastic :author_email, :secure => true,
36
+ :filetype => :gif,
37
+ :size => 120
38
+
39
+ Now all your Gravatars will come from a secure connection, be a GIF and be 120x120px. The email will also come from the `author_email` field, not the default `email` field. Don't worry, you arn't locked into these defaults (you can override them by passing options to `#gravatar_url` like before).
40
+
41
+ _Note: You can use either `is_gravtastic!` or `is_gravtastic`, they both do the same thing._
42
+
43
+ ### Plain Ruby
44
+
45
+ So you just have a regular ol' Ruby app? No Rails and ActiveRecord?
46
+
47
+ require 'gravtastic'
48
+ class BoringUser
49
+ include Gravtastic
50
+ is_gravtastic!
51
+ end
52
+
53
+ And wallah! That works exactly the same as in Rails! Now all instances of the BoringUser class will have `#gravatar_url` methods.
54
+
55
+ _Note: the `#gravatar_url` methods don't get included until you specify the class `is_gravtastic!`_
56
+
57
+ ### Complete List of Options
58
+
59
+ <table>
60
+ <tr>
61
+ <th>Option</th>
62
+ <th>Description</th>
63
+ <th>Default</th>
64
+ <th>Values<th>
65
+ </tr>
66
+ <tr>
67
+ <td><b>secure</b></td>
68
+ <td>Gravatar transmitted with SSL</td>
69
+ <td>false</td>
70
+ <td>true/false</td>
71
+ </tr>
72
+ <tr>
73
+ <td><b>size</b></td>
74
+ <td>The size of the image</td>
75
+ <td>80</td>
76
+ <td>1..512</td>
77
+ </tr>
78
+ <tr>
79
+ <td><b>default</b></td>
80
+ <td>The default avatar image</td>
81
+ <td><i>none</i></td>
82
+ <td>Any URL, or "identicon", "monsterid", "wavatar"</td>
83
+ </tr>
84
+ <tr>
85
+ <td><b>rating</b></td>
86
+ <td>The lowest level of ratings you want to allow</td>
87
+ <td>G</td>
88
+ <td>G, PG, R or X</td>
89
+ </tr>
90
+ <tr>
91
+ <td><b>filetype</b></td>
92
+ <td>The filetype of the image</td>
93
+ <td>png</td>
94
+ <td>gif, jpg or png</td>
95
+ </tr>
96
+ </table>
97
+
98
+ ## Making Changes Yourself
99
+
100
+ Fork the project, submit a pull request and I'll get to it straight away. Or you can just view the source like:
101
+
102
+ git clone git://github.com/chrislloyd/gravtastic.git
103
+
104
+ ## Thanks
105
+
106
+ * [Xavier Shay](http://rhnh.net) and others for [Enki](http://enkiblog.com) (the reason this was originally written)
107
+ * [Matthew Moore](http://www.matthewpaulmoore.com/) for helpful suggestions and for submitting it to the official list of Gravatar implementations.
108
+ * [Vincent Charles](http://vincentcharles.com/) For some documentation in a previous version.
109
+
110
+ ## License
111
+
112
+ Copyright (c) 2009 Chris Lloyd.
113
+
114
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
115
+
116
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
117
+
118
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,76 +1,10 @@
1
1
  require 'mg'
2
+ require 'spec/rake/spectask'
2
3
 
3
4
  MG.new('gravtastic.gemspec')
4
5
 
5
- # require 'rubygems'
6
- # require 'rake/gempackagetask'
7
- # require 'rake/rdoctask'
8
- # require 'rubygems/specification'
9
- # require 'spec/rake/spectask'
10
- # require 'date'
11
- #
12
- # GEM = "gravtastic"
13
- # GEM_VERSION = "2.0.0"
14
- # AUTHOR = "Chris Lloyd"
15
- # EMAIL = "christopher.lloyd@gmail.com"
16
- # HOMEPAGE = "http://github.com/chrislloyd/gravtastic"
17
- # SUMMARY = "Easily add Gravatars to your Ruby objects."
18
- #
19
- # spec = Gem::Specification.new do |s|
20
- # s.name = GEM
21
- # s.version = GEM_VERSION
22
- # s.platform = Gem::Platform::RUBY
23
- # s.rubyforge_project = GEM
24
- # s.has_rdoc = true
25
- # s.extra_rdoc_files = ['README.textile', 'LICENSE']
26
- # s.summary = SUMMARY
27
- # s.description = s.summary
28
- # s.author = AUTHOR
29
- # s.email = EMAIL
30
- # s.homepage = HOMEPAGE
31
- #
32
- # # Uncomment this to add a dependency
33
- # # s.add_dependency "foo"
34
- #
35
- # s.require_path = 'lib'
36
- # s.files = %w(LICENSE README.textile Rakefile) + Dir.glob("{lib,spec}/**/*")
37
- # end
38
- #
39
- # desc "Run Specs"
40
- # Rake::GemPackageTask.new(spec) do |pkg|
41
- # pkg.gem_spec = spec
42
- # end
43
- #
44
- # desc "Generate Documentation"
45
- # Rake::RDocTask.new do |rdoc|
46
- # rdoc.rdoc_dir = 'doc'
47
- # rdoc.title = 'Gravtastic'
48
- # rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'Gravtastic'
49
- # rdoc.rdoc_files.include(FileList[ 'lib/**/*.rb', 'README.textile', 'LICENSE'])
50
- # end
51
- #
52
- # task :default => :spec
53
- # task :specs => :spec
54
- #
55
- # desc "Run all examples"
56
- # Spec::Rake::SpecTask.new('spec') do |t|
57
- # t.spec_opts = ['--options','spec/spec.opts']
58
- # t.spec_files = FileList['spec/**/*.rb']
59
- # # t.rcov = true
60
- # end
61
- #
62
- # desc "install the gem locally"
63
- # task :install => [:package] do
64
- # sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
65
- # end
66
- #
67
- # desc "create a gemspec file"
68
- # task :make_spec do
69
- # File.open("#{GEM}.gemspec", "w") do |file|
70
- # file.puts spec.to_ruby
71
- # end
72
- # end
73
- #
74
- # task :bugs do
75
- # sh %{ditz html ; open html/index.html}
76
- # end
6
+ Spec::Rake::SpecTask.new('spec') do |t|
7
+ t.spec_opts = ['--options','spec/spec.opts']
8
+ t.spec_files = FileList['spec/**/*.rb']
9
+ # t.rcov = true
10
+ end
@@ -1,6 +1,3 @@
1
- $:.unshift(File.dirname(__FILE__)) unless
2
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
-
4
1
  require 'digest/md5'
5
2
  require 'cgi'
6
3
  require 'uri'
@@ -17,6 +14,11 @@ module Gravtastic
17
14
  extend ClassMethods
18
15
  include InstanceMethods
19
16
 
17
+ if source.is_a?(Hash)
18
+ options = source
19
+ source = :email
20
+ end
21
+
20
22
  @gravatar_defaults = {
21
23
  :rating => 'PG',
22
24
  :secure => false,
@@ -25,7 +27,8 @@ module Gravtastic
25
27
  @gravatar_source = source
26
28
  end
27
29
 
28
- alias :has_gravatar :is_gravtastic
30
+ alias_method :has_gravatar, :is_gravtastic
31
+ alias_method :is_gravtastic!, :is_gravtastic
29
32
 
30
33
  end
31
34
 
@@ -41,6 +44,14 @@ module Gravtastic
41
44
  @gravatar_defaults
42
45
  end
43
46
 
47
+ def gravatar_options
48
+ {
49
+ :size => 's',
50
+ :default => 'd',
51
+ :rating => 'r'
52
+ }
53
+ end
54
+
44
55
  end
45
56
 
46
57
  module InstanceMethods
@@ -59,9 +70,8 @@ module Gravtastic
59
70
  private
60
71
 
61
72
  def url_params_from_hash(hash)
62
- '?' + hash.map do |pair|
63
- pair[0] = pair[0].to_s[0,1]
64
- pair.map{|item| item = CGI::escape(item.to_s) }.join('=')
73
+ '?' + hash.map do |key, val|
74
+ [self.class.gravatar_options(key.to_sym) || key.to_s, CGI::escape(val.to_s) ].join('=')
65
75
  end.sort.join('&')
66
76
  end
67
77
 
@@ -1,6 +1,9 @@
1
1
  $TESTING=true
2
2
  $:.push File.join(File.dirname(__FILE__), '..', 'lib')
3
3
 
4
+ require 'rubygems'
5
+ require 'spec'
6
+
4
7
  def reload_gravtastic!
5
8
  Object.class_eval { remove_const :Gravtastic } if defined? Gravtastic
6
9
  require File.join(File.dirname(__FILE__),'../lib/gravtastic')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gravtastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Lloyd
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-30 00:00:00 +10:00
12
+ date: 2008-09-15 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -19,12 +19,11 @@ executables: []
19
19
 
20
20
  extensions: []
21
21
 
22
- extra_rdoc_files:
23
- - README.textile
24
- - LICENSE
22
+ extra_rdoc_files: []
23
+
25
24
  files:
26
25
  - LICENSE
27
- - README.textile
26
+ - README.md
28
27
  - Rakefile
29
28
  - lib/gravtastic.rb
30
29
  - spec/gravtastic_integration_spec.rb
@@ -55,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
54
  requirements: []
56
55
 
57
56
  rubyforge_project: gravtastic
58
- rubygems_version: 1.3.2
57
+ rubygems_version: 1.3.4
59
58
  signing_key:
60
59
  specification_version: 2
61
60
  summary: Easily add Gravatars to your Ruby objects.
@@ -1,97 +0,0 @@
1
- Easily add "Gravatars":http://gravatar.com to your Ruby objects.
2
-
3
-
4
- h2. Install
5
-
6
- sudo gem install gravtastic
7
-
8
-
9
- h2. Usage
10
-
11
- Somewhere in your application you need to @require 'gravtastic'@. In Rails >= 2.1 you can forego this and just add a dependency gem dependency for Gravtastic.
12
-
13
- config.gem 'gravtastic'
14
-
15
- If you are using Merb & DataMapper you can add do the same by adding the following to your init.rb file:
16
-
17
- dependency 'gravtastic'
18
-
19
- Make sure you add this after either the @use_orm :datamapper@ line or after a DataMapper extension. The next step is to give your model a Gravatar:
20
-
21
- class User
22
- is_gravtastic
23
- end
24
-
25
- If you are using a standard Ruby class you have to add the line @include Gravtastic::Resource@ before @is_gravtastic@.
26
-
27
- This defaults to looking for the gravatar ID on the @email@ method. So, if your @User@ has an @email@ then it will send that to Gravatar to get their picture. You can change the default gravatar source like this:
28
-
29
- is_gravtastic :with => :author_email
30
-
31
- Now, you can access your object's gravatar with the @gravatar_url@ method:
32
-
33
- current_user.gravatar_url
34
- => "http://gravatar.com/e9e719b44653a9300e1567f09f6b2e9e.png?r=PG"
35
-
36
- Note that it defaults to a PG rating. You can specify extra options with a hash:
37
-
38
- current_user.gravatar_url(:rating => 'R', :size => 512)
39
- => "http://gravatar.com/e9e719b44653a9300e1567f09f6b2e9e.png?r=R18&s=512"
40
-
41
- current_user.gravatar_url(:secure => true)
42
- => "https://secure.gravatar.com/e9e719b44653a9300e1567f09f6b2e9e.png?r=PG"
43
-
44
- However, to DRY things up you can specify defaults in the class declaration.
45
-
46
- is_gravtastic :with => :author_email, :rating => 'R', :size => 20
47
-
48
- Nice, now all the calls to gravatar_url will have the defaults you have specified. Any options that you pass when you use @gravatar_url@ will over-ride these class-defaults.
49
-
50
- PS. Bonus points for anybody who can tell me what that users email is!
51
-
52
-
53
- h2. Authors
54
-
55
- * "Chris Lloyd":http://chrislloyd.com.au
56
- * You
57
-
58
-
59
- h2. Contribute
60
-
61
- You can checkout the source or fork it yourself from Github.
62
-
63
- git clone git://github.com/chrislloyd/gravtastic.git
64
-
65
- If you submit a successful patch then you'll be given full commit rights to the project.
66
-
67
-
68
- h2. Thanks
69
-
70
- * "Xavier Shay":http://rhnh.net and others for "Enki":http://enkiblog.com (the reason this was written)
71
- * "Matthew Moore":http://www.matthewpaulmoore.com/ for helpful suggestions and for submitting it to the official list of Gravatar implementations.
72
- * "Vincent Charles":http://vincentcharles.com/ For an updated README.
73
-
74
-
75
-
76
- h2. License
77
-
78
- Copyright (c) 2008 Chris Lloyd.
79
-
80
- Permission is hereby granted, free of charge, to any person obtaining
81
- a copy of this software and associated documentation files (the
82
- 'Software'), to deal in the Software without restriction, including
83
- without limitation the rights to use, copy, modify, merge, publish,
84
- distribute, sublicense, and/or sell copies of the Software, and to
85
- permit persons to whom the Software is furnished to do so, subject to
86
- the following conditions:
87
-
88
- The above copyright notice and this permission notice shall be
89
- included in all copies or substantial portions of the Software.
90
-
91
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
92
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
93
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
94
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
95
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
96
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
97
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.