[refs #90] add commit/pull lines ref

This commit is contained in:
Alexander Machehin 2012-07-19 22:42:37 +06:00
parent b24a4a35b2
commit 35b953ac11
5 changed files with 34 additions and 14 deletions

View File

@ -1184,3 +1184,7 @@ table.tablesorter tr td.no_results {
.label-bootstrap.label-info.font14 a { .label-bootstrap.label-info.font14 a {
color: #FFFFFF; color: #FFFFFF;
} }
.line_numbers a {
color: #999999;
}

View File

@ -1,14 +1,18 @@
# -*- encoding : utf-8 -*- # -*- encoding : utf-8 -*-
module DiffHelper module DiffHelper
def render_diff(diff) def render_diff(diff, diff_counter)
diff_display ||= Diff::Display::Unified.new(diff.diff) diff_display ||= Diff::Display::Unified.new(diff.diff)
path = if @pull
"#{polymorphic_path [@project, @pull]}/diff"
elsif @commit
"#{commit_path @project, @commit}"
end
#res = "<a name='#{h(diff.a_path)}'></a>" #res = "<a name='#{h(diff.a_path)}'></a>"
res = "<table class='diff inline' cellspacing='0' cellpadding='0'>" res = "<table class='diff inline' cellspacing='0' cellpadding='0'>"
res += "<tbody>" res += "<tbody>"
res += diff_display.render(Git::Diff::InlineCallback.new) res += diff_display.render(Git::Diff::InlineCallback.new(diff_counter, path))
res += "</tbody>" res += "</tbody>"
res += "</table>" res += "</table>"

View File

@ -7,4 +7,4 @@
.r= link_to "view file @ #{short_hash_id(commit_id)}", blob_path(@project, commit_id, commit_diff.b_path) .r= link_to "view file @ #{short_hash_id(commit_id)}", blob_path(@project, commit_id, commit_diff.b_path)
.clear .clear
.diff_data= render_diff(commit_diff) unless (@git_repository.tree(commit_id) / commit_diff.b_path).binary? .diff_data= render_diff(commit_diff, commit_diff_counter) unless (@git_repository.tree(commit_id) / commit_diff.b_path).binary?

View File

@ -6,5 +6,4 @@
- if pull_diff.b_path.present? - if pull_diff.b_path.present?
.r= link_to "view file @ #{short_hash_id(commit_id)}", blob_path(@project, commit_id, pull_diff.b_path) .r= link_to "view file @ #{short_hash_id(commit_id)}", blob_path(@project, commit_id, pull_diff.b_path)
.clear .clear
.diff_data= render_diff(pull_diff, pull_diff_counter) unless (Git::Repository.new(@pull.path).tree(commit_id) / pull_diff.b_path).binary?
.diff_data= render_diff(pull_diff) unless (Git::Repository.new(@pull.path).tree(commit_id) / pull_diff.b_path).binary?

View File

@ -2,6 +2,11 @@
module Git module Git
module Diff module Diff
class InlineCallback < ::Diff::Renderer::Base class InlineCallback < ::Diff::Renderer::Base
def initialize diff_counter, path
@diff_counter = diff_counter
@path = path
end
def before_headerblock(block) def before_headerblock(block)
end end
@ -17,33 +22,39 @@ module Git
end end
def addline(line) def addline(line)
id = "F#{@diff_counter}R#{line.new_number}"
"<tr class='changes'> "<tr class='changes'>
<td class='line_numbers'></td> <td class='line_numbers'></td>
<td class='line_numbers'>#{line.new_number}</td> <td class='line_numbers' id='#{id}'><a href='#{@path}##{id}'>#{line.new_number}</a></td>
<td class='code ins'><pre>#{render_line(line)}</pre></td> <td class='code ins'><pre>#{render_line(line)}</pre></td>
</tr>" </tr>"
end end
def remline(line) def remline(line)
id = "F#{@diff_counter}L#{line.old_number}"
"<tr class='changes'> "<tr class='changes'>
<td class='line_numbers'>#{line.old_number}</td> <td class='line_numbers' id='#{id}'><a href='#{@path}##{id}'>#{line.old_number}</a></td>
<td class='line_numbers'></td> <td class='line_numbers'></td>
<td class='code del'><pre>#{render_line(line)}</pre></td> <td class='code del'><pre>#{render_line(line)}</pre></td>
</tr>" </tr>"
end end
def modline(line) def modline(line)
rid = "F#{@diff_counter}R#{line.new_number}"
lid = "F#{@diff_counter}L#{line.old_number}"
"<tr clas='chanes line'> "<tr clas='chanes line'>
<td class='line_numbers'>#{line.old_number}</td> <td class='line_numbers' id='#{lid}'><a href='#{@path}##{lid}'>#{line.old_number}</a></td>
<td class='line_numbers'>#{line.new_number}</td> <td class='line_numbers' id='#{rid}'><a href='#{@path}##{rid}'>#{line.new_number}</a></td>
<td class='code unchanged modline'><pre>#{render_line(line)}</pre></td> <td class='code unchanged modline'><pre>#{render_line(line)}</pre></td>
</tr>" </tr>"
end end
def unmodline(line) def unmodline(line)
rid = "F#{@diff_counter}R#{line.new_number}"
lid = "F#{@diff_counter}L#{line.old_number}"
"<tr class='changes unmodline'> "<tr class='changes unmodline'>
<td class='line_numbers'>#{line.old_number}</td> <td class='line_numbers' id='#{lid}'><a href='#{@path}##{lid}'>#{line.old_number}</a></td>
<td class='line_numbers'>#{line.new_number}</td> <td class='line_numbers' id='#{rid}'><a href='#{@path}##{rid}'>#{line.new_number}</a></td>
<td class='code unchanged unmodline'><pre>#{render_line(line)}</pre></td> <td class='code unchanged unmodline'><pre>#{render_line(line)}</pre></td>
</tr>" </tr>"
end end
@ -57,9 +68,11 @@ module Git
end end
def nonewlineline(line) def nonewlineline(line)
rid = "F#{@diff_counter}R#{line.new_number}"
lid = "F#{@diff_counter}L#{line.old_number}"
"<tr class='changes'> "<tr class='changes'>
<td class='line_numbers'>#{line.old_number}</td> <td class='line_numbers' id='#{lid}'><a href='#{@path}##{lid}'>#{line.old_number}</a></td>
<td class='line_numbers'>#{line.new_number}</td> <td class='line_numbers' id='#{rid}'><a href='#{@path}##{rid}'>#{line.new_number}</a></td>
<td class='code modline unmodline'><pre>#{render_line(line)}</pre></td> <td class='code modline unmodline'><pre>#{render_line(line)}</pre></td>
</tr>" </tr>"
end end