Welcome to mirror list, hosted at ThFree Co, Russian Federation.

tree_decorator.rb « decorators « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 754868f58054715a46bedb4e65eddc3ff92bfa2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class TreeDecorator < ApplicationDecorator
  decorates :tree

  def breadcrumbs(max_links = 2)
    if path
      part_path = ""
      parts = path.split("\/")

      #parts = parts[0...-1] if is_blob?

      yield(h.link_to("..", "#", remote: true)) if parts.count > max_links

      parts.each do |part|
        part_path = File.join(part_path, part) unless part_path.empty?
        part_path = part if part_path.empty?

        next unless parts.last(2).include?(part) if parts.count > max_links
        yield(h.link_to(h.truncate(part, length: 40), h.project_tree_path(project, h.tree_join(ref, part_path)), remote: true))
      end
    end
  end

  def up_dir?
    path.present?
  end

  def up_dir_path
    file = File.join(path, "..")
    h.project_tree_path(project, h.tree_join(ref, file))
  end

  def history_path
    h.project_commits_path(project, h.tree_join(ref, path))
  end

  def mb_size
    size = (tree.size / 1024)
    if size < 1024
      "#{size} KB"
    else
      "#{size/1024} MB"
    end
  end
end