class PatienceDiff::Html::Formatter
Produces a fancy HTML-formatted unified diff. All your friends will be jealous.
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
PatienceDiff::Formatter::new
# 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
Public Instance Methods
format() { |context| ... }
click to toggle source
# 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)
click to toggle source
Calls superclass method
PatienceDiff::Formatter#render_header
# 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)
click to toggle source
# 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)
click to toggle source
Render a single file as if it were a diff with no changes & full context
# File lib/patience_diff/html/formatter.rb, line 39 def render_orphan(sequence, name, timestamp) @names << name left_header = "--- New file" right_header = right_header_line(name, timestamp) 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
Private Instance Methods
hunk_context(a, b, hunk_marker, opcodes, last_hunk_end)
click to toggle source
# File lib/patience_diff/html/formatter.rb, line 65 def hunk_context(a, b, hunk_marker, opcodes, last_hunk_end) @hunk_count += 1 HunkHelper.new(a, b, render_hunk_marker(opcodes), opcodes, last_hunk_end, @hunk_count) end
template(filename = "html.erb")
click to toggle source
# File lib/patience_diff/html/formatter.rb, line 56 def template(filename = "html.erb") @erbs[template_path(filename)] end
template_path(filename)
click to toggle source
override to add/change templates
# File lib/patience_diff/html/formatter.rb, line 61 def template_path(filename) File.join(PatienceDiff::TEMPLATE_PATH, filename) end