commit and diff helpers
This commit is contained in:
parent
e9b9e044f9
commit
5d4ca333da
|
@ -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> #{total} "
|
||||
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
|
|
@ -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'> </td>
|
||||
<td class='line_numbers'></td>
|
||||
<td class='line_numbers'></td>
|
||||
<td class=''> </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
|
Loading…
Reference in New Issue