@@ -0,0 +1,1 | |||||
|
1 | coverage |
@@ -12,12 +12,12 set up an avatar for each site that they post on. | |||||
12 | == Installation |
|
12 | == Installation | |
13 |
|
13 | |||
14 | cd ~/myapp |
|
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 | or, if you're using piston[http://piston.rubyforge.org] (worth it!): |
|
17 | or, if you're using piston[http://piston.rubyforge.org] (worth it!): | |
18 |
|
18 | |||
19 | cd ~/myapp/vendor/plugins |
|
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 | == Example |
|
22 | == Example | |
23 |
|
23 | |||
@@ -34,6 +34,9 Other helpers are documented under GravatarHelper::PublicMethods. | |||||
34 |
|
34 | |||
35 | == Acknowledgments |
|
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 | The following people have also written gravatar-related Ruby libraries: |
|
40 | The following people have also written gravatar-related Ruby libraries: | |
38 | * Seth Rasmussen created the gravatar gem[http://gravatar.rubyforge.org] |
|
41 | * Seth Rasmussen created the gravatar gem[http://gravatar.rubyforge.org] | |
39 | * Matt McCray has also created a gravatar |
|
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 | == TODO |
|
52 | == TODO | |
50 |
|
53 | |||
51 | * Get full spec coverage |
|
54 | * Add specs for ssl support | |
52 | * Finish rdoc documentation No newline at end of file |
|
55 | * Finish rdoc documentation |
@@ -6,7 +6,6 task :default => :spec | |||||
6 |
|
6 | |||
7 | desc 'Run all application-specific specs' |
|
7 | desc 'Run all application-specific specs' | |
8 | Spec::Rake::SpecTask.new(:spec) do |t| |
|
8 | Spec::Rake::SpecTask.new(:spec) do |t| | |
9 | t.warning = true |
|
|||
10 | t.rcov = true |
|
9 | t.rcov = true | |
11 | end |
|
10 | end | |
12 |
|
11 |
@@ -1,7 +1,7 | |||||
1 | author: Scott Woods, West Arete Computing |
|
1 | author: Scott Woods, West Arete Computing | |
2 | summary: View helpers for displaying gravatars. |
|
2 | summary: View helpers for displaying gravatars. | |
3 |
homepage: http://gravatarplugin |
|
3 | homepage: http://github.com/woods/gravatar-plugin/ | |
4 | plugin: svn://rubyforge.org//var/svn/gravatarplugin/plugins/gravatar |
|
4 | plugin: git://github.com/woods/gravatar-plugin.git | |
5 | license: MIT |
|
5 | license: MIT | |
6 | version: 0.1 |
|
6 | version: 0.1 | |
7 | rails_version: 1.0+ |
|
7 | rails_version: 1.0+ |
@@ -22,11 +22,16 module GravatarHelper | |||||
22 | # exclude gravatars that may be out of character for your site. |
|
22 | # exclude gravatars that may be out of character for your site. | |
23 | :rating => 'PG', |
|
23 | :rating => 'PG', | |
24 |
|
24 | |||
25 | # The alt text to use in the img tag for the gravatar. |
|
25 | # The alt text to use in the img tag for the gravatar. Since it's a | |
26 | :alt => 'avatar', |
|
26 | # decorational picture, the alt text should be empty according to the | |
|
27 | # XHTML specs. | |||
|
28 | :alt => '', | |||
27 |
|
29 | |||
28 | # The class to assign to the img tag for the gravatar. |
|
30 | # The class to assign to the img tag for the gravatar. | |
29 | :class => 'gravatar', |
|
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 | # The methods that will be made available to your views. |
|
37 | # The methods that will be made available to your views. | |
@@ -46,19 +51,32 module GravatarHelper | |||||
46 | [:class, :alt, :size].each { |opt| options[opt] = h(options[opt]) } |
|
51 | [:class, :alt, :size].each { |opt| options[opt] = h(options[opt]) } | |
47 | "<img class=\"#{options[:class]}\" alt=\"#{options[:alt]}\" width=\"#{options[:size]}\" height=\"#{options[:size]}\" src=\"#{src}\" />" |
|
52 | "<img class=\"#{options[:class]}\" alt=\"#{options[:alt]}\" width=\"#{options[:size]}\" height=\"#{options[:size]}\" src=\"#{src}\" />" | |
48 | end |
|
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 | # Return the gravatar URL for the given email address. |
|
66 | # Return the gravatar URL for the given email address. | |
51 | def gravatar_url(email, options={}) |
|
67 | def gravatar_url(email, options={}) | |
52 | email_hash = Digest::MD5.hexdigest(email) |
|
68 | email_hash = Digest::MD5.hexdigest(email) | |
53 | options = DEFAULT_OPTIONS.merge(options) |
|
69 | options = DEFAULT_OPTIONS.merge(options) | |
54 | options[:default] = CGI::escape(options[:default]) unless options[:default].nil? |
|
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 | [:rating, :size, :default].each do |opt| |
|
73 | [:rating, :size, :default].each do |opt| | |
57 | unless options[opt].nil? |
|
74 | unless options[opt].nil? | |
58 | value = h(options[opt]) |
|
75 | value = h(options[opt]) | |
59 |
|
|
76 | opts << [opt, value].join('=') | |
60 | end |
|
77 | end | |
61 | end |
|
78 | end | |
|
79 | url << "?#{opts.join('&')}" unless opts.empty? | |||
62 | end |
|
80 | end | |
63 | end |
|
81 | end | |
64 |
|
82 |
General Comments 0
You need to be logged in to leave comments.
Login now