Module: AvatarHelper
- Defined in:
- app/helpers/avatar_helper.rb
Instance Method Summary collapse
-
#user_avatar(user, options = {}) ⇒ Object
This returns the html code for an avatar image of the given user.
- #user_avatar_default_url ⇒ Object
- #user_avatar_url(user, options = {}) ⇒ Object
-
#user_gravatar(user, options = {}) ⇒ Object
This returns the html code for an avatar image of the given user.
- #user_gravatar_url(user, options = {}) ⇒ Object
Instance Method Details
#user_avatar(user, options = {}) ⇒ Object
This returns the html code for an avatar image of the given user.
-
If the user has uploaded an avatar image using refile, this one is used.
-
Next, the gravatar of the user’s email is tried.
-
The fallback image is defined in the ‘user_avatar_default_url` method.
9 10 11 12 13 14 15 16 17 18 |
# File 'app/helpers/avatar_helper.rb', line 9 def user_avatar(user, = {}) [:size] ||= 36 content_tag(:span, class: 'avatar') do if user.avatar_id? image_tag Refile.(user, :avatar, :fill, [:size], [:size]), class: 'img-rounded' else user_gravatar(user, ) end end.html_safe end |
#user_avatar_default_url ⇒ Object
66 67 68 |
# File 'app/helpers/avatar_helper.rb', line 66 def user_avatar_default_url "https://wingolfsplattform.org/assets/avatar_128.png" end |
#user_avatar_url(user, options = {}) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'app/helpers/avatar_helper.rb', line 49 def user_avatar_url(user, = {}) [:size] ||= 36 if user.avatar_id? Refile.(user, :avatar, :fill, [:size], [:size]) else user_gravatar_url(user, ) end end |
#user_gravatar(user, options = {}) ⇒ Object
This returns the html code for an avatar image of the given user. This image is just provided by gravatar.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/helpers/avatar_helper.rb', line 23 def user_gravatar(user, = {}) email = user.email [:size] ||= 36 [:gravatar] ||= {} [:gravatar][:size] ||= [:size] #options[:alt] ||= "Gravatar: #{email}" #options[:title] ||= options[:alt] ['data-toggle'] ||= 'tooltip' [:gravatar][:secure] = true [:class] ||= "" [:class] += " img-rounded" # Default Url # Instead of # URI.join(root_url, asset_path('avatar_128.png')) # we use a string at the moment, in order to make this work # locally as well. Otherwise a 'http://localhost/...' would be # submitted to gravatar as source of the default image. # [:gravatar][:default] ||= user_avatar_default_url gravatar_image_tag(email, ) end |
#user_gravatar_url(user, options = {}) ⇒ Object
58 59 60 61 62 63 64 |
# File 'app/helpers/avatar_helper.rb', line 58 def user_gravatar_url(user, = {}) [:gravatar] ||= {} [:gravatar][:default] ||= user_avatar_default_url [:gravatar][:size] ||= 36 [:gravatar][:secure] = true gravatar_image_url(user.email, ) end |