Fix most auto-correctable rubocop issues
[rails.git] / app / helpers / user_helper.rb
1 module UserHelper
2   # User images
3
4   def user_image(user, options = {})
5     options[:class] ||= "user_image"
6     options[:alt] ||= ""
7
8     if user.image_use_gravatar
9       user_gravatar_tag(user, options)
10     else
11       image_tag user.image.url(:large), options
12     end
13   end
14
15   def user_thumbnail(user, options = {})
16     options[:class] ||= "user_thumbnail"
17     options[:alt] ||= ""
18
19     if user.image_use_gravatar
20       user_gravatar_tag(user, options)
21     else
22       image_tag user.image.url(:small), options
23     end
24   end
25
26   def user_thumbnail_tiny(user, options = {})
27     options[:class] ||= "user_thumbnail_tiny"
28     options[:alt] ||= ""
29
30     if user.image_use_gravatar
31       user_gravatar_tag(user, options)
32     else
33       image_tag user.image.url(:small), options
34     end
35   end
36
37   def user_image_url(user, options = {})
38     if user.image_use_gravatar
39       user_gravatar_url(user, options)
40     else
41       image_url(user.image.url)
42     end
43   end
44
45   # OpenID support
46
47   def openid_logo
48     image_tag "openid_small.png", :alt => t('user.login.openid_logo_alt'), :class => "openid_logo"
49   end
50
51   def openid_button(name, url)
52     link_to(
53       image_tag("#{name}.png", :alt => t("user.login.openid_providers.#{name}.alt")),
54       "#",
55       :class => "openid_button", :data => { :url => url },
56       :title => t("user.login.openid_providers.#{name}.title")
57     )
58   end
59
60   # Gravatar support
61
62   # See http://en.gravatar.com/site/implement/images/ for details.
63   def user_gravatar_url(user, options = {})
64     size = options[:size] || 100
65     hash = Digest::MD5.hexdigest(user.email.downcase)
66     default_image_url = image_url("users/images/large.png")
67     url = "#{request.protocol}www.gravatar.com/avatar/#{hash}.jpg?s=#{size}&d=#{u(default_image_url)}"
68   end
69
70   def user_gravatar_tag(user, options = {})
71     url = user_gravatar_url(user, options)
72     options.delete(:size)
73     image_tag url, options
74   end
75 end