@@ -0,0 +1,1 | |||
|
1 | coverage |
@@ -12,12 +12,12 set up an avatar for each site that they post on. | |||
|
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 | |
@@ -34,6 +34,9 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 |
@@ -48,5 +51,5 The following people have also written gravatar-related Ruby libraries: | |||
|
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 |
@@ -6,7 +6,6 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 |
@@ -1,7 +1,7 | |||
|
1 | 1 | author: Scott Woods, West Arete Computing |
|
2 | 2 | summary: View helpers for displaying gravatars. |
|
3 |
homepage: http://gravatarplugin |
|
|
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+ |
@@ -22,11 +22,16 module GravatarHelper | |||
|
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. |
@@ -46,19 +51,32 module GravatarHelper | |||
|
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 |
|
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 | |
|
49 | 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 |
|
|
|
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 |
General Comments 0
You need to be logged in to leave comments.
Login now