gitlabhq/app/decorators/tree_decorator.rb

34 lines
735 B
Ruby
Raw Normal View History

2011-11-20 21:32:12 +01:00
class TreeDecorator < ApplicationDecorator
decorates :tree
def breadcrumbs(max_links = 2)
if path
part_path = ""
parts = path.split("\/")
2013-01-03 20:09:18 +01:00
yield('..', nil) if parts.count > max_links
2011-11-20 21:32:12 +01:00
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
2013-01-03 20:09:18 +01:00
yield(part, h.tree_join(ref, part_path))
2011-11-20 21:32:12 +01:00
end
end
end
def up_dir?
path.present?
2011-11-20 21:32:12 +01:00
end
def up_dir_path
file = File.join(path, "..")
2013-01-03 20:09:18 +01:00
h.tree_join(ref, file)
2011-11-20 21:32:12 +01:00
end
2012-10-16 08:48:55 +02:00
def readme
@readme ||= contents.find { |c| c.is_a?(Grit::Blob) and c.name =~ /^readme/i }
end
2011-11-20 21:32:12 +01:00
end