Module: AvatarsHelper
- Included in:
- Banzai::Filter::CommitTrailersFilter, Gitlab::BlamePresenter, Groups::GroupMembersHelper, MemberEntity
- Defined in:
- app/helpers/avatars_helper.rb
Constant Summary collapse
- DEFAULT_AVATAR_PATH =
'no_avatar.png'
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, by_commit_email: false) ⇒ Object
- #avatar_icon_for_user(user = nil, size = nil, scale = 2, only_path: true, current_user: nil) ⇒ Object
- #avatar_without_link(resource, options = {}) ⇒ Object
- #default_avatar ⇒ Object
- #gravatar_icon(user_email = '', size = nil, scale = 2) ⇒ Object
- #user_avatar(options = {}) ⇒ Object
- #user_avatar_without_link(options = {}) ⇒ Object
Instance Method Details
#author_avatar(commit_or_event, options = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/helpers/avatars_helper.rb', line 51 def (commit_or_event, = {}) [:css_class] ||= "gl-hidden @sm/panel:gl-inline-block" if Feature.enabled?(:cached_author_avatar_helper, .delete(:project)) Gitlab::AvatarCache.by_email(commit_or_event., commit_or_event., ) do user_avatar(.merge({ user: commit_or_event., user_name: commit_or_event., user_email: commit_or_event. })) end.html_safe # rubocop: disable Rails/OutputSafety -- this is only needed as the AvatarCache is a direct Redis cache else user_avatar(.merge({ user: commit_or_event., user_name: commit_or_event., user_email: commit_or_event. })) end 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.
8 9 10 11 12 13 14 15 16 |
# File 'app/helpers/avatars_helper.rb', line 8 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, by_commit_email: false) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/helpers/avatars_helper.rb', line 18 def avatar_icon_for_email(email = nil, size = nil, scale = 2, only_path: true, by_commit_email: false) return default_avatar if email.blank? Gitlab::AvatarCache.by_email(email, size, scale, only_path) do avatar_icon_by_user_email_or_gravatar( email, size, scale, only_path: only_path, by_commit_email: by_commit_email ) end end |
#avatar_icon_for_user(user = nil, size = nil, scale = 2, only_path: true, current_user: nil) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'app/helpers/avatars_helper.rb', line 32 def avatar_icon_for_user(user = nil, size = nil, scale = 2, only_path: true, current_user: nil) return gravatar_icon(nil, size, scale) unless user return default_avatar if blocked_or_unconfirmed?(user) && !can_admin?(current_user) image_size = !size.nil? ? size * 2 : size user_avatar = user.avatar_url(size: image_size, only_path: only_path) user_avatar || default_avatar end |
#avatar_without_link(resource, options = {}) ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'app/helpers/avatars_helper.rb', line 114 def avatar_without_link(resource, = {}) case resource when Namespaces::UserNamespace user_avatar_without_link(.merge(user: resource.first_owner)) when Group render Pajamas::AvatarComponent.new(resource, class: 'gl-avatar-circle gl-mr-3', size: 32) end end |
#default_avatar ⇒ Object
47 48 49 |
# File 'app/helpers/avatars_helper.rb', line 47 def default_avatar ActionController::Base.helpers.image_path(DEFAULT_AVATAR_PATH) end |
#gravatar_icon(user_email = '', size = nil, scale = 2) ⇒ Object
42 43 44 45 |
# File 'app/helpers/avatars_helper.rb', line 42 def gravatar_icon(user_email = '', size = nil, scale = 2) GravatarService.new.execute(user_email, size, scale) || default_avatar end |
#user_avatar(options = {}) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'app/helpers/avatars_helper.rb', line 71 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
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/helpers/avatars_helper.rb', line 81 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 |