2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-03-10 11:34:32 +00:00
|
|
|
module Git
|
|
|
|
module Diff
|
2011-04-01 04:44:21 +01:00
|
|
|
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
|
|
|
|
|
2011-03-10 11:34:32 +00:00
|
|
|
def addline(line)
|
|
|
|
"<tr class='changes'>
|
|
|
|
<td class='line_numbers'></td>
|
|
|
|
<td class='line_numbers'>#{line.new_number}</td>
|
2011-04-01 04:44:21 +01:00
|
|
|
<td class='code ins'><pre>#{render_line(line)}</pre></td>
|
2011-03-10 11:34:32 +00:00
|
|
|
</tr>"
|
|
|
|
end
|
|
|
|
|
|
|
|
def remline(line)
|
|
|
|
"<tr class='changes'>
|
|
|
|
<td class='line_numbers'>#{line.old_number}</td>
|
|
|
|
<td class='line_numbers'></td>
|
2011-04-01 04:44:21 +01:00
|
|
|
<td class='code del'><pre>#{render_line(line)}</pre></td>
|
2011-03-10 11:34:32 +00:00
|
|
|
</tr>"
|
|
|
|
end
|
|
|
|
|
|
|
|
def modline(line)
|
|
|
|
"<tr clas='chanes line'>
|
|
|
|
<td class='line_numbers'>#{line.old_number}</td>
|
|
|
|
<td class='line_numbers'>#{line.new_number}</td>
|
2011-04-01 04:44:21 +01:00
|
|
|
<td class='code unchanged modline'><pre>#{render_line(line)}</pre></td>
|
2011-03-10 11:34:32 +00:00
|
|
|
</tr>"
|
|
|
|
end
|
|
|
|
|
|
|
|
def unmodline(line)
|
|
|
|
"<tr class='changes unmodline'>
|
|
|
|
<td class='line_numbers'>#{line.old_number}</td>
|
|
|
|
<td class='line_numbers'>#{line.new_number}</td>
|
2011-04-01 04:44:21 +01:00
|
|
|
<td class='code unchanged unmodline'><pre>#{render_line(line)}</pre></td>
|
2011-03-10 11:34:32 +00:00
|
|
|
</tr>"
|
|
|
|
end
|
|
|
|
|
|
|
|
def sepline(line)
|
|
|
|
"<tr class='changes hunk-sep'>
|
|
|
|
<td class='line_numbers line_num_cut'>…</td>
|
|
|
|
<td class='line_numbers line_num_cut'>…</td>
|
|
|
|
<td class='code cut-line'></td>
|
|
|
|
</tr>"
|
|
|
|
end
|
|
|
|
|
|
|
|
def nonewlineline(line)
|
|
|
|
"<tr class='changes'>
|
|
|
|
<td class='line_numbers'>#{line.old_number}</td>
|
|
|
|
<td class='line_numbers'>#{line.new_number}</td>
|
2011-04-01 04:44:21 +01:00
|
|
|
<td class='code modline unmodline'><pre>#{render_line(line)}</pre></td>
|
2011-03-10 11:34:32 +00:00
|
|
|
</tr>"
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
def escape(str)
|
|
|
|
str.to_s.gsub('&', '&').gsub('<', '<').gsub('>', '>').gsub('"', '"')
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_line(line)
|
|
|
|
res = '<span class="diff-content">'
|
|
|
|
if line.inline_changes?
|
|
|
|
prefix, changed, postfix = line.segments.map{|segment| escape(segment) }
|
|
|
|
res += "#{prefix}<span class='idiff'>#{changed}</span>#{postfix}"
|
|
|
|
else
|
|
|
|
res += escape(line)
|
|
|
|
end
|
|
|
|
res += '</span>'
|
|
|
|
|
|
|
|
res
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|