2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-04-01 01:36:34 +01:00
|
|
|
module GitHelper
|
|
|
|
|
|
|
|
def render_path
|
|
|
|
# TODO: Looks ugly, rewrite with clear mind.
|
|
|
|
if @path.present?
|
|
|
|
if @treeish == "master"
|
2011-10-24 11:19:04 +01:00
|
|
|
res = "#{link_to @project.name, tree_path(@project)} / "
|
2011-04-01 01:36:34 +01:00
|
|
|
else
|
2011-10-24 11:19:04 +01:00
|
|
|
res = "#{link_to @project.name, tree_path(@project, @treeish)} / "
|
2011-04-01 01:36:34 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
parts = @path.split("/")
|
|
|
|
|
|
|
|
current_path = parts.first
|
2011-10-24 11:19:04 +01:00
|
|
|
res += parts.length == 1 ? parts.first : link_to(parts.first, tree_path(@project, @treeish, current_path)) + " / "
|
2011-04-01 01:36:34 +01:00
|
|
|
|
|
|
|
parts[1..-2].each do |part|
|
|
|
|
current_path = File.join([current_path, part].compact)
|
2011-10-24 11:19:04 +01:00
|
|
|
res += link_to(part, tree_path(@project, @treeish, current_path))
|
2011-04-01 01:36:34 +01:00
|
|
|
res += " / "
|
|
|
|
end
|
|
|
|
|
|
|
|
res += parts.last if parts.length > 1
|
|
|
|
else
|
2011-10-24 11:19:04 +01:00
|
|
|
res = "#{link_to @project.name, tree_path(@project)} /"
|
2011-04-01 01:36:34 +01:00
|
|
|
end
|
|
|
|
|
2012-02-04 20:12:37 +00:00
|
|
|
res.encode_to_default.html_safe
|
2011-04-01 01:36:34 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def render_line_numbers(n)
|
|
|
|
res = ""
|
|
|
|
1.upto(n) {|i| res += "<span>#{i}</span>\n" }
|
|
|
|
|
|
|
|
res
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_blob(blob)
|
|
|
|
res = ""
|
2012-02-04 20:12:37 +00:00
|
|
|
blob.data.force_encoding(Encoding.default_internal || Encoding::UTF_8).split("\n").collect do |line|
|
|
|
|
"<div>#{line.present? ? h(line) : "<br>"}</div>"
|
|
|
|
end.join
|
2011-04-01 01:36:34 +01:00
|
|
|
end
|
|
|
|
|
2012-01-20 18:31:01 +00:00
|
|
|
def choose_render_way(blob)
|
|
|
|
return :image if blob.mime_type.match(/image/)
|
2012-01-20 18:40:00 +00:00
|
|
|
return :text if blob.mime_type.match(/text|xml|json/)
|
2012-01-20 18:31:01 +00:00
|
|
|
:binary
|
|
|
|
end
|
2012-02-04 20:12:37 +00:00
|
|
|
|
|
|
|
def force_encoding_to_site(string)
|
|
|
|
string.dup.force_encoding(Encoding.default_internal || Encoding::UTF_8)
|
|
|
|
end
|
|
|
|
|
2012-01-20 18:31:01 +00:00
|
|
|
end
|