Sha256: aa0a8dc6f8e9f480657506007593d7226a3ec79514b52e2f7c6b6da151d3f6e9

Contents?: true

Size: 965 Bytes

Versions: 5

Compression:

Stored size: 965 Bytes

Contents

module AvatarHelper



  def avatar_for(user, options={})
    size = options.fetch(:size, 24)

    return "<div class=\"avatar avatar-empty\" style=\"width:#{size}px; height:#{size}px\" />".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


  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


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



end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
houston-core-0.8.3 app/helpers/avatar_helper.rb
houston-core-0.8.2 app/helpers/avatar_helper.rb
houston-core-0.8.1 app/helpers/avatar_helper.rb
houston-core-0.8.0 app/helpers/avatar_helper.rb
houston-core-0.8.0.pre2 app/helpers/avatar_helper.rb