debian-mirror-gitlab/app/helpers/avatars_helper.rb

51 lines
1.4 KiB
Ruby
Raw Normal View History

2016-08-24 12:49:21 +05:30
module AvatarsHelper
def author_avatar(commit_or_event, options = {})
user_avatar(options.merge({
user: commit_or_event.author,
user_name: commit_or_event.author_name,
user_email: commit_or_event.author_email,
2016-11-03 12:29:30 +05:30
css_class: 'hidden-xs'
2016-08-24 12:49:21 +05:30
}))
end
2017-09-10 17:25:29 +05:30
def user_avatar_without_link(options = {})
2016-08-24 12:49:21 +05:30
avatar_size = options[:size] || 16
user_name = options[:user].try(:name) || options[:user_name]
2017-09-10 17:25:29 +05:30
avatar_url = options[:url] || avatar_icon(options[:user] || options[:user_email], avatar_size)
has_tooltip = options[:has_tooltip].nil? ? true : options[:has_tooltip]
2018-03-17 18:26:18 +05:30
data_attributes = options[:data] || {}
2017-09-10 17:25:29 +05:30
css_class = %W[avatar s#{avatar_size}].push(*options[:css_class])
if has_tooltip
css_class.push('has-tooltip')
2018-03-17 18:26:18 +05:30
data_attributes[:container] = 'body'
2017-09-10 17:25:29 +05:30
end
2018-03-17 18:26:18 +05:30
if options[:lazy]
css_class << 'lazy'
data_attributes[:src] = avatar_url
avatar_url = LazyImageTagHelper.placeholder_image
end
image_options = {
alt: "#{user_name}'s avatar",
src: avatar_url,
data: data_attributes,
2017-09-10 17:25:29 +05:30
class: css_class,
2018-03-17 18:26:18 +05:30
title: user_name
}
tag(:img, image_options)
2017-09-10 17:25:29 +05:30
end
def user_avatar(options = {})
avatar = user_avatar_without_link(options)
2016-08-24 12:49:21 +05:30
if options[:user]
link_to(avatar, user_path(options[:user]))
elsif options[:user_email]
mail_to(options[:user_email], avatar)
end
end
end