Class: PrettyDiff::Diff

Inherits:
Object show all
Defined in:
lib/pretty_diff/diff.rb

Overview

Main class to interact with. In fact this is the only class you should interact with when using the library.

Usage example

pretty = PrettyDiff::Diff.new(udiff)
pretty.to_html

Keep in mind that Diff will automatically escape all HTML tags from the intput string so that it doesn’t interfere with the output.

Constant Summary collapse

CHUNK_REGEXP =
/@@ .+ @@\n/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(unified_diff, options = {}) ⇒ Diff

Create new Diff object. Accept a String in unified diff format and options hash. Currrent options:

  • wrap_lines – wrap each line in code block with <div> element.



23
24
25
26
# File 'lib/pretty_diff/diff.rb', line 23

def initialize(unified_diff, options={})
  @input = escape_html(unified_diff)
  @options = options
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



17
18
19
# File 'lib/pretty_diff/diff.rb', line 17

def input
  @input
end

#optionsObject (readonly)

Returns the value of attribute options.



17
18
19
# File 'lib/pretty_diff/diff.rb', line 17

def options
  @options
end

Instance Method Details

#chunksObject

Return an array of Chunk objects that Diff found in the input.



34
35
36
# File 'lib/pretty_diff/diff.rb', line 34

def chunks
  @_chunks ||= find_chunks(input)
end

#to_htmlObject

Generate HTML presentation. Return a string.



29
30
31
# File 'lib/pretty_diff/diff.rb', line 29

def to_html    
  generator.generate
end