2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-03-10 13:33:50 +00:00
|
|
|
module DiffHelper
|
|
|
|
|
2012-07-19 17:42:37 +01:00
|
|
|
def render_diff(diff, diff_counter)
|
2011-04-01 04:44:21 +01:00
|
|
|
diff_display ||= Diff::Display::Unified.new(diff.diff)
|
2012-07-19 17:42:37 +01:00
|
|
|
path = if @pull
|
|
|
|
"#{polymorphic_path [@project, @pull]}/diff"
|
|
|
|
elsif @commit
|
|
|
|
"#{commit_path @project, @commit}"
|
|
|
|
end
|
2012-02-29 01:30:22 +00:00
|
|
|
#res = "<a name='#{h(diff.a_path)}'></a>"
|
2011-03-10 13:33:50 +00:00
|
|
|
|
2012-02-29 01:30:22 +00:00
|
|
|
res = "<table class='diff inline' cellspacing='0' cellpadding='0'>"
|
2011-04-01 04:44:21 +01:00
|
|
|
res += "<tbody>"
|
2012-07-19 17:42:37 +01:00
|
|
|
res += diff_display.render(Git::Diff::InlineCallback.new(diff_counter, path))
|
2011-04-01 04:44:21 +01:00
|
|
|
res += "</tbody>"
|
|
|
|
res += "</table>"
|
2011-03-10 13:33:50 +00:00
|
|
|
|
2012-03-21 19:55:14 +00:00
|
|
|
res.html_safe
|
2011-03-10 13:33:50 +00:00
|
|
|
end
|
|
|
|
|
2012-05-29 18:09:43 +01:00
|
|
|
def render_diff_stats(stats)
|
2012-07-18 19:02:27 +01:00
|
|
|
path = "#{polymorphic_path [@project, @pull]}/diff"
|
2012-05-29 18:09:43 +01:00
|
|
|
res = ["<table class='commit_stats'>"]
|
2012-06-07 20:20:06 +01:00
|
|
|
stats.each_with_index do |stat, ind|
|
2012-05-29 18:09:43 +01:00
|
|
|
res << "<tr>"
|
2012-07-18 19:02:27 +01:00
|
|
|
res << "<td>#{link_to stat.filename.rtruncate(120), "#{path}#diff-#{ind}"}</td>"
|
2012-05-29 18:09:43 +01:00
|
|
|
res << "<td class='diffstat'>"
|
|
|
|
res << I18n.t("layout.projects.inline_changes_count", :count => stat.additions + stat.deletions).strip +
|
|
|
|
" (" +
|
|
|
|
I18n.t("layout.projects.inline_additions_count", :count => stat.additions).strip +
|
|
|
|
", " +
|
|
|
|
I18n.t("layout.projects.inline_deletions_count", :count => stat.deletions).strip +
|
|
|
|
")"
|
|
|
|
res << "</td>"
|
|
|
|
end
|
|
|
|
res << "</table>"
|
|
|
|
|
|
|
|
res.join("\n").html_safe.default_encoding!
|
|
|
|
end
|
|
|
|
|
2012-01-30 20:39:34 +00:00
|
|
|
end
|