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 |
|
|
21 |
|
# The maximum allowed MPAA rating for gravatars. This allows you to
|
|
20 |
|
|
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 |
25 |
# The alt text to use in the img tag for the gravatar. Since it's a
|
26 |
26 |
# decorational picture, the alt text should be empty according to the
|
27 |
27 |
# XHTML specs.
|
... | ... | |
29 |
29 |
|
30 |
30 |
# The title text to use for the img tag for the gravatar.
|
31 |
31 |
:title => '',
|
32 |
|
|
|
32 |
|
33 |
33 |
# The class to assign to the img tag for the gravatar.
|
34 |
34 |
:class => 'gravatar',
|
35 |
|
|
|
35 |
|
36 |
36 |
# Whether or not to display the gravatars using HTTPS instead of HTTP
|
37 |
37 |
:ssl => false,
|
38 |
38 |
}
|
39 |
|
|
|
39 |
|
40 |
40 |
# The methods that will be made available to your views.
|
41 |
41 |
module PublicMethods
|
42 |
|
|
43 |
|
# Return the HTML img tag for the given user's gravatar. Presumes that
|
|
42 |
|
|
43 |
# Return the HTML img tag for the given user's gravatar. Presumes that
|
44 |
44 |
# the given user object will respond_to "email", and return the user's
|
45 |
45 |
# email address.
|
46 |
46 |
def gravatar_for(user, options={})
|
... | ... | |
51 |
51 |
def gravatar(email, options={})
|
52 |
52 |
src = h(gravatar_url(email, options))
|
53 |
53 |
options = DEFAULT_OPTIONS.merge(options)
|
|
54 |
options[:title] = email
|
54 |
55 |
[:class, :alt, :title].each { |opt| options[opt] = h(options[opt]) }
|
55 |
56 |
|
56 |
57 |
# double the size for hires displays
|
... | ... | |
58 |
59 |
|
59 |
60 |
image_tag src, options.except(:rating, :size, :default, :ssl)
|
60 |
61 |
end
|
61 |
|
|
|
62 |
|
62 |
63 |
# Returns the base Gravatar URL for the given email hash
|
63 |
64 |
def gravatar_api_url(hash)
|
64 |
65 |
"//www.gravatar.com/avatar/#{hash}"
|
... | ... | |
82 |
83 |
end
|
83 |
84 |
|
84 |
85 |
end
|
85 |
|
|
|
86 |
|
86 |
87 |
end
|