Module: AvatarHelper

Included in:
TestingNotePresenter
Defined in:
app/helpers/avatar_helper.rb

Instance Method Summary collapse

Instance Method Details

#avatar_for(user, options = {}) ⇒ Object



5
6
7
8
9
10
# File 'app/helpers/avatar_helper.rb', line 5

def avatar_for(user, options={})
  return "" unless user

  size = options.fetch(:size, 24)
  "<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



13
14
15
16
17
18
19
# File 'app/helpers/avatar_helper.rb', line 13

def gravatar_image(email, options={})
  return "" if email.blank?

  size = options.fetch(:size, 24)
  alt = options[: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



24
25
26
27
28
# File 'app/helpers/avatar_helper.rb', line 24

def gravatar_url(email, options={})
  url = "//www.gravatar.com/avatar/#{Digest::MD5::hexdigest(email)}?r=g&d=retro"
  url << "&s=#{options[:size]}" if options.key?(:size)
  url
end