Method: ApplicationHelper#render_diff_table

Defined in:
app/helpers/application_helper.rb

#render_diff_table(chunks) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'app/helpers/application_helper.rb', line 86

def render_diff_table(chunks)
  b.table :class => 'diff', :cellspacing => '0' do |b|
    b.colgroup do
      b.col :class => 'line_number'
      b.col :class => 'left'
      b.col :class => 'right'
      b.col :class => 'line_number'
    end
    chunks.each do |chunk|
      if chunk.separator?
        b.tbody :class => 'separator' do
          b.tr do
            b.th
            b.td('%s more lines' / chunk.num_lines.to_s, :colspan => '2')
            b.th
          end
        end
      else  
        b.tbody :class => chunk.action.to_s do
          chunk.lines.each do |line|
            b.tr do
              b.th {b << (line.original_position || '&nbsp;').to_s}
              b.td {b.pre {b << (h(line.original_text) || '&nbsp;')}}
              b.td {b.pre {b << (h(line.modified_text) || '&nbsp;')}}
              b.th {b << (line.modified_position || '&nbsp;').to_s}
            end
          end
        end
      end
    end
  end
end