Class: PrettyDiff::Diff
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
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#chunks ⇒ Object
Return an array of Chunk objects that Diff found in the input.
-
#initialize(unified_diff, options = {}) ⇒ Diff
constructor
Create new Diff object.
-
#to_html ⇒ Object
Generate HTML presentation.
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, ={}) @input = escape_html(unified_diff) @options = end |
Instance Attribute Details
#input ⇒ Object (readonly)
Returns the value of attribute input.
17 18 19 |
# File 'lib/pretty_diff/diff.rb', line 17 def input @input end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
17 18 19 |
# File 'lib/pretty_diff/diff.rb', line 17 def @options end |
Instance Method Details
#chunks ⇒ Object
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_html ⇒ Object
Generate HTML presentation. Return a string.
29 30 31 |
# File 'lib/pretty_diff/diff.rb', line 29 def to_html generator.generate end |