]> git.openstreetmap.org Git - rails.git/blob - app/helpers/user_helper.rb
Show node coordinates in the right place
[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
7     if user.image_use_gravatar
8       user_gravatar_tag(user, options)
9     else
10       image_tag user.image.url(:large), options
11     end
12   end
13
14   def user_thumbnail(user, options = {})
15     options[:class] ||= "user_thumbnail"
16
17     if user.image_use_gravatar
18       user_gravatar_tag(user, options)
19     else
20       image_tag user.image.url(:small), options
21     end
22   end
23
24   def user_thumbnail_tiny(user, options = {})
25     options[:class] ||= "user_thumbnail_tiny"
26
27     if user.image_use_gravatar
28       user_gravatar_tag(user, options)
29     else
30       image_tag user.image.url(:small), options
31     end
32   end
33
34   def user_image_url(user, options = {})
35     if user.image_use_gravatar
36       user_gravatar_url(user, options)
37     else
38       "http://#{SERVER_URL}#{image_path(user.image.url)}"
39     end
40   end
41
42   # OpenID support
43
44   def openid_logo
45     image_tag "openid_small.png", :alt => t('user.login.openid_logo_alt'), :class => "openid_logo"
46   end
47
48   def openid_button(name, url)
49     link_to(
50       image_tag("#{name}.png", :alt => t("user.login.openid_providers.#{name}.alt")),
51       "#",
52       :class => "openid_button", :data => { :url => url },
53       :title => t("user.login.openid_providers.#{name}.title")
54     )
55   end
56
57   # Gravatar support
58
59   # See http://en.gravatar.com/site/implement/images/ for details.
60   def user_gravatar_url(user, options = {})
61     size = options[:size] || 100
62     hash = Digest::MD5::hexdigest(user.email.downcase)
63     default_image_url = "http://#{SERVER_URL}#{image_path("users/images/large.png")}"
64     url = "http://www.gravatar.com/avatar/#{hash}.jpg?s=#{size}&d=#{u(default_image_url)}"
65   end
66
67   def user_gravatar_tag(user, options = {})
68     url = user_gravatar_url(user, options)
69     options.delete(:size)
70     image_tag url, options
71   end
72 end