diffed 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  require 'diffed/version'
2
+ require 'formatters/diff_html'
2
3
  require 'parsers/unified'
3
4
  require 'escape_utils'
4
5
 
@@ -12,7 +13,7 @@ module Diffed
12
13
  end
13
14
 
14
15
  class Diff
15
- include Html
16
+ include DiffHtml
16
17
  attr_accessor :sections
17
18
 
18
19
  def initialize(lines)
@@ -1,3 +1,3 @@
1
1
  module Diffed
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -0,0 +1,64 @@
1
+ module Diffed
2
+ module DiffHtml
3
+ def as_html_table(use_inline_styles=true, row_nums_to_highlight = [])
4
+ html = make_table_tag(use_inline_styles)
5
+
6
+ sections.each do |section|
7
+ html << section.as_html_rows(use_inline_styles, row_nums_to_highlight)
8
+ end
9
+
10
+ html << "</table>"
11
+ end
12
+
13
+ private
14
+ def format_styled_row(bg_color, text_color, row, opts = {})
15
+ row_styles = []
16
+ row_styles << "background-color: #{bg_color}" unless bg_color.nil?
17
+ row_styles << "font-weight: bold" if opts[:highlight]
18
+
19
+ row_style_attr = row_styles.empty? ? "" : %Q{ style="#{row_styles.join('; ')}" }
20
+ text_color = text_color
21
+
22
+ border = '1px solid #CCC'
23
+ html = <<EOS
24
+ <tr#{row_style_attr}>
25
+ <td style="border-left: #{border}">#{row.left}</td>
26
+ <td style="border-left: #{border}">#{row.right}</td>
27
+ <td style="border-left: #{border}; border-right: #{border}; color: #{text_color}"><pre>#{row.text}</pre></td>
28
+ </tr>
29
+ EOS
30
+ end
31
+
32
+ def format_classed_row(css_class, row, opts = {})
33
+ class_attr = %Q{ class="#{css_class}#{opts[:highlight] ? ' highlight' : ''}"}
34
+ %Q{<tr#{class_attr}><td>#{row.left}</td><td>#{row.right}</td><td><pre>#{row.text}</pre></td></tr>\n}
35
+ end
36
+
37
+ def make_table_tag(inline_styles)
38
+ if inline_styles
39
+ table_attributes = %Q{cellpadding="5" style="border-collapse: collapse; border: 1px solid \#CCC; font-family: Consolas, courier, monospace; font-size: 11px; color: #888"}
40
+ else
41
+ table_attributes = %Q{class="coloured-diff"}
42
+ end
43
+
44
+ %Q{<table #{table_attributes}>\n}
45
+ end
46
+
47
+ class OutputRow
48
+ attr_reader :left, :right
49
+
50
+ def initialize(params = {})
51
+ if params[:code_line].nil?
52
+ @left, @right, @text = params[:left], params[:right], params[:text]
53
+ else
54
+ line = params[:code_line]
55
+ @left, @right, @text = line.left_line_num, line.right_line_num, line.text
56
+ end
57
+ end
58
+
59
+ def text
60
+ EscapeUtils.escape_html(@text, false)
61
+ end
62
+ end
63
+ end
64
+ end
@@ -1,4 +1,4 @@
1
- require 'formatters/html'
1
+ require 'formatters/diff_html'
2
2
 
3
3
  module Diffed
4
4
  class DiffedFile
@@ -1,8 +1,8 @@
1
- require 'formatters/html'
1
+ require 'formatters/diff_html'
2
2
 
3
3
  module Diffed
4
4
  class Line
5
- include Html
5
+ include DiffHtml
6
6
  attr_reader :type, :text, :left_line_num, :right_line_num, :no_newline
7
7
 
8
8
  def initialize(type, text, left_line_num, right_line_num)
@@ -22,18 +22,18 @@ module Diffed
22
22
  @no_newline = bool
23
23
  end
24
24
 
25
- def as_html_row(use_inline_styles)
26
- format_code_line(use_inline_styles)
25
+ def as_html_row(use_inline_styles, highlight = false)
26
+ format_code_line(use_inline_styles, highlight)
27
27
  end
28
28
 
29
29
  private
30
- def format_code_line(use_inline_styles)
30
+ def format_code_line(use_inline_styles, highlight)
31
31
  row = OutputRow.new(:code_line => self)
32
32
 
33
33
  if use_inline_styles
34
- format_styled_row code_line_style, '#000', row
34
+ format_styled_row code_line_style, '#000', row, :highlight => highlight
35
35
  else
36
- format_classed_row type.to_s, row
36
+ format_classed_row type.to_s, row, :highlight => highlight
37
37
  end
38
38
  end
39
39
 
@@ -1,17 +1,20 @@
1
- require 'formatters/html'
1
+ require 'formatters/diff_html'
2
2
 
3
3
  module Diffed
4
4
  class Section
5
- include Html
5
+ include DiffHtml
6
6
  attr_reader :header, :lines
7
7
 
8
8
  def initialize(header, lines)
9
9
  @header, @lines = header, lines
10
10
  end
11
11
 
12
- def as_html_rows(use_inline_styles)
12
+ def as_html_rows(use_inline_styles, row_nums_to_highlight = [])
13
13
  html = format_section_header_row(use_inline_styles)
14
- lines.each { |line| html << line.as_html_row(use_inline_styles) }
14
+ lines.each_with_index do |line, i|
15
+ html << line.as_html_row(use_inline_styles, row_nums_to_highlight.include?(i + 1))
16
+ end
17
+
15
18
  html
16
19
  end
17
20
 
@@ -43,8 +43,8 @@ module Diffed
43
43
 
44
44
  def parse_code_line(line)
45
45
  line_parser = LineParser.new(line)
46
- @left_counter, @right_counter = line_parser.increment(@left_counter, @right_counter)
47
- @curr_lines << line_parser.line(@left_counter, @right_counter)
46
+ @curr_lines << line_parser.line(@curr_header, @left_counter, @right_counter)
47
+ @left_counter, @right_counter = line_parser.increment(@left_counter, @right_counter)
48
48
 
49
49
  if @curr_header.section_complete? @left_counter, @right_counter
50
50
  @sections << Section.new(@curr_header.line, @curr_lines)
@@ -82,17 +82,19 @@ module Diffed
82
82
  end
83
83
  end
84
84
 
85
- def line(left_counter, right_counter)
86
- Line.new(@type, @line_text, left_line_num(left_counter), right_line_num(right_counter))
85
+ def line(header, left_counter, right_counter)
86
+ left = left_line_num header, left_counter
87
+ right = right_line_num header, right_counter
88
+ Line.new(@type, @line_text, left, right)
87
89
  end
88
90
 
89
91
  private
90
- def left_line_num(left_counter)
91
- @type == :right ? "." : left_counter
92
+ def left_line_num(header, left_counter)
93
+ @type == :right ? "." : (left_counter + header.line_nums[:left][:from])
92
94
  end
93
95
 
94
- def right_line_num(right_counter)
95
- @type == :left ? "." : right_counter
96
+ def right_line_num(header, right_counter)
97
+ @type == :left ? "." : (right_counter + header.line_nums[:right][:from])
96
98
  end
97
99
  end
98
100
 
@@ -4,24 +4,44 @@ describe "Diffed::Diff.as_html_table" do
4
4
  it "produces an html table representation of a diff, with CSS styles inline" do
5
5
  diff = Diffed.from_text(File.read("testdata/diff1.diff"))
6
6
  output = diff.as_html_table
7
- output.strip == File.read("testdata/diff1.styled.html").strip
7
+ # File.open("wtf1.html", "w") {|f| f.write(output)}
8
+ output.strip.should eq File.read("testdata/diff1.styled.html").strip
8
9
  end
9
10
 
10
11
  it "produces an html table representation of the diff portions of the output of 'git show', with CSS styles inline" do
11
12
  diff = Diffed.from_text(File.read("testdata/git-show.output"))
12
13
  output = diff.as_html_table
13
- output.strip == File.read("testdata/git-show.styled.html").strip
14
+ # File.open("wtf2.html", "w") {|f| f.write(output)}
15
+ output.strip.should eq File.read("testdata/git-show.styled.html").strip
14
16
  end
15
17
 
16
18
  it "produces an html table representation of the diff portions of the output of 'p4 describe -du', with CSS styles inline" do
17
19
  diff = Diffed.from_text(File.read("testdata/p4-describe.output"))
18
20
  output = diff.as_html_table
19
- output.strip == File.read("testdata/p4-describe.styled.html").strip
21
+ # File.open("wtf3.html", "w") {|f| f.write(output)}
22
+ output.strip.should eq File.read("testdata/p4-describe.styled.html").strip
20
23
  end
21
24
 
22
25
  it "produces an html table representation of a diff, with CSS classes" do
23
26
  diff = Diffed.from_text(File.read("testdata/diff1.diff"))
24
27
  output = diff.as_html_table(false)
25
- output.strip == File.read("testdata/diff1.classed.html").strip
26
- end
28
+ # File.open("wtf4.html", "w") {|f| f.write(output)}
29
+ output.strip.should eq File.read("testdata/diff1.classed.html").strip
30
+ end
31
+
32
+ it "renders an html table with two highlighted rows, using inline styles" do
33
+ diff = Diffed.from_text(File.read("testdata/diff2.diff"))
34
+ section1 = diff.sections[0]
35
+ output = section1.as_html_table(true, [9,11])
36
+ # File.open("wtf5.html", "w") {|f| f.write(output)}
37
+ output.strip.should eq File.read("testdata/diff2.styled.html").strip
38
+ end
39
+
40
+ it "renders an html table with two highlighted rows, using CSS classes" do
41
+ diff = Diffed.from_text(File.read("testdata/diff2.diff"))
42
+ section1 = diff.sections[0]
43
+ output = section1.as_html_table(false, [9, 11])
44
+ # File.open("wtf6.html", "w") {|f| f.write(output)}
45
+ output.strip.should eq File.read("testdata/diff2.classed.html").strip
46
+ end
27
47
  end
@@ -41,12 +41,18 @@
41
41
  <tr class="both"><td>37</td><td>37</td><td><pre> def find_lines!</pre></td></tr>
42
42
  <tr class="left"><td>38</td><td>.</td><td><pre>- returning(@lines = []) do</pre></td></tr>
43
43
  <tr class="left"><td>39</td><td>.</td><td><pre>- input.split(/\r?\n/).each_with_index do |line_str, idx|</pre></td></tr>
44
- <tr class="left"><td>40</td><td>.</td><td><pre>- line = PrettyDiff::Line.new(diff, line_str, :number => idx)</pre></td></tr>
44
+ <tr class="left"><td>40</td><td>.</td><td><pre>- line = PrettyDiff::Line.new(diff, line_str, :number =&gt; idx)</pre></td></tr>
45
45
  <tr class="right"><td>.</td><td>38</td><td><pre>+ @lines = []</pre></td></tr>
46
46
  <tr class="right"><td>.</td><td>39</td><td><pre>+ @lines.tap do</pre></td></tr>
47
47
  <tr class="right"><td>.</td><td>40</td><td><pre>+ input.split(/\r?\n/).each do |line_str|</pre></td></tr>
48
48
  <tr class="right"><td>.</td><td>41</td><td><pre>+ line = PrettyDiff::Line.new(diff, line_str)</pre></td></tr>
49
49
  <tr class="both"><td>41</td><td>42</td><td><pre> next if line.ignore?</pre></td></tr>
50
- <tr class="both"><td>42</td><td>43</td><td><pre> @lines << line</pre></td></tr>
50
+ <tr class="both"><td>42</td><td>43</td><td><pre> @lines &lt;&lt; line</pre></td></tr>
51
51
  <tr class="both"><td>43</td><td>44</td><td><pre> line_numbers.act_on_line(line)</pre></td></tr>
52
+ <tr class="section"><td>...</td><td>...</td><td><pre>@@ -45,4 +46,4 @@ private</pre></td></tr>
53
+ <tr class="both"><td>45</td><td>46</td><td><pre> end</pre></td></tr>
54
+ <tr class="both"><td>46</td><td>47</td><td><pre> end</pre></td></tr>
55
+ <tr class="both"><td>47</td><td>48</td><td><pre> </pre></td></tr>
56
+ <tr class="left"><td>48</td><td>.</td><td><pre>-end</pre></td></tr>
57
+ <tr class="right"><td>.</td><td>49</td><td><pre>+end</pre></td></tr>
52
58
  </table>
@@ -1,52 +1,282 @@
1
- <table cellpadding="5" style="border-collapse: collapse; border: 1px solid #CCC; font-family: Consolas, courier, monospace; font-size: 13px; color: #888">
2
- <tr style="background-color: #F0F0FF"><td style="border-left: 1px solid #CCC">...</td><td style="border-left: 1px solid #CCC">...</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #888"><pre>@@ -1,22 +1,22 @@</pre></td></tr>
3
- <tr><td style="border-left: 1px solid #CCC">1</td><td style="border-left: 1px solid #CCC">1</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> #</pre></td></tr>
4
- <tr><td style="border-left: 1px solid #CCC">2</td><td style="border-left: 1px solid #CCC">2</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> # Represent a single piece of a diff.</pre></td></tr>
5
- <tr style="background-color: #FDD"><td style="border-left: 1px solid #CCC">3</td><td style="border-left: 1px solid #CCC">.</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>-# </pre></td></tr>
6
- <tr style="background-color: #DFD"><td style="border-left: 1px solid #CCC">.</td><td style="border-left: 1px solid #CCC">3</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>+#</pre></td></tr>
7
- <tr><td style="border-left: 1px solid #CCC">4</td><td style="border-left: 1px solid #CCC">4</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> class PrettyDiff::Chunk #:nodoc:</pre></td></tr>
8
- <tr><td style="border-left: 1px solid #CCC">5</td><td style="border-left: 1px solid #CCC">5</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> attr_reader :diff, :meta_info, :input, :lines</pre></td></tr>
9
- <tr style="background-color: #FDD"><td style="border-left: 1px solid #CCC">6</td><td style="border-left: 1px solid #CCC">.</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>- </pre></td></tr>
10
- <tr style="background-color: #DFD"><td style="border-left: 1px solid #CCC">.</td><td style="border-left: 1px solid #CCC">6</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>+</pre></td></tr>
11
- <tr><td style="border-left: 1px solid #CCC">7</td><td style="border-left: 1px solid #CCC">7</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> def initialize(diff, meta_info, input)</pre></td></tr>
12
- <tr><td style="border-left: 1px solid #CCC">8</td><td style="border-left: 1px solid #CCC">8</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> @diff = diff</pre></td></tr>
13
- <tr><td style="border-left: 1px solid #CCC">9</td><td style="border-left: 1px solid #CCC">9</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> @meta_info = meta_info</pre></td></tr>
14
- <tr><td style="border-left: 1px solid #CCC">10</td><td style="border-left: 1px solid #CCC">10</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> @input = input</pre></td></tr>
15
- <tr><td style="border-left: 1px solid #CCC">11</td><td style="border-left: 1px solid #CCC">11</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> end</pre></td></tr>
16
- <tr style="background-color: #FDD"><td style="border-left: 1px solid #CCC">12</td><td style="border-left: 1px solid #CCC">.</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>- </pre></td></tr>
17
- <tr style="background-color: #DFD"><td style="border-left: 1px solid #CCC">.</td><td style="border-left: 1px solid #CCC">12</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>+</pre></td></tr>
18
- <tr><td style="border-left: 1px solid #CCC">13</td><td style="border-left: 1px solid #CCC">13</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> # Generate HTML presentation for a Chunk. Return a string.</pre></td></tr>
19
- <tr><td style="border-left: 1px solid #CCC">14</td><td style="border-left: 1px solid #CCC">14</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> def to_html</pre></td></tr>
20
- <tr><td style="border-left: 1px solid #CCC">15</td><td style="border-left: 1px solid #CCC">15</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> # We have to find lines before we can call line numbers methods.</pre></td></tr>
21
- <tr><td style="border-left: 1px solid #CCC">16</td><td style="border-left: 1px solid #CCC">16</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> find_lines!</pre></td></tr>
22
- <tr><td style="border-left: 1px solid #CCC">17</td><td style="border-left: 1px solid #CCC">17</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> generator.generate</pre></td></tr>
23
- <tr><td style="border-left: 1px solid #CCC">18</td><td style="border-left: 1px solid #CCC">18</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> end</pre></td></tr>
24
- <tr style="background-color: #FDD"><td style="border-left: 1px solid #CCC">19</td><td style="border-left: 1px solid #CCC">.</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>- </pre></td></tr>
25
- <tr style="background-color: #DFD"><td style="border-left: 1px solid #CCC">.</td><td style="border-left: 1px solid #CCC">19</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>+</pre></td></tr>
26
- <tr><td style="border-left: 1px solid #CCC">20</td><td style="border-left: 1px solid #CCC">20</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> # Return LineNumbers object that represents two columns of numbers</pre></td></tr>
27
- <tr><td style="border-left: 1px solid #CCC">21</td><td style="border-left: 1px solid #CCC">21</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> # that will be displayed on the left of the HTML presentation.</pre></td></tr>
28
- <tr><td style="border-left: 1px solid #CCC">22</td><td style="border-left: 1px solid #CCC">22</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> #</pre></td></tr>
29
- <tr style="background-color: #F0F0FF"><td style="border-left: 1px solid #CCC">...</td><td style="border-left: 1px solid #CCC">...</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #888"><pre>@@ -25,7 +25,7 @@ class PrettyDiff::Chunk #:nodoc:</pre></td></tr>
30
- <tr><td style="border-left: 1px solid #CCC">25</td><td style="border-left: 1px solid #CCC">25</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> def line_numbers</pre></td></tr>
31
- <tr><td style="border-left: 1px solid #CCC">26</td><td style="border-left: 1px solid #CCC">26</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> @_line_numbers ||= PrettyDiff::LineNumbers.new(diff, meta_info)</pre></td></tr>
32
- <tr><td style="border-left: 1px solid #CCC">27</td><td style="border-left: 1px solid #CCC">27</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> end</pre></td></tr>
33
- <tr style="background-color: #FDD"><td style="border-left: 1px solid #CCC">28</td><td style="border-left: 1px solid #CCC">.</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>- </pre></td></tr>
34
- <tr style="background-color: #DFD"><td style="border-left: 1px solid #CCC">.</td><td style="border-left: 1px solid #CCC">28</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>+</pre></td></tr>
35
- <tr><td style="border-left: 1px solid #CCC">29</td><td style="border-left: 1px solid #CCC">29</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> private</pre></td></tr>
36
- <tr><td style="border-left: 1px solid #CCC">30</td><td style="border-left: 1px solid #CCC">30</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> </pre></td></tr>
37
- <tr><td style="border-left: 1px solid #CCC">31</td><td style="border-left: 1px solid #CCC">31</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> def generator</pre></td></tr>
38
- <tr style="background-color: #F0F0FF"><td style="border-left: 1px solid #CCC">...</td><td style="border-left: 1px solid #CCC">...</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #888"><pre>@@ -35,9 +35,10 @@ private</pre></td></tr>
39
- <tr><td style="border-left: 1px solid #CCC">35</td><td style="border-left: 1px solid #CCC">35</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> # Parse the input searching for lines. Initialize Line object for every line.</pre></td></tr>
40
- <tr><td style="border-left: 1px solid #CCC">36</td><td style="border-left: 1px solid #CCC">36</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> # Return an array of Line objects.</pre></td></tr>
41
- <tr><td style="border-left: 1px solid #CCC">37</td><td style="border-left: 1px solid #CCC">37</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> def find_lines!</pre></td></tr>
42
- <tr style="background-color: #FDD"><td style="border-left: 1px solid #CCC">38</td><td style="border-left: 1px solid #CCC">.</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>- returning(@lines = []) do</pre></td></tr>
43
- <tr style="background-color: #FDD"><td style="border-left: 1px solid #CCC">39</td><td style="border-left: 1px solid #CCC">.</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>- input.split(/\r?\n/).each_with_index do |line_str, idx|</pre></td></tr>
44
- <tr style="background-color: #FDD"><td style="border-left: 1px solid #CCC">40</td><td style="border-left: 1px solid #CCC">.</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>- line = PrettyDiff::Line.new(diff, line_str, :number => idx)</pre></td></tr>
45
- <tr style="background-color: #DFD"><td style="border-left: 1px solid #CCC">.</td><td style="border-left: 1px solid #CCC">38</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>+ @lines = []</pre></td></tr>
46
- <tr style="background-color: #DFD"><td style="border-left: 1px solid #CCC">.</td><td style="border-left: 1px solid #CCC">39</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>+ @lines.tap do</pre></td></tr>
47
- <tr style="background-color: #DFD"><td style="border-left: 1px solid #CCC">.</td><td style="border-left: 1px solid #CCC">40</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>+ input.split(/\r?\n/).each do |line_str|</pre></td></tr>
48
- <tr style="background-color: #DFD"><td style="border-left: 1px solid #CCC">.</td><td style="border-left: 1px solid #CCC">41</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>+ line = PrettyDiff::Line.new(diff, line_str)</pre></td></tr>
49
- <tr><td style="border-left: 1px solid #CCC">41</td><td style="border-left: 1px solid #CCC">42</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> next if line.ignore?</pre></td></tr>
50
- <tr><td style="border-left: 1px solid #CCC">42</td><td style="border-left: 1px solid #CCC">43</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> @lines << line</pre></td></tr>
51
- <tr><td style="border-left: 1px solid #CCC">43</td><td style="border-left: 1px solid #CCC">44</td><td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> line_numbers.act_on_line(line)</pre></td></tr>
1
+ <table cellpadding="5" style="border-collapse: collapse; border: 1px solid #CCC; font-family: Consolas, courier, monospace; font-size: 11px; color: #888">
2
+ <tr style="background-color: #F0F0FF" >
3
+ <td style="border-left: 1px solid #CCC">...</td>
4
+ <td style="border-left: 1px solid #CCC">...</td>
5
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #888"><pre>@@ -1,22 +1,22 @@</pre></td>
6
+ </tr>
7
+ <tr>
8
+ <td style="border-left: 1px solid #CCC">1</td>
9
+ <td style="border-left: 1px solid #CCC">1</td>
10
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> #</pre></td>
11
+ </tr>
12
+ <tr>
13
+ <td style="border-left: 1px solid #CCC">2</td>
14
+ <td style="border-left: 1px solid #CCC">2</td>
15
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> # Represent a single piece of a diff.</pre></td>
16
+ </tr>
17
+ <tr style="background-color: #FDD" >
18
+ <td style="border-left: 1px solid #CCC">3</td>
19
+ <td style="border-left: 1px solid #CCC">.</td>
20
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>-# </pre></td>
21
+ </tr>
22
+ <tr style="background-color: #DFD" >
23
+ <td style="border-left: 1px solid #CCC">.</td>
24
+ <td style="border-left: 1px solid #CCC">3</td>
25
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>+#</pre></td>
26
+ </tr>
27
+ <tr>
28
+ <td style="border-left: 1px solid #CCC">4</td>
29
+ <td style="border-left: 1px solid #CCC">4</td>
30
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> class PrettyDiff::Chunk #:nodoc:</pre></td>
31
+ </tr>
32
+ <tr>
33
+ <td style="border-left: 1px solid #CCC">5</td>
34
+ <td style="border-left: 1px solid #CCC">5</td>
35
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> attr_reader :diff, :meta_info, :input, :lines</pre></td>
36
+ </tr>
37
+ <tr style="background-color: #FDD" >
38
+ <td style="border-left: 1px solid #CCC">6</td>
39
+ <td style="border-left: 1px solid #CCC">.</td>
40
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>- </pre></td>
41
+ </tr>
42
+ <tr style="background-color: #DFD" >
43
+ <td style="border-left: 1px solid #CCC">.</td>
44
+ <td style="border-left: 1px solid #CCC">6</td>
45
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>+</pre></td>
46
+ </tr>
47
+ <tr>
48
+ <td style="border-left: 1px solid #CCC">7</td>
49
+ <td style="border-left: 1px solid #CCC">7</td>
50
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> def initialize(diff, meta_info, input)</pre></td>
51
+ </tr>
52
+ <tr>
53
+ <td style="border-left: 1px solid #CCC">8</td>
54
+ <td style="border-left: 1px solid #CCC">8</td>
55
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> @diff = diff</pre></td>
56
+ </tr>
57
+ <tr>
58
+ <td style="border-left: 1px solid #CCC">9</td>
59
+ <td style="border-left: 1px solid #CCC">9</td>
60
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> @meta_info = meta_info</pre></td>
61
+ </tr>
62
+ <tr>
63
+ <td style="border-left: 1px solid #CCC">10</td>
64
+ <td style="border-left: 1px solid #CCC">10</td>
65
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> @input = input</pre></td>
66
+ </tr>
67
+ <tr>
68
+ <td style="border-left: 1px solid #CCC">11</td>
69
+ <td style="border-left: 1px solid #CCC">11</td>
70
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> end</pre></td>
71
+ </tr>
72
+ <tr style="background-color: #FDD" >
73
+ <td style="border-left: 1px solid #CCC">12</td>
74
+ <td style="border-left: 1px solid #CCC">.</td>
75
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>- </pre></td>
76
+ </tr>
77
+ <tr style="background-color: #DFD" >
78
+ <td style="border-left: 1px solid #CCC">.</td>
79
+ <td style="border-left: 1px solid #CCC">12</td>
80
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>+</pre></td>
81
+ </tr>
82
+ <tr>
83
+ <td style="border-left: 1px solid #CCC">13</td>
84
+ <td style="border-left: 1px solid #CCC">13</td>
85
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> # Generate HTML presentation for a Chunk. Return a string.</pre></td>
86
+ </tr>
87
+ <tr>
88
+ <td style="border-left: 1px solid #CCC">14</td>
89
+ <td style="border-left: 1px solid #CCC">14</td>
90
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> def to_html</pre></td>
91
+ </tr>
92
+ <tr>
93
+ <td style="border-left: 1px solid #CCC">15</td>
94
+ <td style="border-left: 1px solid #CCC">15</td>
95
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> # We have to find lines before we can call line numbers methods.</pre></td>
96
+ </tr>
97
+ <tr>
98
+ <td style="border-left: 1px solid #CCC">16</td>
99
+ <td style="border-left: 1px solid #CCC">16</td>
100
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> find_lines!</pre></td>
101
+ </tr>
102
+ <tr>
103
+ <td style="border-left: 1px solid #CCC">17</td>
104
+ <td style="border-left: 1px solid #CCC">17</td>
105
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> generator.generate</pre></td>
106
+ </tr>
107
+ <tr>
108
+ <td style="border-left: 1px solid #CCC">18</td>
109
+ <td style="border-left: 1px solid #CCC">18</td>
110
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> end</pre></td>
111
+ </tr>
112
+ <tr style="background-color: #FDD" >
113
+ <td style="border-left: 1px solid #CCC">19</td>
114
+ <td style="border-left: 1px solid #CCC">.</td>
115
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>- </pre></td>
116
+ </tr>
117
+ <tr style="background-color: #DFD" >
118
+ <td style="border-left: 1px solid #CCC">.</td>
119
+ <td style="border-left: 1px solid #CCC">19</td>
120
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>+</pre></td>
121
+ </tr>
122
+ <tr>
123
+ <td style="border-left: 1px solid #CCC">20</td>
124
+ <td style="border-left: 1px solid #CCC">20</td>
125
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> # Return LineNumbers object that represents two columns of numbers</pre></td>
126
+ </tr>
127
+ <tr>
128
+ <td style="border-left: 1px solid #CCC">21</td>
129
+ <td style="border-left: 1px solid #CCC">21</td>
130
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> # that will be displayed on the left of the HTML presentation.</pre></td>
131
+ </tr>
132
+ <tr>
133
+ <td style="border-left: 1px solid #CCC">22</td>
134
+ <td style="border-left: 1px solid #CCC">22</td>
135
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> #</pre></td>
136
+ </tr>
137
+ <tr style="background-color: #F0F0FF" >
138
+ <td style="border-left: 1px solid #CCC">...</td>
139
+ <td style="border-left: 1px solid #CCC">...</td>
140
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #888"><pre>@@ -25,7 +25,7 @@ class PrettyDiff::Chunk #:nodoc:</pre></td>
141
+ </tr>
142
+ <tr>
143
+ <td style="border-left: 1px solid #CCC">25</td>
144
+ <td style="border-left: 1px solid #CCC">25</td>
145
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> def line_numbers</pre></td>
146
+ </tr>
147
+ <tr>
148
+ <td style="border-left: 1px solid #CCC">26</td>
149
+ <td style="border-left: 1px solid #CCC">26</td>
150
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> @_line_numbers ||= PrettyDiff::LineNumbers.new(diff, meta_info)</pre></td>
151
+ </tr>
152
+ <tr>
153
+ <td style="border-left: 1px solid #CCC">27</td>
154
+ <td style="border-left: 1px solid #CCC">27</td>
155
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> end</pre></td>
156
+ </tr>
157
+ <tr style="background-color: #FDD" >
158
+ <td style="border-left: 1px solid #CCC">28</td>
159
+ <td style="border-left: 1px solid #CCC">.</td>
160
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>- </pre></td>
161
+ </tr>
162
+ <tr style="background-color: #DFD" >
163
+ <td style="border-left: 1px solid #CCC">.</td>
164
+ <td style="border-left: 1px solid #CCC">28</td>
165
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>+</pre></td>
166
+ </tr>
167
+ <tr>
168
+ <td style="border-left: 1px solid #CCC">29</td>
169
+ <td style="border-left: 1px solid #CCC">29</td>
170
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> private</pre></td>
171
+ </tr>
172
+ <tr>
173
+ <td style="border-left: 1px solid #CCC">30</td>
174
+ <td style="border-left: 1px solid #CCC">30</td>
175
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> </pre></td>
176
+ </tr>
177
+ <tr>
178
+ <td style="border-left: 1px solid #CCC">31</td>
179
+ <td style="border-left: 1px solid #CCC">31</td>
180
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> def generator</pre></td>
181
+ </tr>
182
+ <tr style="background-color: #F0F0FF" >
183
+ <td style="border-left: 1px solid #CCC">...</td>
184
+ <td style="border-left: 1px solid #CCC">...</td>
185
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #888"><pre>@@ -35,9 +35,10 @@ private</pre></td>
186
+ </tr>
187
+ <tr>
188
+ <td style="border-left: 1px solid #CCC">35</td>
189
+ <td style="border-left: 1px solid #CCC">35</td>
190
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> # Parse the input searching for lines. Initialize Line object for every line.</pre></td>
191
+ </tr>
192
+ <tr>
193
+ <td style="border-left: 1px solid #CCC">36</td>
194
+ <td style="border-left: 1px solid #CCC">36</td>
195
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> # Return an array of Line objects.</pre></td>
196
+ </tr>
197
+ <tr>
198
+ <td style="border-left: 1px solid #CCC">37</td>
199
+ <td style="border-left: 1px solid #CCC">37</td>
200
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> def find_lines!</pre></td>
201
+ </tr>
202
+ <tr style="background-color: #FDD" >
203
+ <td style="border-left: 1px solid #CCC">38</td>
204
+ <td style="border-left: 1px solid #CCC">.</td>
205
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>- returning(@lines = []) do</pre></td>
206
+ </tr>
207
+ <tr style="background-color: #FDD" >
208
+ <td style="border-left: 1px solid #CCC">39</td>
209
+ <td style="border-left: 1px solid #CCC">.</td>
210
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>- input.split(/\r?\n/).each_with_index do |line_str, idx|</pre></td>
211
+ </tr>
212
+ <tr style="background-color: #FDD" >
213
+ <td style="border-left: 1px solid #CCC">40</td>
214
+ <td style="border-left: 1px solid #CCC">.</td>
215
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>- line = PrettyDiff::Line.new(diff, line_str, :number =&gt; idx)</pre></td>
216
+ </tr>
217
+ <tr style="background-color: #DFD" >
218
+ <td style="border-left: 1px solid #CCC">.</td>
219
+ <td style="border-left: 1px solid #CCC">38</td>
220
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>+ @lines = []</pre></td>
221
+ </tr>
222
+ <tr style="background-color: #DFD" >
223
+ <td style="border-left: 1px solid #CCC">.</td>
224
+ <td style="border-left: 1px solid #CCC">39</td>
225
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>+ @lines.tap do</pre></td>
226
+ </tr>
227
+ <tr style="background-color: #DFD" >
228
+ <td style="border-left: 1px solid #CCC">.</td>
229
+ <td style="border-left: 1px solid #CCC">40</td>
230
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>+ input.split(/\r?\n/).each do |line_str|</pre></td>
231
+ </tr>
232
+ <tr style="background-color: #DFD" >
233
+ <td style="border-left: 1px solid #CCC">.</td>
234
+ <td style="border-left: 1px solid #CCC">41</td>
235
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>+ line = PrettyDiff::Line.new(diff, line_str)</pre></td>
236
+ </tr>
237
+ <tr>
238
+ <td style="border-left: 1px solid #CCC">41</td>
239
+ <td style="border-left: 1px solid #CCC">42</td>
240
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> next if line.ignore?</pre></td>
241
+ </tr>
242
+ <tr>
243
+ <td style="border-left: 1px solid #CCC">42</td>
244
+ <td style="border-left: 1px solid #CCC">43</td>
245
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> @lines &lt;&lt; line</pre></td>
246
+ </tr>
247
+ <tr>
248
+ <td style="border-left: 1px solid #CCC">43</td>
249
+ <td style="border-left: 1px solid #CCC">44</td>
250
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> line_numbers.act_on_line(line)</pre></td>
251
+ </tr>
252
+ <tr style="background-color: #F0F0FF" >
253
+ <td style="border-left: 1px solid #CCC">...</td>
254
+ <td style="border-left: 1px solid #CCC">...</td>
255
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #888"><pre>@@ -45,4 +46,4 @@ private</pre></td>
256
+ </tr>
257
+ <tr>
258
+ <td style="border-left: 1px solid #CCC">45</td>
259
+ <td style="border-left: 1px solid #CCC">46</td>
260
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> end</pre></td>
261
+ </tr>
262
+ <tr>
263
+ <td style="border-left: 1px solid #CCC">46</td>
264
+ <td style="border-left: 1px solid #CCC">47</td>
265
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> end</pre></td>
266
+ </tr>
267
+ <tr>
268
+ <td style="border-left: 1px solid #CCC">47</td>
269
+ <td style="border-left: 1px solid #CCC">48</td>
270
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre> </pre></td>
271
+ </tr>
272
+ <tr style="background-color: #FDD" >
273
+ <td style="border-left: 1px solid #CCC">48</td>
274
+ <td style="border-left: 1px solid #CCC">.</td>
275
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>-end</pre></td>
276
+ </tr>
277
+ <tr style="background-color: #DFD" >
278
+ <td style="border-left: 1px solid #CCC">.</td>
279
+ <td style="border-left: 1px solid #CCC">49</td>
280
+ <td style="border-left: 1px solid #CCC; border-right: 1px solid #CCC; color: #000"><pre>+end</pre></td>
281
+ </tr>
52
282
  </table>