class LCS::HTMLDiff
Produce a simple HTML diff view.
Constants
- DEFAULT_CSS
standard:disable Layout/HeredocIndentation
- DEFAULT_OPTIONS
standard:disable Style/HashSyntax
Attributes
options[R]
Public Class Methods
new(left, right, options = nil)
click to toggle source
# File lib/diff/lcs/htmldiff.rb, line 94 def initialize(left, right, options = nil) @left = left @right = right @options = options @options = DEFAULT_OPTIONS.dup if @options.nil? end
Public Instance Methods
run()
click to toggle source
# File lib/diff/lcs/htmldiff.rb, line 116 def run verify_options if @options[:expand_tabs].positive? && self.class.can_expand_tabs formatter = Text::Format.new formatter.tabstop = @options[:expand_tabs] @left.map! { |line| formatter.expand(line.chomp) } @right.map! { |line| formatter.expand(line.chomp) } end @left.map! { |line| CGI.escapeHTML(line.chomp) } @right.map! { |line| CGI.escapeHTML(line.chomp) } # standard:disable Layout/HeredocIndentation @options[:output] << <<-OUTPUT <html> <head> <title>#{@options[:title]}</title> <style type="text/css"> #{@options[:css]} </style> </head> <body> <h1>#{@options[:title]}</h1> <p>Legend: <span class="only_a">Only in Old</span> <span class="only_b">Only in New</span></p> <div class="diff"> OUTPUT # standard:enable Layout/HeredocIndentation callbacks = Callbacks.new(@options[:output]) Diff::LCS.traverse_sequences(@left, @right, callbacks) # standard:disable Layout/HeredocIndentation @options[:output] << <<-OUTPUT </div> </body> </html> OUTPUT # standard:enable Layout/HeredocIndentation end