Commit aef2031ad6bac1d3c35e5beb3b82fb0abfd3c1de

Authored by Riyad Preukschas
1 parent b3a5f0a7

Add CommitDecorator#author_link

Showing 1 changed file with 22 additions and 0 deletions   Show diff stats
app/decorators/commit_decorator.rb
... ... @@ -42,6 +42,28 @@ class CommitDecorator < ApplicationDecorator
42 42 end
43 43 end
44 44  
  45 + # Returns a link to the commit author. If the author has a matching user and
  46 + # is a member of the current @project it will link to the team member page.
  47 + # Otherwise it will link to the author email as specified in the commit.
  48 + #
  49 + # options:
  50 + # avatar: true will prepend avatar image
  51 + def author_link(options)
  52 + text = if options[:avatar]
  53 + avatar = h.image_tag h.gravatar_icon(author_email), class: "avatar", width: 16
  54 + "#{avatar} #{author_name}"
  55 + else
  56 + author_name
  57 + end
  58 + team_member = @project.try(:team_member_by_name_or_email, author_name, author_email)
  59 +
  60 + if team_member.nil?
  61 + h.mail_to author_email, text.html_safe, class: "commit-author-link"
  62 + else
  63 + h.link_to text, h.project_team_member_path(@project, team_member), class: "commit-author-link"
  64 + end
  65 + end
  66 +
45 67 protected
46 68  
47 69 def no_commit_message
... ...