Module: GravatarHelper::PublicMethods
- Included in:
- ApplicationHelper
- Defined in:
- lib/plugins/gravatar/lib/gravatar.rb
Overview
The methods that will be made available to your views.
Instance Method Summary collapse
-
#gravatar(email, options = {}) ⇒ Object
Return the HTML img tag for the given email address's gravatar.
-
#gravatar_api_url(hash) ⇒ Object
Returns the base Gravatar URL for the given email hash.
-
#gravatar_for(user, options = {}) ⇒ Object
Return the HTML img tag for the given user's gravatar.
-
#gravatar_url(email, options = {}) ⇒ Object
Return the gravatar URL for the given email address.
Instance Method Details
#gravatar(email, options = {}) ⇒ Object
Return the HTML img tag for the given email address's gravatar.
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/plugins/gravatar/lib/gravatar.rb', line 51 def gravatar(email, ={}) src = h(gravatar_url(email, )) = DEFAULT_OPTIONS.merge() [:class, :alt, :title].each { |opt| [opt] = h([opt]) } # double the size for hires displays [:srcset] = "#{gravatar_url(email, .merge(size: [:size].to_i * 2))} 2x" image_tag src, .except(:rating, :size, :default, :ssl) end |
#gravatar_api_url(hash) ⇒ Object
Returns the base Gravatar URL for the given email hash
63 64 65 |
# File 'lib/plugins/gravatar/lib/gravatar.rb', line 63 def gravatar_api_url(hash) "//www.gravatar.com/avatar/#{hash}" end |
#gravatar_for(user, options = {}) ⇒ Object
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.
46 47 48 |
# File 'lib/plugins/gravatar/lib/gravatar.rb', line 46 def gravatar_for(user, ={}) gravatar(user.email, ) end |
#gravatar_url(email, options = {}) ⇒ Object
Return the gravatar URL for the given email address.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/plugins/gravatar/lib/gravatar.rb', line 68 def gravatar_url(email, ={}) email_hash = Digest::MD5.hexdigest(email) = DEFAULT_OPTIONS.merge() [:default] = CGI::escape([:default]) unless [:default].nil? gravatar_api_url(email_hash).tap 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 |