summaryrefslogtreecommitdiff
path: root/app/helpers
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-03-31 23:46:54 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-03-31 23:46:54 +0300
commitda5b0c91dc79136be4315cf61e5520692e19be8a (patch)
tree2c5d3ad4c39ed9df045917ebfb9f9498afb7a575 /app/helpers
parent685681e28af2cae7c5ba208130ad5b6b4e5c4ed9 (diff)
downloadgitlab-ce-da5b0c91dc79136be4315cf61e5520692e19be8a.tar.gz
Move some decorator logic to helpers
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/commits_helper.rb74
-rw-r--r--app/helpers/tree_helper.rb34
2 files changed, 90 insertions, 18 deletions
diff --git a/app/helpers/commits_helper.rb b/app/helpers/commits_helper.rb
index acdd48e04eb..da209e06421 100644
--- a/app/helpers/commits_helper.rb
+++ b/app/helpers/commits_helper.rb
@@ -1,4 +1,20 @@
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)
if line[0] == "+"
"new"
@@ -105,4 +121,62 @@ module CommitsHelper
line
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
diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb
index fab0085ba73..1cba9476179 100644
--- a/app/helpers/tree_helper.rb
+++ b/app/helpers/tree_helper.rb
@@ -70,28 +70,26 @@ module TreeHelper
end
end
- # Breadcrumb links for a Project and, if applicable, a tree path
- def 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
+ def tree_breadcrumbs(tree, max_links = 2)
+ if tree.path
+ part_path = ""
+ parts = tree.path.split("\/")
+
+ yield('..', nil) if parts.count > max_links
- if @path
- parts = @path.split('/')
+ parts.each do |part|
+ 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|
- 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
+ next unless parts.last(2).include?(part) if parts.count > max_links
+ yield(part, tree_join(tree.ref, part_path))
end
end
+ end
- crumbs.html_safe
+ def up_dir_path tree
+ file = File.join(tree.path, "..")
+ tree_join(tree.ref, file)
end
+
end