BigW Consortium Gitlab

avatars_helper.rb 1.12 KB
Newer Older
1 2 3 4 5 6
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,
7
      css_class: 'hidden-xs'
8 9 10
    }))
  end

11
  def user_avatar_without_link(options = {})
12 13
    avatar_size = options[:size] || 16
    user_name = options[:user].try(:name) || options[:user_name]
14
    css_class = options[:css_class] || ''
15 16 17 18 19 20 21 22 23
    avatar_url = options[:url] || avatar_icon(options[:user] || options[:user_email], avatar_size)
    data_attributes = { container: 'body' }

    if options[:lazy]
      data_attributes[:src] = avatar_url
    end

    image_tag(
      options[:lazy] ? '' : avatar_url,
24
      class: "avatar has-tooltip s#{avatar_size} #{css_class}",
25
      alt: "#{user_name}'s avatar",
26
      title: user_name,
27
      data: data_attributes
28
    )
29 30 31 32
  end

  def user_avatar(options = {})
    avatar = user_avatar_without_link(options)
33 34 35 36 37 38 39 40

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