gravatar_image_tag 0.0.1 → 0.0.2
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/README.textile +45 -4
- data/lib/gravatar_image_tag.rb +23 -7
- data/spec/gravatar_image_tag_spec.rb +17 -2
- metadata +1 -1
data/README.textile
CHANGED
@@ -33,7 +33,7 @@ Once you have installed it as a plugin for your rails app usage is simple.
|
|
33
33
|
|
34
34
|
<pre>gravatar_image_tag('spam@spam.com'.gsub('spam', 'mdeering'), :alt => 'Michael Deering')</pre>
|
35
35
|
|
36
|
-
*Boom* here is my gravatar !http://www.gravatar.com/
|
36
|
+
*Boom* here is my gravatar !http://www.gravatar.com/avata/4da9ad2bd4a2d1ce3c428e32c423588a(Michael Deering)!
|
37
37
|
|
38
38
|
h2. Configuration Points
|
39
39
|
|
@@ -43,7 +43,7 @@ If no default image is given in either an initializer or through the options pas
|
|
43
43
|
|
44
44
|
<pre>gravatar_image_tag('junk', :alt => 'Default Gravatar Image')</pre>
|
45
45
|
|
46
|
-
*Splat* the default gravatar image !http://www.gravatar.com/avatar
|
46
|
+
*Splat* the default gravatar image !http://www.gravatar.com/avatar/0c821f675f132d790b3f25e79da739a7(Default Gravatar Image)!
|
47
47
|
|
48
48
|
You can specify the default image through an initializer as follows:
|
49
49
|
|
@@ -54,7 +54,13 @@ You can also specify the default image to fallback to or override the one set in
|
|
54
54
|
|
55
55
|
<pre>gravatar_image_tag('junk', :alt => 'Github Default Gravatar', :gravatar => { :default => 'http://github.com/images/gravatars/gravatar-80.png' })</pre>
|
56
56
|
|
57
|
-
*Ka-Pow* !http://www.gravatar.com/avatar
|
57
|
+
*Ka-Pow* !http://www.gravatar.com/avatar/0c821f675f132d790b3f25e79da739a7?default=http%3A%2F%2Fgithub.com%2Fimages%2Fgravatars%2Fgravatar-80.png(Github Default Gravatar)!
|
58
|
+
|
59
|
+
p. Other options supported besides an image url to fall back on include the following:
|
60
|
+
* :identicon !http://www.gravatar.com/avatar/0c821f675f132d790b3f25e79da739a7?default=identicon(Identicon Avatar)!
|
61
|
+
* :monsterid !http://www.gravatar.com/avatar/0c821f675f132d790b3f25e79da739a7?default=monsterid(Monster Id Avatar)!
|
62
|
+
* :wavatar !http://www.gravatar.com/avatar/0c821f675f132d790b3f25e79da739a7?default=wavatar(Wavatar Avatar)!
|
63
|
+
* 404: !http://www.gravatar.com/avatar/0c821f675f132d790b3f25e79da739a7?default=404(Not Found)!
|
58
64
|
|
59
65
|
h3. Setting the default image size
|
60
66
|
|
@@ -69,7 +75,42 @@ You can also specify the image size or override the one set in the plugin config
|
|
69
75
|
|
70
76
|
<pre>gravatar_image_tag('spam@spam.com'.gsub('spam', 'mdeering'), :alt => 'Michael Deering', :class => 'some-class', :gravatar => { :size => 15 })</pre>
|
71
77
|
|
72
|
-
*Mini Me!* !(some-class)http://www.gravatar.com/avatar
|
78
|
+
*Mini Me!* !(some-class)http://www.gravatar.com/avatar/4da9ad2bd4a2d1ce3c428e32c423588a?size=15(Michael Deering)!
|
79
|
+
|
80
|
+
h3. Grabbing gravatars from the secure gravatar server.
|
81
|
+
|
82
|
+
p. You can make a request for a gravatar from the secure server at https://secure.gravatar.com by passing the _:gravatar => { :secure => true }_ option to the gravatar_image_tag call.
|
83
|
+
|
84
|
+
<pre>gravatar_image_tag('spam@spam.com'.gsub('spam', 'mdeering'), :alt => 'Michael Deering', :gravatar => { :secure => true } )</pre>
|
85
|
+
|
86
|
+
Delivered by a secure url! !https://secure.gravatar.com/avatar/4da9ad2bd4a2d1ce3c428e32c423588a(Michael Deering)!
|
87
|
+
|
88
|
+
p. You globally set the gravatar image tag to always use the secure server by setting the following. By default this is set to false.
|
89
|
+
|
90
|
+
<pre># config/initializers/gravatar_defaults.rb
|
91
|
+
ActionView::Base.secure_gravatar = true</pre>
|
92
|
+
|
93
|
+
h3. Using Gravatar's built in rating system
|
94
|
+
|
95
|
+
p. By default only those gravatars that have a rating of 'g' are returned. You can change this by passing in the rating parameter as follows. Possible options for ratings are _g, pg, r, or x_.
|
96
|
+
|
97
|
+
<pre>gravatar_image_tag('spam@spam.com'.gsub('spam', 'mdeering'), :alt => 'Michael Deering', :gravatar => { :rating => 'pg' } )</pre>
|
98
|
+
|
99
|
+
p. You can globally set the gravatar image tag rating by setting the following. There is no default value, the default of 'g' is being set by the gravatar service itself.
|
100
|
+
|
101
|
+
<pre># config/initializers/gravatar_defaults.rb
|
102
|
+
ActionView::Base.default_gravatar_rating = 'r'</pre>
|
103
|
+
|
104
|
+
h3. Specifying a filetype
|
105
|
+
|
106
|
+
p. By default no filetype extension is given in the produced gravatar urls but of your application requires it you can specify one to be added to the generated url.
|
107
|
+
|
108
|
+
<pre>gravatar_image_tag('spam@spam.com'.gsub('spam', 'mdeering'), :alt => 'Michael Deering', :gravatar => { :filetype => :gif } )</pre>
|
109
|
+
|
110
|
+
p. You can globally set the filetype extension as follows.
|
111
|
+
|
112
|
+
<pre># config/initializers/gravatar_defaults.rb
|
113
|
+
ActionView::Base.default_gravatar_filetype = :gif</pre>
|
73
114
|
|
74
115
|
h2. Credits
|
75
116
|
|
data/lib/gravatar_image_tag.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
module GravatarImageTag
|
2
2
|
|
3
|
-
GRAVATAR_BASE_URL = 'http://www.gravatar.com/avatar.php'
|
4
|
-
|
5
3
|
def self.included(base)
|
6
|
-
base.cattr_accessor :
|
4
|
+
base.cattr_accessor :default_gravatar_filetype, :default_gravatar_image,
|
5
|
+
:default_gravatar_rating, :default_gravatar_size, :secure_gravatar
|
7
6
|
base.send :include, InstanceMethods
|
8
7
|
end
|
9
8
|
|
@@ -11,20 +10,37 @@ module GravatarImageTag
|
|
11
10
|
|
12
11
|
def gravatar_image_tag(email, options = {})
|
13
12
|
options[:src] = gravatar_url( email, options.delete( :gravatar ) )
|
14
|
-
options[:alt] ||=
|
13
|
+
options[:alt] ||= 'Gravatar'
|
15
14
|
tag 'img', options, false, false # Patch submitted to rails to allow image_tag here https://rails.lighthouseapp.com/projects/8994/tickets/2878-image_tag-doesnt-allow-escape-false-option-anymore
|
16
15
|
end
|
17
16
|
|
18
17
|
def gravatar_url(email, overrides)
|
19
18
|
overrides ||= {}
|
20
|
-
|
19
|
+
gravatar_params = {
|
21
20
|
:default => ActionView::Base.default_gravatar_image,
|
22
|
-
:
|
21
|
+
:filetype => ActionView::Base.default_gravatar_filetype,
|
22
|
+
:rating => ActionView::Base.default_gravatar_rating,
|
23
|
+
:secure => ActionView::Base.secure_gravatar,
|
23
24
|
:size => ActionView::Base.default_gravatar_size
|
24
25
|
}.merge(overrides).delete_if { |key, value| value.nil? }
|
25
|
-
"#{
|
26
|
+
"#{gravatar_url_base(gravatar_params.delete(:secure))}/#{gravatar_id(email, gravatar_params.delete(:filetype))}#{url_params(gravatar_params)}"
|
26
27
|
end
|
27
28
|
|
29
|
+
private
|
30
|
+
|
31
|
+
def gravatar_url_base(secure = false)
|
32
|
+
'http' + (!!secure ? 's://secure.' : '://') + 'gravatar.com/avatar'
|
33
|
+
end
|
34
|
+
|
35
|
+
def gravatar_id(email, filetype = nil)
|
36
|
+
"#{ Digest::MD5.hexdigest(email) }#{ ".#{filetype}" unless filetype.nil? }"
|
37
|
+
end
|
38
|
+
|
39
|
+
def url_params(gravatar_params)
|
40
|
+
return nil if gravatar_params.keys.count == 0
|
41
|
+
"?#{gravatar_params.map { |key, value| "#{key}=#{URI.escape(value.is_a?(String) ? value : value.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}"}.join('&')}"
|
42
|
+
end
|
43
|
+
|
28
44
|
end
|
29
45
|
|
30
46
|
end
|
@@ -8,8 +8,10 @@ describe GravatarImageTag do
|
|
8
8
|
|
9
9
|
email = 'mdeering@mdeering.com'
|
10
10
|
md5 = '4da9ad2bd4a2d1ce3c428e32c423588a'
|
11
|
+
default_filetype = :gif
|
11
12
|
default_image = 'http://mdeering.com/images/default_gravatar.png'
|
12
13
|
default_image_escaped = 'http%3A%2F%2Fmdeering.com%2Fimages%2Fdefault_gravatar.png'
|
14
|
+
default_rating = 'x'
|
13
15
|
default_size = 50
|
14
16
|
other_image = 'http://mdeering.com/images/other_gravatar.png'
|
15
17
|
other_image_escaped = 'http%3A%2F%2Fmdeering.com%2Fimages%2Fother_gravatar.png'
|
@@ -18,6 +20,7 @@ describe GravatarImageTag do
|
|
18
20
|
|
19
21
|
{
|
20
22
|
{ :gravatar_id => md5 } => {},
|
23
|
+
{ :gravatar_id => md5 } => { :gravatar => { :rating => 'x' } },
|
21
24
|
{ :gravatar_id => md5, :size => 30 } => { :gravatar => {:size => 30 } },
|
22
25
|
{ :gravatar_id => md5, :default => other_image_escaped } => { :gravatar => {:default => other_image } },
|
23
26
|
{ :gravatar_id => md5, :default => other_image_escaped, :size => 30 } => { :gravatar => {:default => other_image, :size => 30 } }
|
@@ -25,13 +28,16 @@ describe GravatarImageTag do
|
|
25
28
|
it "#gravatar_image_tag should create the provided url with the provided options #{options}" do
|
26
29
|
view = ActionView::Base.new
|
27
30
|
image_tag = view.gravatar_image_tag(email, options)
|
31
|
+
image_tag.include?("#{params.delete(:gravatar_id)}").should be_true
|
28
32
|
params.all? {|key, value| image_tag.include?("#{key}=#{value}")}.should be_true
|
29
33
|
end
|
30
34
|
end
|
31
35
|
|
32
36
|
{
|
33
|
-
:default_gravatar_image
|
34
|
-
:
|
37
|
+
:default_gravatar_image => default_image,
|
38
|
+
:default_gravatar_filetype => default_filetype,
|
39
|
+
:default_gravatar_rating => default_rating,
|
40
|
+
:default_gravatar_size => default_size
|
35
41
|
}.each do |singleton_variable, value|
|
36
42
|
it "should create gravatar class (singleton) variable #{singleton_variable} on its included class" do
|
37
43
|
ActionView::Base.send(singleton_variable).should == nil
|
@@ -50,8 +56,17 @@ describe GravatarImageTag do
|
|
50
56
|
it "#gravatar_image_tag should create the provided url when defaults have been set with the provided options #{options}" do
|
51
57
|
view = ActionView::Base.new
|
52
58
|
image_tag = view.gravatar_image_tag(email, options)
|
59
|
+
image_tag.include?("#{params.delete(:gravatar_id)}.#{default_filetype}").should be_true
|
53
60
|
params.all? {|key, value| image_tag.include?("#{key}=#{value}")}.should be_true
|
54
61
|
end
|
55
62
|
end
|
56
63
|
|
64
|
+
it 'should request the gravatar image from the non-secure server if the https => false option is given' do
|
65
|
+
(!!view.gravatar_image_tag(email, { :gravatar => { :secure => false } }).match(/^https:\/\/secure.gravatar.com\/avatar\//)).should be_false
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should request the gravatar image from the secure server if the https => true option is given' do
|
69
|
+
(!!view.gravatar_image_tag(email, { :gravatar => { :secure => true } }).match(/src="https:\/\/secure.gravatar.com\/avatar\//)).should be_true
|
70
|
+
end
|
71
|
+
|
57
72
|
end
|