pretty_diff 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.6.0
@@ -2,9 +2,10 @@
2
2
  # Represent a single piece of a diff.
3
3
  #
4
4
  class PrettyDiff::Chunk #:nodoc:
5
- attr_reader :meta_info, :input, :lines
5
+ attr_reader :diff, :meta_info, :input, :lines
6
6
 
7
- def initialize(meta_info, input)
7
+ def initialize(diff, meta_info, input)
8
+ @diff = diff
8
9
  @meta_info = meta_info
9
10
  @input = input
10
11
  end
@@ -22,7 +23,7 @@ class PrettyDiff::Chunk #:nodoc:
22
23
  # IMPORTANT! Before calling this method it's essential to call "find_lines!" first,
23
24
  # otherwise the array will be empty.
24
25
  def line_numbers
25
- @_line_numbers ||= PrettyDiff::LineNumbers.new(meta_info)
26
+ @_line_numbers ||= PrettyDiff::LineNumbers.new(diff, meta_info)
26
27
  end
27
28
 
28
29
  private
@@ -36,7 +37,7 @@ private
36
37
  def find_lines!
37
38
  returning(@lines = []) do
38
39
  input.split(/\r?\n/).each do |line_str|
39
- line = PrettyDiff::Line.new(line_str)
40
+ line = PrettyDiff::Line.new(diff, line_str)
40
41
  next if line.ignore?
41
42
  @lines << line
42
43
  line_numbers.act_on_line(line)
@@ -14,11 +14,15 @@ require 'cgi'
14
14
  class PrettyDiff::Diff
15
15
  CHUNK_REGEXP = /@@ .+ @@\n/
16
16
 
17
- attr_reader :input
17
+ attr_reader :input, :options
18
18
 
19
- # Create new Diff object. Accept a String in unified diff format.
20
- def initialize(unified_diff)
19
+ # Create new Diff object.
20
+ # Accept a String in unified diff format and options hash.
21
+ # Currrent options:
22
+ # * wrap_lines -- wrap each line in code block with <div> element.
23
+ def initialize(unified_diff, options={})
21
24
  @input = escape_html(unified_diff)
25
+ @options = options
22
26
  end
23
27
 
24
28
  # Generate HTML presentation. Return a string.
@@ -45,7 +49,7 @@ private
45
49
  split = text.split(CHUNK_REGEXP)
46
50
  split.shift
47
51
  split.each_with_index do |lines, idx|
48
- chunks << PrettyDiff::Chunk.new(meta_info[idx], lines)
52
+ chunks << PrettyDiff::Chunk.new(self, meta_info[idx], lines)
49
53
  end
50
54
  end
51
55
  end
@@ -23,9 +23,11 @@ private
23
23
  end
24
24
 
25
25
  def wrapper_html
26
- %Q[<div>] +
27
- yield +
28
- %Q[</div>]
26
+ if line.diff.options[:wrap_lines]
27
+ "<div> #{yield} </div>"
28
+ else
29
+ yield
30
+ end
29
31
  end
30
32
 
31
33
  def added_html(text)
@@ -21,7 +21,7 @@ private
21
21
  end
22
22
 
23
23
  def column_html(text)
24
- %Q[<td class="linenos"><pre>
24
+ %Q[<td width="2%" class="linenos"><pre>
25
25
  #{text}</pre></td>]
26
26
  end
27
27
 
@@ -3,9 +3,10 @@
3
3
  #
4
4
  class PrettyDiff::Line #:nodoc:
5
5
 
6
- attr_reader :input
6
+ attr_reader :diff, :input
7
7
 
8
- def initialize(input)
8
+ def initialize(diff, input)
9
+ @diff = diff
9
10
  @input = input
10
11
  end
11
12
 
@@ -4,9 +4,10 @@
4
4
  #
5
5
  class PrettyDiff::LineNumbers #:nodoc:
6
6
 
7
- attr_reader :meta_info
7
+ attr_reader :diff, :meta_info
8
8
 
9
- def initialize(meta)
9
+ def initialize(diff, meta)
10
+ @diff = diff
10
11
  @meta_info = meta
11
12
  end
12
13
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{pretty_diff}
8
- s.version = "0.5.0"
8
+ s.version = "0.6.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ilya Sabanin"]
12
- s.date = %q{2010-01-24}
12
+ s.date = %q{2010-03-03}
13
13
  s.description = %q{PrettyDiff is a highly customizable library for creating fully featured HTML
14
14
  listings out of unified diff format strings.
15
15
  Include copy/paste-safe line numbers and built-in syntax highlighting.}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pretty_diff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Sabanin
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-24 00:00:00 +07:00
12
+ date: 2010-03-03 00:00:00 +07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency