gravatar_image_tag 0.1.0 → 1.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +4 -4
- data/README.textile +34 -45
- data/Rakefile +1 -1
- data/lib/gravatar_image_tag.rb +73 -27
- data/spec/gravatar_image_tag_spec.rb +17 -7
- metadata +22 -7
data/MIT-LICENSE
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
Copyright (c)
|
2
|
-
|
1
|
+
Copyright (c) 2010 Michael Deering
|
2
|
+
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
a copy of this software and associated documentation files (the
|
5
5
|
"Software"), to deal in the Software without restriction, including
|
@@ -7,10 +7,10 @@ without limitation the rights to use, copy, modify, merge, publish,
|
|
7
7
|
distribute, sublicense, and/or sell copies of the Software, and to
|
8
8
|
permit persons to whom the Software is furnished to do so, subject to
|
9
9
|
the following conditions:
|
10
|
-
|
10
|
+
|
11
11
|
The above copyright notice and this permission notice shall be
|
12
12
|
included in all copies or substantial portions of the Software.
|
13
|
-
|
13
|
+
|
14
14
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
15
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
16
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
data/README.textile
CHANGED
@@ -6,26 +6,31 @@ Rails view helper for grabbing "Gravatar":http://en.gravatar.com/ images. The g
|
|
6
6
|
|
7
7
|
h2. Install as a Ruby Gem
|
8
8
|
|
9
|
-
|
9
|
+
h3. Rails 2
|
10
10
|
|
11
11
|
p. Include the following line in your Rails environment
|
12
12
|
|
13
|
-
<pre
|
13
|
+
<pre># config/environment
|
14
|
+
config.gem 'gravatar_image_tag'</pre>
|
14
15
|
|
15
|
-
p. Then ensure the gem is installed
|
16
|
+
p. Then ensure the gem is installed by running the following rake task from the your application root.
|
16
17
|
|
17
18
|
<pre>rake gems:install</pre>
|
18
19
|
|
19
|
-
|
20
|
+
h3. Rails 3
|
20
21
|
|
21
|
-
|
22
|
-
<pre>./script/plugin install git://github.com/mdeering/gravatar_image_tag.git</pre>
|
22
|
+
p. Include the following line in your Rails environment
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
<pre># Gemfile
|
25
|
+
gem 'gravatar_image_tag'</pre>
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
p. Then ensure the gem is installed by running the following command from the your application root.
|
28
|
+
|
29
|
+
<pre>bundle install</pre>
|
30
|
+
|
31
|
+
h2. Install as a Ruby on Rails Plugin
|
32
|
+
|
33
|
+
<pre>./script/plugin install git://github.com/mdeering/gravatar_image_tag.git</pre>
|
29
34
|
|
30
35
|
h2. Usage
|
31
36
|
|
@@ -35,28 +40,32 @@ Once you have installed it as a plugin for your rails app usage is simple.
|
|
35
40
|
|
36
41
|
*Boom* here is my gravatar !http://www.gravatar.com/avatar/4da9ad2bd4a2d1ce3c428e32c423588a(Michael Deering)!
|
37
42
|
|
38
|
-
h2. Configuration
|
39
|
-
|
40
|
-
h3. Setting the default image
|
43
|
+
h2. Configuration
|
41
44
|
|
42
|
-
|
45
|
+
h3. Global configuration points
|
43
46
|
|
44
|
-
<pre
|
47
|
+
<pre># config/initializers/gravatar_image_tag.rb
|
48
|
+
GravatarImageTag.configure do |config|
|
49
|
+
config.default_image = nil # Set this to use your own default gravatar image rather then serving up Gravatar's default image [ 'http://example.com/images/default_gravitar.jpg', :identicon, :monsterid, :wavatar, 404 ].
|
50
|
+
config.filetype = nil # Set this if you require a specific image file format ['gif', 'jpg' or 'png']. Gravatar's default is png
|
51
|
+
config.rating = nil # Set this if you change the rating of the images that will be returned ['G', 'PG', 'R', 'X']. Gravatar's default is G
|
52
|
+
config.size = nil # Set this to globally set the size of the gravatar image returned (1..512). Gravatar's default is 80
|
53
|
+
config.secure = false # Set this to true if you require secure images on your pages.
|
54
|
+
end
|
55
|
+
</pre>
|
45
56
|
|
46
|
-
|
57
|
+
h3. Setting the default image inline
|
47
58
|
|
48
|
-
|
59
|
+
p. *Splat* the default gravatar image !http://www.gravatar.com/avatar/0c821f675f132d790b3f25e79da739a7(Default Gravatar Image)!
|
49
60
|
|
50
|
-
|
51
|
-
ActionView::Base.default_gravatar_image = 'http://assets.yourhost.com/images/default_gravatar.png'</pre>
|
52
|
-
|
53
|
-
You can also specify the default image to fallback to or override the one set in the above initializer by passing the _:gravatar => { :default => 'http://assets.yourhost.com/images/override_gravatar.png' }_ option to the gravatar_image_tag call. All other options will be forwarded onto the image_tag.
|
61
|
+
p. You can set the default gravatar image inline as follows:
|
54
62
|
|
55
63
|
<pre>gravatar_image_tag('junk', :alt => 'Github Default Gravatar', :gravatar => { :default => 'http://github.com/images/gravatars/gravatar-80.png' })</pre>
|
56
64
|
|
57
|
-
*Ka-Pow* !http://www.gravatar.com/avatar/0c821f675f132d790b3f25e79da739a7?default=http%3A%2F%2Fgithub.com%2Fimages%2Fgravatars%2Fgravatar-80.png(Github Default Gravatar)!
|
65
|
+
p. *Ka-Pow* !http://www.gravatar.com/avatar/0c821f675f132d790b3f25e79da739a7?default=http%3A%2F%2Fgithub.com%2Fimages%2Fgravatars%2Fgravatar-80.png(Github Default Gravatar)!
|
58
66
|
|
59
67
|
p. Other options supported besides an image url to fall back on include the following:
|
68
|
+
|
60
69
|
* :identicon !http://www.gravatar.com/avatar/0c821f675f132d790b3f25e79da739a7?default=identicon(Identicon Avatar)!
|
61
70
|
* :monsterid !http://www.gravatar.com/avatar/0c821f675f132d790b3f25e79da739a7?default=monsterid(Monster Id Avatar)!
|
62
71
|
* :wavatar !http://www.gravatar.com/avatar/0c821f675f132d790b3f25e79da739a7?default=wavatar(Wavatar Avatar)!
|
@@ -64,14 +73,7 @@ p. Other options supported besides an image url to fall back on include the foll
|
|
64
73
|
|
65
74
|
h3. Setting the default image size
|
66
75
|
|
67
|
-
|
68
|
-
|
69
|
-
You can specify your default image size through the plugin configuration by adding the following line to your rails environment.
|
70
|
-
|
71
|
-
<pre># config/initializers/gravatar_defaults.rb
|
72
|
-
ActionView::Base.default_gravatar_size = 120</pre>
|
73
|
-
|
74
|
-
You can also specify the image size or override the one set in the plugin configuration by passing the _:gravatar => { :size => 50 }_ option to the gravatar_image_tag call. All other options will be forwarded on to the image_tag call.
|
76
|
+
p. You can set the gravatar image size inline as follows:
|
75
77
|
|
76
78
|
<pre>gravatar_image_tag('spam@spam.com'.gsub('spam', 'mdeering'), :alt => 'Michael Deering', :class => 'some-class', :gravatar => { :size => 15 })</pre>
|
77
79
|
|
@@ -85,32 +87,19 @@ p. You can make a request for a gravatar from the secure server at https://secur
|
|
85
87
|
|
86
88
|
Delivered by a secure url! !https://secure.gravatar.com/avatar/4da9ad2bd4a2d1ce3c428e32c423588a(Michael Deering)!
|
87
89
|
|
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
90
|
h3. Using Gravatar's built in rating system
|
94
91
|
|
95
|
-
p.
|
92
|
+
p. You can set the gravatar rating inline as follows:
|
96
93
|
|
97
94
|
<pre>gravatar_image_tag('spam@spam.com'.gsub('spam', 'mdeering'), :alt => 'Michael Deering', :gravatar => { :rating => 'pg' } )</pre>
|
98
95
|
|
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
96
|
|
104
97
|
h3. Specifying a filetype
|
105
98
|
|
106
|
-
p.
|
99
|
+
p. You can set the gravatar filetype inline as follows:
|
107
100
|
|
108
101
|
<pre>gravatar_image_tag('spam@spam.com'.gsub('spam', 'mdeering'), :alt => 'Michael Deering', :gravatar => { :filetype => :gif } )</pre>
|
109
102
|
|
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>
|
114
103
|
|
115
104
|
h2. Credits
|
116
105
|
|
data/Rakefile
CHANGED
@@ -21,7 +21,7 @@ begin
|
|
21
21
|
end
|
22
22
|
Jeweler::GemcutterTasks.new
|
23
23
|
rescue LoadError
|
24
|
-
puts "Jeweler, or one of its dependencies, is not available. Install it with:
|
24
|
+
puts "Jeweler, or one of its dependencies, is not available. Install it with: gem install jeweler"
|
25
25
|
end
|
26
26
|
|
27
27
|
desc 'Default: spec tests.'
|
data/lib/gravatar_image_tag.rb
CHANGED
@@ -1,48 +1,94 @@
|
|
1
1
|
module GravatarImageTag
|
2
2
|
|
3
|
+
class << self
|
4
|
+
attr_accessor :configuration
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.configure
|
8
|
+
self.configuration ||= Configuration.new
|
9
|
+
yield(configuration)
|
10
|
+
end
|
11
|
+
|
12
|
+
class Configuration
|
13
|
+
attr_accessor :default_image, :filetype, :rating, :size, :secure
|
14
|
+
end
|
15
|
+
|
3
16
|
def self.included(base)
|
4
|
-
|
5
|
-
|
17
|
+
GravatarImageTag.configure { |c| nil }
|
18
|
+
base.extend ClassMethods
|
6
19
|
base.send :include, InstanceMethods
|
7
20
|
end
|
8
21
|
|
22
|
+
module ClassMethods
|
23
|
+
def default_gravatar_filetype=(value)
|
24
|
+
warn "DEPRECATION WARNING: configuration of filetype= through this method is deprecated! Use the block configuration instead. http://github.com/mdeering/gravatar_image_tag"
|
25
|
+
GravatarImageTag.configure do |c|
|
26
|
+
c.filetype = value
|
27
|
+
end
|
28
|
+
end
|
29
|
+
def default_gravatar_image=(value)
|
30
|
+
warn "DEPRECATION WARNING: configuration of default_gravatar_image= through this method is deprecated! Use the block configuration instead. http://github.com/mdeering/gravatar_image_tag"
|
31
|
+
GravatarImageTag.configure do |c|
|
32
|
+
c.default_image = value
|
33
|
+
end
|
34
|
+
end
|
35
|
+
def default_gravatar_rating=(value)
|
36
|
+
warn "DEPRECATION WARNING: configuration of default_gravatar_rating= through this method is deprecated! Use the block configuration instead. http://github.com/mdeering/gravatar_image_tag"
|
37
|
+
GravatarImageTag.configure do |c|
|
38
|
+
c.rating = value
|
39
|
+
end
|
40
|
+
end
|
41
|
+
def default_gravatar_size=(value)
|
42
|
+
warn "DEPRECATION WARNING: configuration of default_gravatar_size= through this method is deprecated! Use the block configuration instead. http://github.com/mdeering/gravatar_image_tag"
|
43
|
+
GravatarImageTag.configure do |c|
|
44
|
+
c.size = value
|
45
|
+
end
|
46
|
+
end
|
47
|
+
def secure_gravatar=(value)
|
48
|
+
warn "DEPRECATION WARNING: configuration of secure_gravatar= through this method is deprecated! Use the block configuration instead. http://github.com/mdeering/gravatar_image_tag"
|
49
|
+
GravatarImageTag.configure do |c|
|
50
|
+
c.secure = value
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
9
55
|
module InstanceMethods
|
10
56
|
|
11
57
|
def gravatar_image_tag(email, options = {})
|
12
|
-
options[:src] = gravatar_url( email, options.delete( :gravatar ) )
|
58
|
+
options[:src] = GravatarImageTag::gravatar_url( email, options.delete( :gravatar ) )
|
13
59
|
options[:alt] ||= 'Gravatar'
|
14
60
|
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
|
15
61
|
end
|
16
62
|
|
17
|
-
|
18
|
-
overrides ||= {}
|
19
|
-
gravatar_params = {
|
20
|
-
:default => ActionView::Base.default_gravatar_image,
|
21
|
-
:filetype => ActionView::Base.default_gravatar_filetype,
|
22
|
-
:rating => ActionView::Base.default_gravatar_rating,
|
23
|
-
:secure => ActionView::Base.secure_gravatar,
|
24
|
-
:size => ActionView::Base.default_gravatar_size
|
25
|
-
}.merge(overrides).delete_if { |key, value| value.nil? }
|
26
|
-
"#{gravatar_url_base(gravatar_params.delete(:secure))}/#{gravatar_id(email, gravatar_params.delete(:filetype))}#{url_params(gravatar_params)}"
|
27
|
-
end
|
63
|
+
end
|
28
64
|
|
29
|
-
|
65
|
+
def self.gravatar_url(email, overrides = {})
|
66
|
+
overrides ||= {}
|
67
|
+
gravatar_params = {
|
68
|
+
:default => GravatarImageTag.configuration.default_image,
|
69
|
+
:filetype => GravatarImageTag.configuration.filetype,
|
70
|
+
:rating => GravatarImageTag.configuration.rating,
|
71
|
+
:secure => GravatarImageTag.configuration.secure,
|
72
|
+
:size => GravatarImageTag.configuration.size
|
73
|
+
}.merge(overrides).delete_if { |key, value| value.nil? }
|
74
|
+
"#{gravatar_url_base(gravatar_params.delete(:secure))}/#{gravatar_id(email, gravatar_params.delete(:filetype))}#{url_params(gravatar_params)}"
|
75
|
+
end
|
30
76
|
|
31
|
-
|
32
|
-
'http' + (!!secure ? 's://secure.' : '://') + 'gravatar.com/avatar'
|
33
|
-
end
|
77
|
+
private
|
34
78
|
|
35
|
-
|
36
|
-
|
37
|
-
|
79
|
+
def self.gravatar_url_base(secure = false)
|
80
|
+
'http' + (!!secure ? 's://secure.' : '://') + 'gravatar.com/avatar'
|
81
|
+
end
|
38
82
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
83
|
+
def self.gravatar_id(email, filetype = nil)
|
84
|
+
"#{ Digest::MD5.hexdigest(email) }#{ ".#{filetype}" unless filetype.nil? }" unless email.nil?
|
85
|
+
end
|
43
86
|
|
44
|
-
|
87
|
+
def self.url_params(gravatar_params)
|
88
|
+
return nil if gravatar_params.keys.size == 0
|
89
|
+
"?#{gravatar_params.map { |key, value| "#{key}=#{URI.escape(value.is_a?(String) ? value : value.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}"}.join('&')}"
|
90
|
+
end
|
45
91
|
|
46
92
|
end
|
47
93
|
|
48
|
-
ActionView::Base.send(:include, GravatarImageTag)
|
94
|
+
ActionView::Base.send(:include, GravatarImageTag) if defined?(ActionView::Base)
|
@@ -15,6 +15,7 @@ describe GravatarImageTag do
|
|
15
15
|
default_size = 50
|
16
16
|
other_image = 'http://mdeering.com/images/other_gravatar.png'
|
17
17
|
other_image_escaped = 'http%3A%2F%2Fmdeering.com%2Fimages%2Fother_gravatar.png'
|
18
|
+
secure = false
|
18
19
|
|
19
20
|
view = ActionView::Base.new
|
20
21
|
|
@@ -37,23 +38,28 @@ describe GravatarImageTag do
|
|
37
38
|
:default_gravatar_image => default_image,
|
38
39
|
:default_gravatar_filetype => default_filetype,
|
39
40
|
:default_gravatar_rating => default_rating,
|
40
|
-
:default_gravatar_size => default_size
|
41
|
+
:default_gravatar_size => default_size,
|
42
|
+
:secure_gravatar => secure
|
41
43
|
}.each do |singleton_variable, value|
|
42
|
-
it "should
|
43
|
-
ActionView::Base.
|
44
|
+
it "should give a deprication warning for assigning to #{singleton_variable} and passthrough to set the new variable" do
|
45
|
+
ActionView::Base.should_receive(:warn)
|
44
46
|
ActionView::Base.send("#{singleton_variable}=", value)
|
45
|
-
|
47
|
+
GravatarImageTag.configuration.default_image == value if singleton_variable == :default_gravatar_image
|
48
|
+
GravatarImageTag.configuration.filetype == value if singleton_variable == :default_gravatar_filetype
|
49
|
+
GravatarImageTag.configuration.rating == value if singleton_variable == :default_gravatar_rating
|
50
|
+
GravatarImageTag.configuration.size == value if singleton_variable == :default_gravatar_size
|
51
|
+
GravatarImageTag.configuration.secure == value if singleton_variable == :secure_gravatar
|
46
52
|
end
|
47
53
|
end
|
48
54
|
|
49
55
|
# Now that the defaults are set...
|
50
56
|
{
|
51
57
|
{ :gravatar_id => md5, :size => default_size, :default => default_image_escaped } => {},
|
52
|
-
{ :gravatar_id => md5, :size => 30, :default => default_image_escaped } => { :gravatar => { :size => 30 }},
|
58
|
+
{ :gravatar_id => md5, :size => 30, :default => default_image_escaped } => { :gravatar => { :size => 30 } },
|
53
59
|
{ :gravatar_id => md5, :size => default_size, :default => other_image_escaped } => { :gravatar => {:default => other_image } },
|
54
|
-
{ :gravatar_id => md5, :size => 30, :default => other_image_escaped } => { :gravatar => { :default => other_image, :size => 30 }},
|
60
|
+
{ :gravatar_id => md5, :size => 30, :default => other_image_escaped } => { :gravatar => { :default => other_image, :size => 30 } },
|
55
61
|
}.each do |params, options|
|
56
|
-
it "#gravatar_image_tag should create the provided url when defaults have been set with the provided options #{options}" do
|
62
|
+
it "#gravatar_image_tag #{params} should create the provided url when defaults have been set with the provided options #{options}" do
|
57
63
|
view = ActionView::Base.new
|
58
64
|
image_tag = view.gravatar_image_tag(email, options)
|
59
65
|
image_tag.include?("#{params.delete(:gravatar_id)}.#{default_filetype}").should be_true
|
@@ -69,4 +75,8 @@ describe GravatarImageTag do
|
|
69
75
|
(!!view.gravatar_image_tag(email, { :gravatar => { :secure => true } }).match(/src="https:\/\/secure.gravatar.com\/avatar\//)).should be_true
|
70
76
|
end
|
71
77
|
|
78
|
+
it 'GravatarImageTag#gravitar_id should not error out when email is nil' do
|
79
|
+
lambda { GravatarImageTag::gravatar_id(nil) }.should_not raise_error(TypeError)
|
80
|
+
end
|
81
|
+
|
72
82
|
end
|
metadata
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gravatar_image_tag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: -1876988176
|
5
|
+
prerelease: true
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
- pre1
|
11
|
+
version: 1.0.0.pre1
|
5
12
|
platform: ruby
|
6
13
|
authors:
|
7
14
|
- Michael Deering
|
@@ -9,7 +16,7 @@ autorequire:
|
|
9
16
|
bindir: bin
|
10
17
|
cert_chain: []
|
11
18
|
|
12
|
-
date: 2010-
|
19
|
+
date: 2010-07-11 00:00:00 -06:00
|
13
20
|
default_executable:
|
14
21
|
dependencies: []
|
15
22
|
|
@@ -38,21 +45,29 @@ rdoc_options:
|
|
38
45
|
require_paths:
|
39
46
|
- lib
|
40
47
|
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
41
49
|
requirements:
|
42
50
|
- - ">="
|
43
51
|
- !ruby/object:Gem::Version
|
52
|
+
hash: 3
|
53
|
+
segments:
|
54
|
+
- 0
|
44
55
|
version: "0"
|
45
|
-
version:
|
46
56
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
47
58
|
requirements:
|
48
|
-
- - "
|
59
|
+
- - ">"
|
49
60
|
- !ruby/object:Gem::Version
|
50
|
-
|
51
|
-
|
61
|
+
hash: 25
|
62
|
+
segments:
|
63
|
+
- 1
|
64
|
+
- 3
|
65
|
+
- 1
|
66
|
+
version: 1.3.1
|
52
67
|
requirements: []
|
53
68
|
|
54
69
|
rubyforge_project:
|
55
|
-
rubygems_version: 1.3.
|
70
|
+
rubygems_version: 1.3.7
|
56
71
|
signing_key:
|
57
72
|
specification_version: 3
|
58
73
|
summary: A configurable and documented Rails view helper for adding gravatars into your Rails application.
|