Commit c78359a84bc958c7e6d4fca84dc77b25f6b28cf7
1 parent
17cec050
Exists in
master
and in
4 other branches
Generalize CommitDecorator#author_link to #person_link
Showing
1 changed file
with
34 additions
and
14 deletions
Show diff stats
app/decorators/commit_decorator.rb
... | ... | @@ -47,21 +47,15 @@ class CommitDecorator < ApplicationDecorator |
47 | 47 | # Otherwise it will link to the author email as specified in the commit. |
48 | 48 | # |
49 | 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 s16", 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) | |
50 | + # avatar: true will prepend the avatar image | |
51 | + # size: size of the avatar image in px | |
52 | + def author_link(options = {}) | |
53 | + person_link(options.merge source: :author) | |
54 | + end | |
59 | 55 | |
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 | |
56 | + # Just like #author_link but for the committer. | |
57 | + def committer_link(options = {}) | |
58 | + person_link(options.merge source: :committer) | |
65 | 59 | end |
66 | 60 | |
67 | 61 | protected |
... | ... | @@ -69,4 +63,30 @@ class CommitDecorator < ApplicationDecorator |
69 | 63 | def no_commit_message |
70 | 64 | "--no commit message" |
71 | 65 | end |
66 | + | |
67 | + # Private: Returns a link to a person. If the person has a matching user and | |
68 | + # is a member of the current @project it will link to the team member page. | |
69 | + # Otherwise it will link to the person email as specified in the commit. | |
70 | + # | |
71 | + # options: | |
72 | + # source: one of :author or :committer | |
73 | + # avatar: true will prepend the avatar image | |
74 | + # size: size of the avatar image in px | |
75 | + def person_link(options = {}) | |
76 | + source_name = send "#{options[:source]}_name".to_sym | |
77 | + source_email = send "#{options[:source]}_email".to_sym | |
78 | + text = if options[:avatar] | |
79 | + avatar = h.image_tag h.gravatar_icon(source_email, options[:size]), class: "avatar #{"s#{options[:size]}" if options[:size]}", width: options[:size] | |
80 | + %Q{#{avatar} <span class="commit-#{options[:source]}-name">#{source_name}</span>} | |
81 | + else | |
82 | + source_name | |
83 | + end | |
84 | + team_member = @project.try(:team_member_by_name_or_email, source_name, source_email) | |
85 | + | |
86 | + if team_member.nil? | |
87 | + h.mail_to source_email, text.html_safe, class: "commit-#{options[:source]}-link" | |
88 | + else | |
89 | + h.link_to text, h.project_team_member_path(@project, team_member), class: "commit-#{options[:source]}-link" | |
90 | + end | |
91 | + end | |
72 | 92 | end | ... | ... |