Commit e60185699b0cd34fe3ae37db6db318478232c84b
1 parent
b1be377f
Exists in
master
and in
4 other branches
Add 'breadcrumbs' helper for Commit breadcrumb links
Closes #1731
Showing
2 changed files
with
26 additions
and
8 deletions
Show diff stats
app/helpers/tree_helper.rb
@@ -67,4 +67,29 @@ module TreeHelper | @@ -67,4 +67,29 @@ module TreeHelper | ||
67 | can?(current_user, :push_code, @project) | 67 | can?(current_user, :push_code, @project) |
68 | end | 68 | end |
69 | end | 69 | end |
70 | + | ||
71 | + # Breadcrumb links for a Project and, if applicable, a tree path | ||
72 | + def breadcrumbs | ||
73 | + return unless @project && @ref | ||
74 | + | ||
75 | + # Add the root project link and the arrow icon | ||
76 | + crumbs = content_tag(:li) do | ||
77 | + content_tag(:span, nil, class: 'arrow') + | ||
78 | + link_to(@project.name, project_commits_path(@project, @ref)) | ||
79 | + end | ||
80 | + | ||
81 | + if @path | ||
82 | + parts = @path.split('/') | ||
83 | + | ||
84 | + parts.each_with_index do |part, i| | ||
85 | + crumbs += content_tag(:span, '/', class: 'divider') | ||
86 | + crumbs += content_tag(:li) do | ||
87 | + # The text is just the individual part, but the link needs all the parts before it | ||
88 | + link_to part, project_commits_path(@project, tree_join(@ref, parts[0..i].join('/'))) | ||
89 | + end | ||
90 | + end | ||
91 | + end | ||
92 | + | ||
93 | + crumbs.html_safe | ||
94 | + end | ||
70 | end | 95 | end |
app/views/commits/show.html.haml
@@ -2,14 +2,7 @@ | @@ -2,14 +2,7 @@ | ||
2 | 2 | ||
3 | - if @path.present? | 3 | - if @path.present? |
4 | %ul.breadcrumb | 4 | %ul.breadcrumb |
5 | - %li | ||
6 | - %span.arrow | ||
7 | - = link_to project_commits_path(@project) do | ||
8 | - = @project.name | ||
9 | - %span.divider | ||
10 | - \/ | ||
11 | - %li | ||
12 | - %a{href: "#"}= @path.split("/").join(" / ") | 5 | + = breadcrumbs |
13 | 6 | ||
14 | %div{id: dom_id(@project)} | 7 | %div{id: dom_id(@project)} |
15 | #commits_list= render "commits" | 8 | #commits_list= render "commits" |