gravtastic 1.5.2 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -3,14 +3,14 @@ Easily add "Gravatars":http://gravatar.com to your Ruby objects.
3
3
 
4
4
  h2. Install
5
5
 
6
- sudo gem install chrislloyd-gravtastic --source=http://gems.github.com
6
+ sudo gem install gravtastic
7
7
 
8
8
 
9
9
  h2. Usage
10
10
 
11
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
12
 
13
- config.gem 'gravtastic', :source => 'http://gems.github.com/'
13
+ config.gem 'gravtastic'
14
14
 
15
15
  The next step is to give your model a Gravatar:
16
16
 
@@ -36,14 +36,14 @@ Note that it defaults to a PG rating. You can specify extra options with a hash:
36
36
 
37
37
  current_user.gravatar_url(:secure => true)
38
38
  => "https://secure.gravatar.com/e9e719b44653a9300e1567f09f6b2e9e.png?r=PG"
39
+
40
+ However, to DRY things up you can specify defaults in the class declaration.
39
41
 
40
- PS. Bonus points for anybody who can tell me what that users email is!
41
- PPS. Shame on Automattic for still using MD5!
42
-
42
+ has_gravatar :author_email, :defaults => { :rating => 'R18', :size => 20 }
43
43
 
44
- h2. The Future
44
+ Nice, now all the calls to gravatar_url will have the defaults you have specified.
45
45
 
46
- * "Datamapper":http://datamaper.org support
46
+ PS. Bonus points for anybody who can tell me what that users email is!
47
47
 
48
48
 
49
49
  h2. Authors
@@ -64,6 +64,7 @@ If you submit a successful patch then you'll be given full commit rights to the
64
64
  h2. Thanks
65
65
 
66
66
  * "Xavier Shay":http://rhnh.net and others for "Enki":http://enkiblog.com (the reason this was written)
67
+ * "Matthew Moore":http://www.matthewpaulmoore.com/ for helpful suggestions
67
68
 
68
69
 
69
70
  h2. License
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'spec/rake/spectask'
5
5
  require 'date'
6
6
 
7
7
  GEM = "gravtastic"
8
- GEM_VERSION = "1.5.2"
8
+ GEM_VERSION = "1.6.0"
9
9
  AUTHOR = "Chris Lloyd"
10
10
  EMAIL = "christopher.lloyd@gmail.com"
11
11
  HOMEPAGE = "http://github.com/chrislloyd/gravtastic"
data/lib/gravtastic.rb CHANGED
@@ -57,8 +57,12 @@ module Gravtastic
57
57
  #
58
58
  # has_gravatar :on => :author_email
59
59
  #
60
+ # has_gravatar :defaults => { :rating => 'R18' }
61
+ #
60
62
  def has_gravatar(options={:on => :email})
61
63
  @gravatar_source = options[:on]
64
+ options[:defaults] ||= {}
65
+ @gravatar_defaults = {:rating => 'PG', :secure => false}.merge(options[:defaults])
62
66
  end
63
67
 
64
68
  #
@@ -70,7 +74,14 @@ module Gravtastic
70
74
  def gravatar_source
71
75
  @gravatar_source
72
76
  end
73
-
77
+
78
+ #
79
+ # Returns a hash of all the default gravtastic options.
80
+ #
81
+ def gravatar_defaults
82
+ @gravatar_defaults
83
+ end
84
+
74
85
  #
75
86
  # Returns <tt>true</tt> if the gravatar_source is set. <tt>false</tt> if not. Easy!
76
87
  #
@@ -92,7 +103,7 @@ module Gravtastic
92
103
  #
93
104
  # Returns a string with the URL for the instance's Gravatar.
94
105
  #
95
- # It defaults to <tt>:rating => 'PG'</tt>
106
+ # It defaults to <tt>:rating => 'PG'</tt> and <tt>:secure => false</tt>
96
107
  #
97
108
  # Examples:
98
109
  #
@@ -105,9 +116,10 @@ module Gravtastic
105
116
  # current_user.gravatar_url(:secure => true)
106
117
  # => "https://secure.gravatar.com/e9e719b44653a9300e1567f09f6b2e9e.png?r=PG"
107
118
  #
108
- def gravatar_url(options={})
109
- options[:rating] ||= 'PG'
110
- options[:secure] ||= false
119
+ def gravatar_url(options={})
120
+
121
+ options = self.class.gravatar_defaults.merge(options)
122
+
111
123
  if gravatar_id
112
124
  @gravatar_url = 'http' + (options[:secure] ? 's://secure.' : '://') + 'gravatar.com/avatar/' + gravatar_id + '.png' + parse_url_options_hash(options)
113
125
  end
@@ -13,27 +13,66 @@ describe "Gravtastic::Model" do
13
13
  it "is nil if unset" do
14
14
  @klass.gravatar_source.should be_nil
15
15
  end
16
+
17
+ it "returns the value of @gravatar_source" do
18
+ @klass.instance_variable_set('@gravatar_source', :foo)
19
+ @klass.gravatar_source.should == :foo
20
+ end
16
21
 
17
22
  end
18
23
 
24
+ describe ".gravatar_defaults" do
25
+
26
+ it "it nil if unset" do
27
+ @klass.gravatar_defaults.should be_nil
28
+ end
29
+
30
+ it "returns the value of @gravatar_defaults" do
31
+ @klass.instance_variable_set('@gravatar_defaults', :foo)
32
+ @klass.gravatar_source.should == :foo
33
+ end
34
+
35
+ end
36
+
19
37
  describe ".has_gravatar" do
20
38
 
21
- it "sets .gravatar_source to email by default" do
39
+ it "sets .gravatar_source to :email by default" do
22
40
  @klass.has_gravatar
23
41
  @klass.gravatar_source.should == :email
24
42
  end
25
43
 
44
+ it "sets .gravatar_defaults to { :rating => 'PG', :secure => false } by default" do
45
+ @klass.has_gravatar
46
+ @klass.gravatar_defaults.should == { :rating => 'PG', :secure => false }
47
+ end
48
+
49
+ it "keeps either :rating or :secure if only the other is passed as a default" do
50
+ @klass.has_gravatar :defaults => { :secure => true }
51
+ @klass.gravatar_defaults.should == { :rating => 'PG', :secure => true }
52
+ end
53
+
26
54
  it "changes .gravatar_source" do
27
55
  lambda {
28
56
  @klass.has_gravatar :on => :other_method
29
57
  }.should change(@klass, :gravatar_source)
30
58
  end
31
59
 
60
+ it "changes .gravatar_defaults" do
61
+ lambda {
62
+ @klass.has_gravatar :defaults => { :rating => 'R18' }
63
+ }.should change(@klass, :gravatar_defaults)
64
+ end
65
+
32
66
  it "sets .gravatar_source to the value of :on" do
33
67
  @klass.has_gravatar :on => :other_method
34
68
  @klass.gravatar_source.should == :other_method
35
69
  end
36
70
 
71
+ it "sets .gravatar_defaults to the value of :defaults" do
72
+ @klass.has_gravatar :defaults => { :rating => 'R18'}
73
+ @klass.gravatar_defaults.should == { :rating => 'R18', :secure => false }
74
+ end
75
+
37
76
  end
38
77
 
39
78
  describe ".has_gravatar?" do
@@ -90,6 +129,7 @@ describe "Gravtastic::Model" do
90
129
  @user.stub!(:email).and_return('joe@example.com')
91
130
  @user.stub!(:name).and_return('Joe Bloggs')
92
131
  @user.class.stub!(:gravatar_source).and_return(:email)
132
+ @user.class.stub!(:gravatar_defaults).and_return({:rating => 'PG'})
93
133
  end
94
134
 
95
135
  it "is not nil when .gravatar_source is not nil" do
@@ -149,6 +189,11 @@ describe "Gravtastic::Model" do
149
189
  @user.gravatar_url(:rating => 'PG').should == @user.gravatar_url
150
190
  end
151
191
 
192
+ it "uses the defaults from .gravatar_defaults" do
193
+ @user.class.stub!(:gravatar_defaults).and_return({ :size => 20, :rating => 'R18'})
194
+ @user.gravatar_url.should == valid_gravatar_url + '?r=R18&s=20'
195
+ end
196
+
152
197
  def valid_gravatar_url # :nodoc:
153
198
  'http://gravatar.com/avatar/f5b8fb60c6116331da07c65b96a8a1d1.png'
154
199
  end
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: 1.5.2
4
+ version: 1.6.0
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-06-15 00:00:00 +10:00
12
+ date: 2008-06-28 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -52,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
52
  requirements: []
53
53
 
54
54
  rubyforge_project: gravtastic
55
- rubygems_version: 1.1.1
55
+ rubygems_version: 1.2.0
56
56
  signing_key:
57
57
  specification_version: 2
58
58
  summary: Easily add Gravatars to your Ruby objects.