Module: GravatarHelper::PublicMethods
- Included in:
- ApplicationHelper
- Defined in:
- vendor/plugins/gravatar/lib/gravatar.rb
Overview
The methods that will be made available to your views.
Instance Method Summary
-
- (Object) gravatar(email, options = {})
Return the HTML img tag for the given email address’s gravatar.
-
- (Object) gravatar_api_url(hash, ssl = false)
Returns the base Gravatar URL for the given email hash.
-
- (Object) gravatar_for(user, options = {})
Return the HTML img tag for the given user’s gravatar.
-
- (Object) gravatar_url(email, options = {})
Return the gravatar URL for the given email address.
Instance Method Details
- (Object) gravatar(email, options = {})
Return the HTML img tag for the given email address’s gravatar.
48 49 50 51 52 53 |
# File 'vendor/plugins/gravatar/lib/gravatar.rb', line 48 def gravatar(email, ={}) src = h(gravatar_url(email, )) = DEFAULT_OPTIONS.merge() [:class, :alt, :size].each { |opt| [opt] = h([opt]) } "<img class=\"#{options[:class]}\" alt=\"#{options[:alt]}\" width=\"#{options[:size]}\" height=\"#{options[:size]}\" src=\"#{src}\" />" end |
- (Object) gravatar_api_url(hash, ssl = false)
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.
58 59 60 61 62 63 64 |
# File 'vendor/plugins/gravatar/lib/gravatar.rb', line 58 def gravatar_api_url(hash, ssl=false) if ssl "https://secure.gravatar.com/avatar/#{hash}" else "http://www.gravatar.com/avatar/#{hash}" end end |
- (Object) gravatar_for(user, options = {})
Return the HTML img tag for the given user’s gravatar. Presumes that the given user object will respond_to "email", and return the user’s email address.
43 44 45 |
# File 'vendor/plugins/gravatar/lib/gravatar.rb', line 43 def gravatar_for(user, ={}) gravatar(user.email, ) end |
- (Object) gravatar_url(email, options = {})
Return the gravatar URL for the given email address.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'vendor/plugins/gravatar/lib/gravatar.rb', line 67 def gravatar_url(email, ={}) email_hash = Digest::MD5.hexdigest(email) = DEFAULT_OPTIONS.merge() [:default] = CGI::escape([:default]) unless [:default].nil? returning gravatar_api_url(email_hash, .delete(:ssl)) do |url| opts = [] [:rating, :size, :default].each do |opt| unless [opt].nil? value = h([opt]) opts << [opt, value].join('=') end end url << "?#{opts.join('&')}" unless opts.empty? end end |