Upgraded the gravatar plugin from http://github.com/woods/gravatar-plugin
This will update the gravatar.com url (#2921) and provide support for SSL gravatars (#2718). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2832 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
bb61c9a0ec
commit
560e915c50
|
@ -0,0 +1 @@
|
||||||
|
coverage
|
|
@ -12,12 +12,12 @@ set up an avatar for each site that they post on.
|
||||||
== Installation
|
== Installation
|
||||||
|
|
||||||
cd ~/myapp
|
cd ~/myapp
|
||||||
ruby script/plugin install svn://rubyforge.org//var/svn/gravatarplugin/plugins/gravatar
|
ruby script/plugin install git://github.com/woods/gravatar-plugin.git
|
||||||
|
|
||||||
or, if you're using piston[http://piston.rubyforge.org] (worth it!):
|
or, if you're using piston[http://piston.rubyforge.org] (worth it!):
|
||||||
|
|
||||||
cd ~/myapp/vendor/plugins
|
cd ~/myapp/vendor/plugins
|
||||||
piston import svn://rubyforge.org//var/svn/gravatarplugin/plugins/gravatar
|
piston import git://github.com/woods/gravatar-plugin.git
|
||||||
|
|
||||||
== Example
|
== Example
|
||||||
|
|
||||||
|
@ -34,6 +34,9 @@ Other helpers are documented under GravatarHelper::PublicMethods.
|
||||||
|
|
||||||
== Acknowledgments
|
== Acknowledgments
|
||||||
|
|
||||||
|
Thanks to Magnus Bergmark (http://github.com/Mange), who contributed the SSL
|
||||||
|
support in this plugin, as well as a few minor fixes.
|
||||||
|
|
||||||
The following people have also written gravatar-related Ruby libraries:
|
The following people have also written gravatar-related Ruby libraries:
|
||||||
* Seth Rasmussen created the gravatar gem[http://gravatar.rubyforge.org]
|
* Seth Rasmussen created the gravatar gem[http://gravatar.rubyforge.org]
|
||||||
* Matt McCray has also created a gravatar
|
* Matt McCray has also created a gravatar
|
||||||
|
@ -48,5 +51,5 @@ The following people have also written gravatar-related Ruby libraries:
|
||||||
|
|
||||||
== TODO
|
== TODO
|
||||||
|
|
||||||
* Get full spec coverage
|
* Add specs for ssl support
|
||||||
* Finish rdoc documentation
|
* Finish rdoc documentation
|
|
@ -6,7 +6,6 @@ task :default => :spec
|
||||||
|
|
||||||
desc 'Run all application-specific specs'
|
desc 'Run all application-specific specs'
|
||||||
Spec::Rake::SpecTask.new(:spec) do |t|
|
Spec::Rake::SpecTask.new(:spec) do |t|
|
||||||
t.warning = true
|
|
||||||
t.rcov = true
|
t.rcov = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
author: Scott Woods, West Arete Computing
|
author: Scott Woods, West Arete Computing
|
||||||
summary: View helpers for displaying gravatars.
|
summary: View helpers for displaying gravatars.
|
||||||
homepage: http://gravatarplugin.rubyforge.org/
|
homepage: http://github.com/woods/gravatar-plugin/
|
||||||
plugin: svn://rubyforge.org//var/svn/gravatarplugin/plugins/gravatar
|
plugin: git://github.com/woods/gravatar-plugin.git
|
||||||
license: MIT
|
license: MIT
|
||||||
version: 0.1
|
version: 0.1
|
||||||
rails_version: 1.0+
|
rails_version: 1.0+
|
||||||
|
|
|
@ -22,11 +22,16 @@ module GravatarHelper
|
||||||
# exclude gravatars that may be out of character for your site.
|
# exclude gravatars that may be out of character for your site.
|
||||||
:rating => 'PG',
|
:rating => 'PG',
|
||||||
|
|
||||||
# The alt text to use in the img tag for the gravatar.
|
# The alt text to use in the img tag for the gravatar. Since it's a
|
||||||
:alt => 'avatar',
|
# decorational picture, the alt text should be empty according to the
|
||||||
|
# XHTML specs.
|
||||||
|
:alt => '',
|
||||||
|
|
||||||
# The class to assign to the img tag for the gravatar.
|
# The class to assign to the img tag for the gravatar.
|
||||||
:class => 'gravatar',
|
:class => 'gravatar',
|
||||||
|
|
||||||
|
# Whether or not to display the gravatars using HTTPS instead of HTTP
|
||||||
|
:ssl => false,
|
||||||
}
|
}
|
||||||
|
|
||||||
# The methods that will be made available to your views.
|
# The methods that will be made available to your views.
|
||||||
|
@ -46,19 +51,32 @@ module GravatarHelper
|
||||||
[:class, :alt, :size].each { |opt| options[opt] = h(options[opt]) }
|
[:class, :alt, :size].each { |opt| options[opt] = h(options[opt]) }
|
||||||
"<img class=\"#{options[:class]}\" alt=\"#{options[:alt]}\" width=\"#{options[:size]}\" height=\"#{options[:size]}\" src=\"#{src}\" />"
|
"<img class=\"#{options[:class]}\" alt=\"#{options[:alt]}\" width=\"#{options[:size]}\" height=\"#{options[:size]}\" src=\"#{src}\" />"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns the base Gravatar URL for the given email hash. If ssl evaluates to true,
|
||||||
|
# a secure URL will be used instead. This is required when the gravatar is to be
|
||||||
|
# displayed on a HTTPS site.
|
||||||
|
def gravatar_api_url(hash, ssl=false)
|
||||||
|
if ssl
|
||||||
|
"https://secure.gravatar.com/avatar/#{hash}"
|
||||||
|
else
|
||||||
|
"http://www.gravatar.com/avatar/#{hash}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Return the gravatar URL for the given email address.
|
# Return the gravatar URL for the given email address.
|
||||||
def gravatar_url(email, options={})
|
def gravatar_url(email, options={})
|
||||||
email_hash = Digest::MD5.hexdigest(email)
|
email_hash = Digest::MD5.hexdigest(email)
|
||||||
options = DEFAULT_OPTIONS.merge(options)
|
options = DEFAULT_OPTIONS.merge(options)
|
||||||
options[:default] = CGI::escape(options[:default]) unless options[:default].nil?
|
options[:default] = CGI::escape(options[:default]) unless options[:default].nil?
|
||||||
returning "http://www.gravatar.com/avatar.php?gravatar_id=#{email_hash}" do |url|
|
returning gravatar_api_url(email_hash, options.delete(:ssl)) do |url|
|
||||||
|
opts = []
|
||||||
[:rating, :size, :default].each do |opt|
|
[:rating, :size, :default].each do |opt|
|
||||||
unless options[opt].nil?
|
unless options[opt].nil?
|
||||||
value = h(options[opt])
|
value = h(options[opt])
|
||||||
url << "&#{opt}=#{value}"
|
opts << [opt, value].join('=')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
url << "?#{opts.join('&')}" unless opts.empty?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue