BigW Consortium Gitlab

avatars_helper.rb 807 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
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,
    }))
  end

  def user_avatar(options = {})
    avatar_size = options[:size] || 16
    user_name = options[:user].try(:name) || options[:user_name]
    avatar = image_tag(
      avatar_icon(options[:user] || options[:user_email], avatar_size),
      class: "avatar has-tooltip hidden-xs s#{avatar_size}",
      alt: "#{user_name}'s avatar",
17 18
      title: user_name,
      data: { container: 'body' }
19 20 21 22 23 24 25 26 27
    )

    if options[:user]
      link_to(avatar, user_path(options[:user]))
    elsif options[:user_email]
      mail_to(options[:user_email], avatar)
    end
  end
end