2016-07-08 20:47:05 -04:00
|
|
|
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-10-06 06:32:58 -04:00
|
|
|
css_class: 'hidden-xs'
|
2016-07-08 20:47:05 -04:00
|
|
|
}))
|
|
|
|
end
|
|
|
|
|
2017-06-02 03:42:18 -04:00
|
|
|
def user_avatar_without_link(options = {})
|
2016-07-08 20:47:05 -04:00
|
|
|
avatar_size = options[:size] || 16
|
|
|
|
user_name = options[:user].try(:name) || options[:user_name]
|
2017-06-02 03:42:18 -04:00
|
|
|
avatar_url = options[:url] || avatar_icon(options[:user] || options[:user_email], avatar_size)
|
2017-08-22 17:41:17 -04:00
|
|
|
has_tooltip = options[:has_tooltip].nil? ? true : options[:has_tooltip]
|
|
|
|
data_attributes = {}
|
|
|
|
css_class = %W[avatar s#{avatar_size}].push(*options[:css_class])
|
|
|
|
|
|
|
|
if has_tooltip
|
|
|
|
css_class.push('has-tooltip')
|
|
|
|
data_attributes = { container: 'body' }
|
|
|
|
end
|
2017-06-02 03:42:18 -04:00
|
|
|
|
|
|
|
image_tag(
|
2017-07-24 13:36:52 -04:00
|
|
|
avatar_url,
|
2017-08-22 17:41:17 -04:00
|
|
|
class: css_class,
|
2016-07-08 20:47:05 -04:00
|
|
|
alt: "#{user_name}'s avatar",
|
2016-09-06 05:36:09 -04:00
|
|
|
title: user_name,
|
2017-08-07 17:44:42 -04:00
|
|
|
data: data_attributes,
|
|
|
|
lazy: true
|
2016-07-08 20:47:05 -04:00
|
|
|
)
|
2017-06-02 03:42:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def user_avatar(options = {})
|
|
|
|
avatar = user_avatar_without_link(options)
|
2016-07-08 20:47:05 -04:00
|
|
|
|
|
|
|
if options[:user]
|
|
|
|
link_to(avatar, user_path(options[:user]))
|
|
|
|
elsif options[:user_email]
|
|
|
|
mail_to(options[:user_email], avatar)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|