2012-03-06 18:59:29 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
|
|
|
module UsersHelper
|
2012-03-11 17:06:41 +00:00
|
|
|
|
|
|
|
def avatar_url_by_email(email, size = :small)
|
2012-03-13 18:47:37 +00:00
|
|
|
avatar_url(User.where(:email => email).first || User.new(:email => email), size)
|
2012-03-11 17:06:41 +00:00
|
|
|
end
|
|
|
|
|
2012-03-06 18:59:29 +00:00
|
|
|
def avatar_url(user, size = :small)
|
2012-03-11 17:06:41 +00:00
|
|
|
if user.try('avatar?')
|
2012-03-06 18:59:29 +00:00
|
|
|
user.avatar.url(size)
|
|
|
|
else
|
|
|
|
gravatar_url(user.email, user.avatar.styles[size].geometry.split('x').first)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def gravatar_url(email, size = 30)
|
|
|
|
"https://secure.gravatar.com/avatar/#{Digest::MD5.hexdigest(email.downcase)}?s=#{size}&r=pg"
|
|
|
|
end
|
|
|
|
end
|