Refactored Diff::Display classes
[gitorious:yousource.git] / vendor / diff-display / lib / diff / renderer / base.rb
1 module Diff
2   module Renderer
3     class Base
4       def render(data)
5         result = []
6         data.each do |block|
7           result << send("before_" + classify(block), block)
8           result << block.map { |line| send(classify(line), line) }
9           result << send("after_" + classify(block), block)
10         end
11         result.compact.join(new_line)
12       end
13       
14       def before_headerblock(block)
15       end
16       
17       def before_unmodblock(block)
18       end
19       
20       def before_modblock(block)
21       end
22       
23       def before_remblock(block)
24       end
25       
26       def before_addblock(block)
27       end
28       
29       def before_sepblock(block)
30       end
31       
32       def headerline(line)
33         line
34       end
35       
36       def unmodline(line)
37         line
38       end
39       
40       def remline(line)
41         line
42       end
43       
44       def addline(line)
45         line
46       end
47       
48       def sepline(line)
49         
50       end
51       
52       def after_headerblock(block)
53       end
54       
55       def after_unmodblock(block)
56       end
57       
58       def after_modblock(block)
59       end
60       
61       def after_remblock(block)
62       end
63       
64       def after_addblock(block)
65       end
66       
67       def after_sepblock(block)
68       end
69       
70       def new_line
71         ""
72       end
73       
74       protected
75         def classify(object)
76           object.class.name[/\w+$/].downcase 
77         end
78     end
79   end
80 end