4 def user_image(user, options = {})
5 options[:class] ||= "user_image"
8 if user.image_use_gravatar
9 user_gravatar_tag(user, options)
10 elsif user.avatar.attached?
11 image_tag user.avatar.variant(:resize => "100x100>"), options
13 image_tag "avatar_large.png", options
17 def user_thumbnail(user, options = {})
18 options[:class] ||= "user_thumbnail"
21 if user.image_use_gravatar
22 user_gravatar_tag(user, options)
23 elsif user.avatar.attached?
24 image_tag user.avatar.variant(:resize => "50x50>"), options
26 image_tag "avatar_small.png", options
30 def user_thumbnail_tiny(user, options = {})
31 options[:class] ||= "user_thumbnail_tiny"
34 if user.image_use_gravatar
35 user_gravatar_tag(user, options)
36 elsif user.avatar.attached?
37 image_tag user.avatar.variant(:resize => "50x50>"), options
39 image_tag "avatar_small.png", options
43 def user_image_url(user, options = {})
44 if user.image_use_gravatar
45 user_gravatar_url(user, options)
46 elsif user.avatar.attached?
47 polymorphic_url(user.avatar.variant(:resize => "100x100>"))
49 image_url("avatar_large.png")
53 # External authentication support
56 image_tag "openid_small.png", :alt => t("users.login.openid_logo_alt"), :class => "openid_logo"
59 def auth_button(name, provider, options = {})
61 image_tag("#{name}.png", :alt => t("users.login.auth_providers.#{name}.alt")),
62 auth_path(options.merge(:provider => provider)),
63 :class => "auth_button",
64 :title => t("users.login.auth_providers.#{name}.title")
72 # See http://en.gravatar.com/site/implement/images/ for details.
73 def user_gravatar_url(user, options = {})
74 size = options[:size] || 100
75 hash = Digest::MD5.hexdigest(user.email.downcase)
76 default_image_url = image_url("avatar_large.png")
77 "#{request.protocol}www.gravatar.com/avatar/#{hash}.jpg?s=#{size}&d=#{u(default_image_url)}"
80 def user_gravatar_tag(user, options = {})
81 url = user_gravatar_url(user, options)
83 image_tag url, options