Module: AvatarsHelper
- Included in:
- Banzai::Filter::CommitTrailersFilter, Gitlab::BlamePresenter, Groups::GroupMembersHelper
- Defined in:
- app/helpers/avatars_helper.rb
Instance Method Summary collapse
- #author_avatar(commit_or_event, options = {}) ⇒ Object
-
#avatar_icon_for(user = nil, email = nil, size = nil, scale = 2, only_path: true) ⇒ Object
Takes both user and email and returns the avatar_icon by user (preferred) or email.
- #avatar_icon_for_email(email = nil, size = nil, scale = 2, only_path: true) ⇒ Object
- #avatar_icon_for_user(user = nil, size = nil, scale = 2, only_path: true) ⇒ Object
- #default_avatar ⇒ Object
- #gravatar_icon(user_email = '', size = nil, scale = 2) ⇒ Object
- #group_icon(group, options = {}) ⇒ Object
- #project_icon(project, options = {}) ⇒ Object
- #user_avatar(options = {}) ⇒ Object
- #user_avatar_without_link(options = {}) ⇒ Object
Instance Method Details
#author_avatar(commit_or_event, options = {}) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'app/helpers/avatars_helper.rb', line 50 def (commit_or_event, = {}) user_avatar(.merge({ user: commit_or_event., user_name: commit_or_event., user_email: commit_or_event., css_class: 'd-none d-sm-inline-block' })) end |
#avatar_icon_for(user = nil, email = nil, size = nil, scale = 2, only_path: true) ⇒ Object
Takes both user and email and returns the avatar_icon by user (preferred) or email.
14 15 16 17 18 19 20 21 22 |
# File 'app/helpers/avatars_helper.rb', line 14 def avatar_icon_for(user = nil, email = nil, size = nil, scale = 2, only_path: true) if user avatar_icon_for_user(user, size, scale, only_path: only_path) elsif email avatar_icon_for_email(email, size, scale, only_path: only_path) else default_avatar end end |
#avatar_icon_for_email(email = nil, size = nil, scale = 2, only_path: true) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'app/helpers/avatars_helper.rb', line 24 def avatar_icon_for_email(email = nil, size = nil, scale = 2, only_path: true) user = User.find_by_any_email(email) if user avatar_icon_for_user(user, size, scale, only_path: only_path) else gravatar_icon(email, size, scale) end end |
#avatar_icon_for_user(user = nil, size = nil, scale = 2, only_path: true) ⇒ Object
33 34 35 36 37 38 39 |
# File 'app/helpers/avatars_helper.rb', line 33 def avatar_icon_for_user(user = nil, size = nil, scale = 2, only_path: true) if user user.avatar_url(size: size, only_path: only_path) || default_avatar else gravatar_icon(nil, size, scale) end end |
#default_avatar ⇒ Object
46 47 48 |
# File 'app/helpers/avatars_helper.rb', line 46 def default_avatar ActionController::Base.helpers.image_path('no_avatar.png') end |
#gravatar_icon(user_email = '', size = nil, scale = 2) ⇒ Object
41 42 43 44 |
# File 'app/helpers/avatars_helper.rb', line 41 def gravatar_icon(user_email = '', size = nil, scale = 2) GravatarService.new.execute(user_email, size, scale) || default_avatar end |
#group_icon(group, options = {}) ⇒ Object
8 9 10 |
# File 'app/helpers/avatars_helper.rb', line 8 def group_icon(group, = {}) source_icon(group, ) end |
#project_icon(project, options = {}) ⇒ Object
4 5 6 |
# File 'app/helpers/avatars_helper.rb', line 4 def project_icon(project, = {}) source_icon(project, ) end |
#user_avatar(options = {}) ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'app/helpers/avatars_helper.rb', line 92 def user_avatar( = {}) avatar = user_avatar_without_link() if [:user] link_to(avatar, user_path([:user])) elsif [:user_email] mail_to([:user_email], avatar) end end |
#user_avatar_without_link(options = {}) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/helpers/avatars_helper.rb', line 59 def user_avatar_without_link( = {}) avatar_size = [:size] || 16 user_name = [:user].try(:name) || [:user_name] avatar_url = user_avatar_url_for(.merge(size: avatar_size)) has_tooltip = [:has_tooltip].nil? ? true : [:has_tooltip] data_attributes = [:data] || {} css_class = %W[avatar s#{avatar_size}].push(*[:css_class]) alt_text = user_name ? "#{user_name}'s avatar" : "default avatar" if has_tooltip css_class.push('has-tooltip') data_attributes[:container] = 'body' end if [:lazy] css_class << 'lazy' data_attributes[:src] = avatar_url avatar_url = LazyImageTagHelper.placeholder_image end = { alt: alt_text, src: avatar_url, data: data_attributes, class: css_class, title: user_name } tag(:img, ) end |