commit and diff helpers

This commit is contained in:
Timothy N. Tsvetkov 2011-03-10 16:33:50 +03:00
parent e9b9e044f9
commit 5d4ca333da
2 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,25 @@
module CommitHelper
def render_commit_stats(stats)
res = ["<ul class='diff_stats'>"]
stats.files.each do |filename, adds, deletes, total|
res << "<li>"
res << "<a href='##{h(filename)}'>#{h(filename)}</a>&nbsp;#{total}&nbsp;"
res << "<small class='deletions'>#{(0...deletes).map{|i| "-" }.join}</small>"
res << "<small class='insertions'>#{(0...adds).map{|i| "+" }.join}</small>"
res << "</li>"
end
res << "</ul>"
res.join("\n")
end
def format_commit_message(message)
h(message).gsub("\n", "<br />")
end
def commit_date(date)
I18n.localize(date, { :format => "%d %B %Y" })
end
end

View File

@ -0,0 +1,36 @@
module DiffHelper
def render_inline_diff(commit, diff)
[render_inline_diff_header(commit, diff), render_inline_diff_body(diff.diff), render_inline_diff_footer].join("\n")
end
def render_inline_diff_header(commit, diff)
res = "<a name='#{h(diff.a_path)}'></a>"
if diff.b_path.present?
res += link_to("view file @ #{commit.id}", blob_commit_path(@platform.name, @project.name, commit.id, diff.b_path))
res += "<br />"
end
res += "<table class='diff inline'>
<thead>
<tr>
<td class='comments'>&nbsp;</td>
<td class='line_numbers'></td>
<td class='line_numbers'></td>
<td class=''>&nbsp;</td>
</tr>
</thead>"
res
end
def render_inline_diff_body(diff)
diff_display ||= Diff::Display::Unified.new(diff)
"<tbody>
#{diff_display.render(Git::Diff::InlineCallback.new)}
</tbody>"
end
def render_inline_diff_footer
"</table>"
end
end