rosa-build/app/helpers/diff_helper.rb

43 lines
1.4 KiB
Ruby
Raw Normal View History

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)
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
#res = "<a name='#{h(diff.a_path)}'></a>"
2011-03-10 13:33:50 +00:00
res = "<table class='diff inline' cellspacing='0' cellpadding='0'>"
res += "<tbody>"
2012-07-19 17:42:37 +01:00
res += diff_display.render(Git::Diff::InlineCallback.new(diff_counter, path))
res += "</tbody>"
res += "</table>"
2011-03-10 13:33:50 +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'>"]
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