diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-03-31 23:46:54 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-03-31 23:46:54 +0300 |
commit | da5b0c91dc79136be4315cf61e5520692e19be8a (patch) | |
tree | 2c5d3ad4c39ed9df045917ebfb9f9498afb7a575 /app/helpers/tree_helper.rb | |
parent | 685681e28af2cae7c5ba208130ad5b6b4e5c4ed9 (diff) | |
download | gitlab-ce-da5b0c91dc79136be4315cf61e5520692e19be8a.tar.gz |
Move some decorator logic to helpers
Diffstat (limited to 'app/helpers/tree_helper.rb')
-rw-r--r-- | app/helpers/tree_helper.rb | 34 |
1 files changed, 16 insertions, 18 deletions
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 |