Module: AvatarHelper
- Defined in:
- app/helpers/avatar_helper.rb
Instance Method Summary collapse
- #avatar_for(user, options = {}) ⇒ Object
- #gravatar_image(email, options = {}) ⇒ Object
- #gravatar_url(email, options = {}) ⇒ Object
Instance Method Details
#avatar_for(user, options = {}) ⇒ Object
5 6 7 8 9 10 11 |
# File 'app/helpers/avatar_helper.rb', line 5 def avatar_for(user, ={}) size = .fetch(:size, 24) return "<div class=\"avatar avatar-empty\" style=\"width:#{size}px; height:#{size}px\"></div>".html_safe unless user "<img class=\"avatar user-#{user.id}\" src=\"#{gravatar_url(user.email, size: size * 2)}\" width=\"#{size}\" height=\"#{size}\" alt=\"#{user.name}\" />".html_safe end |
#gravatar_image(email, options = {}) ⇒ Object
14 15 16 17 18 19 20 |
# File 'app/helpers/avatar_helper.rb', line 14 def gravatar_image(email, ={}) return "" if email.blank? size = .fetch(:size, 24) alt = [:alt] "<img class=\"avatar\" src=\"#{gravatar_url(email, size: size * 2)}\" width=\"#{size}\" height=\"#{size}\" alt=\"#{alt}\" />".html_safe end |
#gravatar_url(email, options = {}) ⇒ Object
25 26 27 28 29 |
# File 'app/helpers/avatar_helper.rb', line 25 def gravatar_url(email, ={}) url = "https://www.gravatar.com/avatar/#{Digest::MD5::hexdigest(email)}?r=g&d=retro" url << "&s=#{[:size]}" if .key?(:size) url end |