Move some decorator logic to helpers
parent
685681e28a
commit
da5b0c91dc
|
@ -1,4 +1,20 @@
|
||||||
module CommitsHelper
|
module CommitsHelper
|
||||||
|
# Returns a link to the commit author. If the author has a matching user and
|
||||||
|
# is a member of the current @project it will link to the team member page.
|
||||||
|
# Otherwise it will link to the author email as specified in the commit.
|
||||||
|
#
|
||||||
|
# options:
|
||||||
|
# avatar: true will prepend the avatar image
|
||||||
|
# size: size of the avatar image in px
|
||||||
|
def commit_author_link(commit, options = {})
|
||||||
|
commit_person_link(commit, options.merge(source: :author))
|
||||||
|
end
|
||||||
|
|
||||||
|
# Just like #author_link but for the committer.
|
||||||
|
def commit_committer_link(commit, options = {})
|
||||||
|
commit_person_link(commit, options.merge(source: :committer))
|
||||||
|
end
|
||||||
|
|
||||||
def identification_type(line)
|
def identification_type(line)
|
||||||
if line[0] == "+"
|
if line[0] == "+"
|
||||||
"new"
|
"new"
|
||||||
|
@ -105,4 +121,62 @@ module CommitsHelper
|
||||||
line
|
line
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Breadcrumb links for a Project and, if applicable, a tree path
|
||||||
|
def commits_breadcrumbs
|
||||||
|
return unless @project && @ref
|
||||||
|
|
||||||
|
# Add the root project link and the arrow icon
|
||||||
|
crumbs = content_tag(:li) do
|
||||||
|
content_tag(:span, nil, class: 'arrow') +
|
||||||
|
link_to(@project.name, project_commits_path(@project, @ref))
|
||||||
|
end
|
||||||
|
|
||||||
|
if @path
|
||||||
|
parts = @path.split('/')
|
||||||
|
|
||||||
|
parts.each_with_index do |part, i|
|
||||||
|
crumbs += content_tag(:span, '/', class: 'divider')
|
||||||
|
crumbs += content_tag(:li) do
|
||||||
|
# The text is just the individual part, but the link needs all the parts before it
|
||||||
|
link_to part, project_commits_path(@project, tree_join(@ref, parts[0..i].join('/')))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
crumbs.html_safe
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def no_commit_message
|
||||||
|
"--no commit message"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Private: Returns a link to a person. If the person has a matching user and
|
||||||
|
# is a member of the current @project it will link to the team member page.
|
||||||
|
# Otherwise it will link to the person email as specified in the commit.
|
||||||
|
#
|
||||||
|
# options:
|
||||||
|
# source: one of :author or :committer
|
||||||
|
# avatar: true will prepend the avatar image
|
||||||
|
# size: size of the avatar image in px
|
||||||
|
def commit_person_link(commit, options = {})
|
||||||
|
source_name = commit.send "#{options[:source]}_name".to_sym
|
||||||
|
source_email = commit.send "#{options[:source]}_email".to_sym
|
||||||
|
text = if options[:avatar]
|
||||||
|
avatar = image_tag(gravatar_icon(source_email, options[:size]), class: "avatar #{"s#{options[:size]}" if options[:size]}", width: options[:size], alt: "")
|
||||||
|
%Q{#{avatar} <span class="commit-#{options[:source]}-name">#{source_name}</span>}
|
||||||
|
else
|
||||||
|
source_name
|
||||||
|
end
|
||||||
|
|
||||||
|
user = User.where('name like ? or email like ?', source_name, source_email).first
|
||||||
|
|
||||||
|
if user.nil?
|
||||||
|
mail_to(source_email, text.html_safe, class: "commit-#{options[:source]}-link")
|
||||||
|
else
|
||||||
|
link_to(text.html_safe, user_path(user), class: "commit-#{options[:source]}-link")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -70,28 +70,26 @@ module TreeHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Breadcrumb links for a Project and, if applicable, a tree path
|
def tree_breadcrumbs(tree, max_links = 2)
|
||||||
def breadcrumbs
|
if tree.path
|
||||||
return unless @project && @ref
|
part_path = ""
|
||||||
|
parts = tree.path.split("\/")
|
||||||
|
|
||||||
# Add the root project link and the arrow icon
|
yield('..', nil) if parts.count > max_links
|
||||||
crumbs = content_tag(:li) do
|
|
||||||
content_tag(:span, nil, class: 'arrow') +
|
|
||||||
link_to(@project.name, project_commits_path(@project, @ref))
|
|
||||||
end
|
|
||||||
|
|
||||||
if @path
|
parts.each do |part|
|
||||||
parts = @path.split('/')
|
part_path = File.join(part_path, part) unless part_path.empty?
|
||||||
|
part_path = part if part_path.empty?
|
||||||
|
|
||||||
parts.each_with_index do |part, i|
|
next unless parts.last(2).include?(part) if parts.count > max_links
|
||||||
crumbs += content_tag(:span, '/', class: 'divider')
|
yield(part, tree_join(tree.ref, part_path))
|
||||||
crumbs += content_tag(:li) do
|
|
||||||
# The text is just the individual part, but the link needs all the parts before it
|
|
||||||
link_to part, project_commits_path(@project, tree_join(@ref, parts[0..i].join('/')))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
crumbs.html_safe
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def up_dir_path tree
|
||||||
|
file = File.join(tree.path, "..")
|
||||||
|
tree_join(tree.ref, file)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue