Class: PatienceDiff::Html::Formatter
- Defined in:
- lib/patience_diff/html/formatter.rb
Overview
Produces a fancy HTML-formatted unified diff. All your friends will be jealous.
Instance Attribute Summary
Attributes inherited from Formatter
#left_name, #left_timestamp, #names, #right_name, #right_timestamp, #title
Instance Method Summary collapse
- #format {|context| ... } ⇒ Object
-
#initialize(*args) ⇒ Formatter
constructor
A new instance of Formatter.
- #render_header(*args) ⇒ Object
- #render_hunk(a, b, opcodes, last_hunk_end) ⇒ Object
-
#render_orphan(sequence, name, timestamp) ⇒ Object
Render a single file as if it were a diff with no changes & full context.
Methods inherited from Formatter
Constructor Details
#initialize(*args) ⇒ Formatter
Returns a new instance of Formatter.
13 14 15 16 17 18 19 |
# File 'lib/patience_diff/html/formatter.rb', line 13 def initialize(*args) super(*args) @erbs = Hash.new do |hash, key| hash[key] = Erubis::Eruby.new(File.read(key)) end @hunk_count = 0 end |
Instance Method Details
#format {|context| ... } ⇒ Object
21 22 23 24 25 |
# File 'lib/patience_diff/html/formatter.rb', line 21 def format context = FormattingContext.new(@differ, self) yield context template.evaluate(context) end |
#render_header(*args) ⇒ Object
27 28 29 30 31 |
# File 'lib/patience_diff/html/formatter.rb', line 27 def render_header(*args) left_header, right_header = *super(*args) helper = HeaderHelper.new(left_header, right_header, @names.count - 1) template("html_header.erb").evaluate(helper) end |
#render_hunk(a, b, opcodes, last_hunk_end) ⇒ Object
33 34 35 36 |
# File 'lib/patience_diff/html/formatter.rb', line 33 def render_hunk(a, b, opcodes, last_hunk_end) helper = hunk_context(a, b, render_hunk_marker(opcodes), opcodes, last_hunk_end) template("html_hunk.erb").evaluate(helper) end |
#render_orphan(sequence, name, timestamp) ⇒ Object
Render a single file as if it were a diff with no changes & full context
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/patience_diff/html/formatter.rb', line 39 def render_orphan(sequence, name, ) @names << name left_header = "--- New file" right_header = right_header_line(name, ) helper = HeaderHelper.new(left_header, right_header, @names.count - 1) result = template("html_header.erb").evaluate(helper) # create one opcode with the entire content opcodes = [ [:equal, 0, sequence.length-1, 0, sequence.length-1] ] helper = hunk_context(sequence, sequence, nil, opcodes, 0) result << template("html_hunk.erb").evaluate(helper) result end |