##// END OF EJS Templates
Upgraded the gravatar plugin from http://github.com/woods/gravatar-plugin...
Eric Davis -
r2727:560e915c50e8
parent child
Show More
@@ -0,0 +1,1
1 coverage
@@ -1,52 +1,55
1 1 == Gravatar Plugin
2 2
3 3 This plugin provides a handful of view helpers for displaying gravatars
4 4 (globally-recognized avatars).
5 5
6 6 Gravatars allow users to configure an avatar to go with their email address at
7 7 a central location: http://gravatar.com. Gravatar-aware websites (such
8 8 as yours) can then look up and display each user's preferred avatar, without
9 9 having to handle avatar management. The user gets the benefit of not having to
10 10 set up an avatar for each site that they post on.
11 11
12 12 == Installation
13 13
14 14 cd ~/myapp
15 ruby script/plugin install svn://rubyforge.org//var/svn/gravatarplugin/plugins/gravatar
15 ruby script/plugin install git://github.com/woods/gravatar-plugin.git
16 16
17 17 or, if you're using piston[http://piston.rubyforge.org] (worth it!):
18 18
19 19 cd ~/myapp/vendor/plugins
20 piston import svn://rubyforge.org//var/svn/gravatarplugin/plugins/gravatar
20 piston import git://github.com/woods/gravatar-plugin.git
21 21
22 22 == Example
23 23
24 24 If you represent your users with a model that has an +email+ method (typical
25 25 for most rails authentication setups), then you can simply use this method
26 26 in your views:
27 27
28 28 <%= gravatar_for @user %>
29 29
30 30 This will be replaced with the full HTML +img+ tag necessary for displaying
31 31 that user's gravatar.
32 32
33 33 Other helpers are documented under GravatarHelper::PublicMethods.
34 34
35 35 == Acknowledgments
36 36
37 Thanks to Magnus Bergmark (http://github.com/Mange), who contributed the SSL
38 support in this plugin, as well as a few minor fixes.
39
37 40 The following people have also written gravatar-related Ruby libraries:
38 41 * Seth Rasmussen created the gravatar gem[http://gravatar.rubyforge.org]
39 42 * Matt McCray has also created a gravatar
40 43 plugin[http://mattmccray.com/svn/rails/plugins/gravatar_helper]
41 44
42 45 == Author
43 46
44 47 Scott A. Woods
45 48 West Arete Computing, Inc.
46 49 http://westarete.com
47 50 scott at westarete dot com
48 51
49 52 == TODO
50 53
51 * Get full spec coverage
54 * Add specs for ssl support
52 55 * Finish rdoc documentation No newline at end of file
@@ -1,33 +1,32
1 1 require 'spec/rake/spectask'
2 2 require 'rake/rdoctask'
3 3
4 4 desc 'Default: run all specs'
5 5 task :default => :spec
6 6
7 7 desc 'Run all application-specific specs'
8 8 Spec::Rake::SpecTask.new(:spec) do |t|
9 t.warning = true
10 9 t.rcov = true
11 10 end
12 11
13 12 desc "Report code statistics (KLOCs, etc) from the application"
14 13 task :stats do
15 14 RAILS_ROOT = File.dirname(__FILE__)
16 15 STATS_DIRECTORIES = [
17 16 %w(Libraries lib/),
18 17 %w(Specs spec/),
19 18 ].collect { |name, dir| [ name, "#{RAILS_ROOT}/#{dir}" ] }.select { |name, dir| File.directory?(dir) }
20 19 require 'code_statistics'
21 20 CodeStatistics.new(*STATS_DIRECTORIES).to_s
22 21 end
23 22
24 23 namespace :doc do
25 24 desc 'Generate documentation for the assert_request plugin.'
26 25 Rake::RDocTask.new(:plugin) do |rdoc|
27 26 rdoc.rdoc_dir = 'rdoc'
28 27 rdoc.title = 'Gravatar Rails Plugin'
29 28 rdoc.options << '--line-numbers' << '--inline-source' << '--accessor' << 'cattr_accessor=rw'
30 29 rdoc.rdoc_files.include('README')
31 30 rdoc.rdoc_files.include('lib/**/*.rb')
32 31 end
33 32 end
@@ -1,7 +1,7
1 1 author: Scott Woods, West Arete Computing
2 2 summary: View helpers for displaying gravatars.
3 homepage: http://gravatarplugin.rubyforge.org/
4 plugin: svn://rubyforge.org//var/svn/gravatarplugin/plugins/gravatar
3 homepage: http://github.com/woods/gravatar-plugin/
4 plugin: git://github.com/woods/gravatar-plugin.git
5 5 license: MIT
6 6 version: 0.1
7 7 rails_version: 1.0+
@@ -1,67 +1,85
1 1 require 'digest/md5'
2 2 require 'cgi'
3 3
4 4 module GravatarHelper
5 5
6 6 # These are the options that control the default behavior of the public
7 7 # methods. They can be overridden during the actual call to the helper,
8 8 # or you can set them in your environment.rb as such:
9 9 #
10 10 # # Allow racier gravatars
11 11 # GravatarHelper::DEFAULT_OPTIONS[:rating] = 'R'
12 12 #
13 13 DEFAULT_OPTIONS = {
14 14 # The URL of a default image to display if the given email address does
15 15 # not have a gravatar.
16 16 :default => nil,
17 17
18 18 # The default size in pixels for the gravatar image (they're square).
19 19 :size => 50,
20 20
21 21 # The maximum allowed MPAA rating for gravatars. This allows you to
22 22 # exclude gravatars that may be out of character for your site.
23 23 :rating => 'PG',
24 24
25 # The alt text to use in the img tag for the gravatar.
26 :alt => 'avatar',
25 # The alt text to use in the img tag for the gravatar. Since it's a
26 # decorational picture, the alt text should be empty according to the
27 # XHTML specs.
28 :alt => '',
27 29
28 30 # The class to assign to the img tag for the gravatar.
29 31 :class => 'gravatar',
32
33 # Whether or not to display the gravatars using HTTPS instead of HTTP
34 :ssl => false,
30 35 }
31 36
32 37 # The methods that will be made available to your views.
33 38 module PublicMethods
34 39
35 40 # Return the HTML img tag for the given user's gravatar. Presumes that
36 41 # the given user object will respond_to "email", and return the user's
37 42 # email address.
38 43 def gravatar_for(user, options={})
39 44 gravatar(user.email, options)
40 45 end
41 46
42 47 # Return the HTML img tag for the given email address's gravatar.
43 48 def gravatar(email, options={})
44 49 src = h(gravatar_url(email, options))
45 50 options = DEFAULT_OPTIONS.merge(options)
46 51 [:class, :alt, :size].each { |opt| options[opt] = h(options[opt]) }
47 52 "<img class=\"#{options[:class]}\" alt=\"#{options[:alt]}\" width=\"#{options[:size]}\" height=\"#{options[:size]}\" src=\"#{src}\" />"
48 53 end
49 54
55 # Returns the base Gravatar URL for the given email hash. If ssl evaluates to true,
56 # a secure URL will be used instead. This is required when the gravatar is to be
57 # displayed on a HTTPS site.
58 def gravatar_api_url(hash, ssl=false)
59 if ssl
60 "https://secure.gravatar.com/avatar/#{hash}"
61 else
62 "http://www.gravatar.com/avatar/#{hash}"
63 end
64 end
65
50 66 # Return the gravatar URL for the given email address.
51 67 def gravatar_url(email, options={})
52 68 email_hash = Digest::MD5.hexdigest(email)
53 69 options = DEFAULT_OPTIONS.merge(options)
54 70 options[:default] = CGI::escape(options[:default]) unless options[:default].nil?
55 returning "http://www.gravatar.com/avatar.php?gravatar_id=#{email_hash}" do |url|
71 returning gravatar_api_url(email_hash, options.delete(:ssl)) do |url|
72 opts = []
56 73 [:rating, :size, :default].each do |opt|
57 74 unless options[opt].nil?
58 75 value = h(options[opt])
59 url << "&#{opt}=#{value}"
76 opts << [opt, value].join('=')
60 77 end
61 78 end
79 url << "?#{opts.join('&')}" unless opts.empty?
62 80 end
63 81 end
64 82
65 83 end
66 84
67 85 end No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now