Refactored Diff::Display classes
[gitorious:yousource.git] / lib / gitorious / diff / sidebyside_table_callback.rb
1 module Gitorious
2   module Diff
3     class SidebysideTableCallback < BaseCallback
4       
5       # Before blocks
6       def before_addblock(block)
7         %q{<tbody class="add"><tr>}
8       end
9       
10       def before_remblock(block) 
11         %Q{<tbody class="rem"><tr>}
12       end
13       
14       def before_modblock(block)
15         %Q{<tbody class="mod"><tr>}
16       end
17       
18       def before_unmodblock(block)
19         %Q{<tbody class="unmod"><tr>}
20       end
21       
22       def before_sepblock(block)
23         %Q{<tbody class="sep"><tr>}
24       end
25       
26       # After blocks
27       def after_addblock(block)
28         "</tbody>"
29       end
30       
31       def after_remblock(block)
32         "</tbody>"
33       end
34       
35       def after_modblock(block)
36         "</tbody>"
37       end
38       
39       def after_unmodblock(block)
40         "</tbody>"
41       end
42       
43       def after_sepblock(block)
44         "</tbody>"
45       end
46       
47       # Before lines
48       def addline(line)
49         # adds go on the right
50         %Q{<th class="line-numbers">#{line.number}</th>} + 
51         %Q{<td class="code ins"></td>} + 
52         %Q{<th class="line-numbers">#{line.number}</th>} + 
53         %Q{<td class="code ins"><ins>#{escape(line)}</ins></td></tr>}
54       end
55       
56       def remline(line)
57         # rems go on the left (hide the right side)
58         %Q{<th class="line-numbers">#{line.number}</th>} + 
59         %Q{<td class="code del"><del>#{CGI.escapeHTML(line)}</del></td>} + 
60         %Q{<th class="line-numbers">#{line.number}</th>} + 
61         %Q{<td class="code del hidden"><del>#{escape(line)}</del></td></tr>}
62       end
63       
64       def modline(line)
65         # TODO: figure how we best display these
66         # %Q{<th class="line-numbers">#{line.number}</th>} + 
67         # %Q{<td class="code changed mod">#{CGI.escapeHTML(line)}</td>} + 
68         # %Q{<th class="line-numbers">#{line.number}</th>} + 
69         # %Q{<td class="code changed mod">#{escape(line)}</td></tr>}
70       end
71       
72       def unmodline(line)
73         # unmods goes on both sides
74         %Q{<th class="line-numbers">#{line.number}</th>} + 
75         %Q{<td class="code unchanged unmod">#{escape(line)}</td>} + 
76         %Q{<th class="line-numbers">#{line.number}</th>} + 
77         %Q{<td class="code unchanged unmod">#{escape(line)}</td></tr>}
78       end
79       
80       def sepline(line)
81         %Q{<th class="line-numbers line-num-cut">&hellip;</th>} + 
82         %Q{<td class="code cut-line"></td>} + 
83         %Q{<th class="line-numbers line-num-cut">&hellip;</th>} + 
84         %Q{<td class="code cut-line"></td></tr>}
85       end
86     end
87   end
88 end