the aWeSOME commit view (with REALLY AWESOME view for git diffs)
This commit is contained in:
parent
6ee2a4ded1
commit
efbd64e924
|
@ -1,22 +1,23 @@
|
|||
module CommitHelper
|
||||
|
||||
def render_commit_stats(stats)
|
||||
res = ["<ul class='diff_stats'>"]
|
||||
res = ["<table class='commit_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>"
|
||||
res << "<tr>"
|
||||
res << "<td><a href='##{h(filename)}'>#{h(filename)}</a></td>"
|
||||
res << "<td>#{total}</td>"
|
||||
res << "<td><small class='deletions'>#{(0...deletes).map{|i| "-" }.join}</small>"
|
||||
res << "<small class='insertions'>#{(0...adds).map{|i| "+" }.join}</small></td>"
|
||||
res << "</tr>"
|
||||
end
|
||||
res << "</ul>"
|
||||
res << "</table>"
|
||||
|
||||
res.join("\n")
|
||||
res.join("\n").html_safe
|
||||
end
|
||||
|
||||
def format_commit_message(message)
|
||||
h(message).gsub("\n", "<br />").html_safe
|
||||
end
|
||||
# def format_commit_message(message)
|
||||
# h(message).gsub("\n", "<br />").html_safe
|
||||
# end
|
||||
|
||||
def commit_date(date)
|
||||
I18n.localize(date, { :format => "%d %B %Y" })
|
||||
|
|
|
@ -1,36 +1,17 @@
|
|||
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)
|
||||
def render_diff(diff)
|
||||
diff_display ||= Diff::Display::Unified.new(diff.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, @repository, @project, commit.id, diff.b_path))
|
||||
res += "<br />"
|
||||
|
||||
res += "<table class='diff inline' cellspacing='0' cellpadding='0'>"
|
||||
res += "<tbody>"
|
||||
res += diff_display.render(Git::Diff::InlineCallback.new)
|
||||
res += "</tbody>"
|
||||
res += "</table>"
|
||||
|
||||
res.html_safe
|
||||
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
|
|
@ -0,0 +1,15 @@
|
|||
.block
|
||||
.content
|
||||
.inner
|
||||
|
||||
%a{ :name => h(commit_diff.a_path) }
|
||||
|
||||
.blob_header
|
||||
.size= h(commit_diff.a_path)
|
||||
- if commit_diff.b_path.present?
|
||||
.buttons
|
||||
= link_to("view file @ #{short_hash_id(@commit.id)}", blob_commit_path(@platform, @repository, @project, @commit.id, commit_diff.b_path))
|
||||
.clear
|
||||
|
||||
.diff_data
|
||||
= render_diff(commit_diff)
|
|
@ -17,21 +17,16 @@
|
|||
.inner
|
||||
= render :partial => "git/commits/commits", :object => [@commit]
|
||||
|
||||
.block
|
||||
.content
|
||||
.inner
|
||||
.patch_and_diff
|
||||
#{link_to "raw diff", commit_path(@platform, @repository, @project, @commit.id, :diff)} | #{link_to "patch", commit_path(@platform, @repository, @project, @commit.id, :patch)}
|
||||
|
||||
.clear
|
||||
|
||||
= render_commit_stats(@commit.stats)
|
||||
|
||||
= render :partial => "git/commits/commit_diff", :collection => @commit.diffs
|
||||
|
||||
-#%h3 Commit: #{@commit.id}
|
||||
-#
|
||||
-#= render :partial => "commit_pane", :locals => { :commit => @commit}
|
||||
-#
|
||||
-##{link_to "raw diff", commit_path(@platform, @repository, @project, @commit.id, :diff)} | #{link_to "patch", commit_path(@platform, @repository, @project, @commit.id, :patch)}
|
||||
-#
|
||||
-#.row.commit_message
|
||||
-# %code!= format_commit_message(@commit.message)
|
||||
-#
|
||||
-#.row.commit_stats
|
||||
-# != render_commit_stats(@commit.stats)
|
||||
-#
|
||||
-#- @commit.diffs.each do |diff|
|
||||
-# != render_inline_diff(@commit, diff)
|
||||
- content_for :sidebar, render(:partial => 'git/shared/sidebar')
|
||||
|
|
|
@ -1,45 +1,54 @@
|
|||
module Git
|
||||
module Diff
|
||||
class InlineCallback < ::Diff::Renderer::Base
|
||||
def before_headerblock(block)
|
||||
end
|
||||
|
||||
def after_headerblock(block)
|
||||
end
|
||||
|
||||
def headerline(line)
|
||||
"<tr class='header'>
|
||||
<td class='line_numbers'>...</td>
|
||||
<td class='line_numbers'>...</td>
|
||||
<td class='header'>#{line}</td>
|
||||
</tr>"
|
||||
end
|
||||
|
||||
def addline(line)
|
||||
"<tr class='changes'>
|
||||
<td></td>
|
||||
<td class='line_numbers'></td>
|
||||
<td class='line_numbers'>#{line.new_number}</td>
|
||||
<td class='code ins'>#{render_line(line)}</td>
|
||||
<td class='code ins'><pre>#{render_line(line)}</pre></td>
|
||||
</tr>"
|
||||
end
|
||||
|
||||
def remline(line)
|
||||
"<tr class='changes'>
|
||||
<td></td>
|
||||
<td class='line_numbers'>#{line.old_number}</td>
|
||||
<td class='line_numbers'></td>
|
||||
<td class='code del'>#{render_line(line)}</td>
|
||||
<td class='code del'><pre>#{render_line(line)}</pre></td>
|
||||
</tr>"
|
||||
end
|
||||
|
||||
def modline(line)
|
||||
"<tr clas='chanes line'>
|
||||
<td></td>
|
||||
<td class='line_numbers'>#{line.old_number}</td>
|
||||
<td class='line_numbers'>#{line.new_number}</td>
|
||||
<td class='code unchanged modline'>#{render_line(line)}</td>
|
||||
<td class='code unchanged modline'><pre>#{render_line(line)}</pre></td>
|
||||
</tr>"
|
||||
end
|
||||
|
||||
def unmodline(line)
|
||||
"<tr class='changes unmodline'>
|
||||
<td></td>
|
||||
<td class='line_numbers'>#{line.old_number}</td>
|
||||
<td class='line_numbers'>#{line.new_number}</td>
|
||||
<td class='code unchanged unmodline'>#{render_line(line)}</td>
|
||||
<td class='code unchanged unmodline'><pre>#{render_line(line)}</pre></td>
|
||||
</tr>"
|
||||
end
|
||||
|
||||
def sepline(line)
|
||||
"<tr class='changes hunk-sep'>
|
||||
<td></td>
|
||||
<td class='line_numbers line_num_cut'>…</td>
|
||||
<td class='line_numbers line_num_cut'>…</td>
|
||||
<td class='code cut-line'></td>
|
||||
|
@ -48,10 +57,9 @@ module Git
|
|||
|
||||
def nonewlineline(line)
|
||||
"<tr class='changes'>
|
||||
<td></td>
|
||||
<td class='line_numbers'>#{line.old_number}</td>
|
||||
<td class='line_numbers'>#{line.new_number}</td>
|
||||
<td class='code modline unmodline'>#{render_line(line)}</td>
|
||||
<td class='code modline unmodline'><pre>#{render_line(line)}</pre></td>
|
||||
</tr>"
|
||||
end
|
||||
|
||||
|
|
|
@ -107,6 +107,7 @@ table.blob td.blob pre {
|
|||
border-bottom: 1px solid #DDDDDD;
|
||||
font-family: Monaco,"Courier New","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace;
|
||||
padding: 5px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.blob_header .size {
|
||||
|
@ -118,3 +119,72 @@ table.blob td.blob pre {
|
|||
float: right;
|
||||
margin-right: 15px;
|
||||
}
|
||||
|
||||
table.commit_stats {
|
||||
width: 100%;
|
||||
margin-top: 12px;
|
||||
line-height: 1.4em;
|
||||
}
|
||||
|
||||
table.commit_stats tr {
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.diff_data {
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
table.diff {
|
||||
line-height: 1.4em;
|
||||
font-family: 'Bitstream Vera Sans Mono','Courier',monospace;
|
||||
border: 1px solid #EAEAEA;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
table.diff tr td.line_numbers {
|
||||
background-color: #ECECEC;
|
||||
border-right: 1px solid #DDDDDD;
|
||||
color: #AAAAAA;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
table.diff tr td.header {
|
||||
line-height: 1.4em;
|
||||
font-family: 'Bitstream Vera Sans Mono','Courier',monospace;
|
||||
width: 100%;
|
||||
background-color: #ECECEC;
|
||||
color: #AAAAAA;
|
||||
padding-left: 10px;
|
||||
}
|
||||
|
||||
table.diff tr td.code {
|
||||
width: 100%;
|
||||
padding-left: 10px;
|
||||
}
|
||||
|
||||
table.diff tr td.code.del {
|
||||
background-color: #FFDDDD;
|
||||
}
|
||||
|
||||
table.diff tr td.code.del .idiff {
|
||||
background-color: #F2ACAD;
|
||||
}
|
||||
|
||||
table.diff tr td.code.ins {
|
||||
background-color: #DDFFDD;
|
||||
}
|
||||
|
||||
table.diff tr td.code.ins .idiff {
|
||||
background-color: #BAFBAD;
|
||||
}
|
||||
|
||||
table.diff .diff-content {
|
||||
}
|
||||
|
||||
.patch_and_diff {
|
||||
margin-top: 10px;
|
||||
float: right;
|
||||
margin-right: 10px;
|
||||
}
|
Loading…
Reference in New Issue