module SiteDiff::Diff
Public Instance Methods
binary_diffy(before, after, before_encoding, after_encoding)
click to toggle source
Computes diff of binary files using MD5 hashes.
# File lib/sitediff/diff.rb, line 34 def binary_diffy(before, after, before_encoding, after_encoding) if before_encoding || after_encoding Diffy::Diff.new(encoding_blurb(before_encoding), encoding_blurb(after_encoding)).to_s(:html) elsif before == after nil else md5_before = Digest::MD5.hexdigest(before) md5_after = Digest::MD5.hexdigest(after) Diffy::Diff.new("Binary content returned md5: #{md5_before}", "Binary content returned md5: #{md5_after}").to_s(:html) end end
diff_config(config)
click to toggle source
Set configuration for Diffy.
# File lib/sitediff/diff.rb, line 78 def diff_config(config) diff_options = Diffy::Diff.default_options[:diff] diff_options = [diff_options] unless diff_options.is_a?(Array) # ignore_whitespace option diff_options.push('-w').uniq if config.ignore_whitespace Diffy::Diff.default_options[:diff] = diff_options end
encoding_blurb(encoding)
click to toggle source
Generates a description about encoding.
# File lib/sitediff/diff.rb, line 24 def encoding_blurb(encoding) if encoding "Text content returned - charset #{encoding}" else 'Binary content returned' end end
generate_diff_output(result, relative = false)
click to toggle source
Generates diff output for a single result.
# File lib/sitediff/diff.rb, line 71 def generate_diff_output(result, relative = false) erb_path = File.join(SiteDiff::FILES_DIR, 'diff.html.erb') ERB.new(File.read(erb_path)).result(binding) end
generate_html(results, before, after, cache, config)
click to toggle source
Generates an HTML report. TODO: Generate the report in SiteDif::Report instead.
# File lib/sitediff/diff.rb, line 60 def generate_html(results, before, after, cache, config) relative = config.export report = config.report || {} before_url_report = report['before_url_report'] after_url_report = report['after_url_report'] erb_path = File.join(SiteDiff::FILES_DIR, 'report.html.erb') ERB.new(File.read(erb_path)).result(binding) end
html_diffy(before_html, after_html)
click to toggle source
Generates HTML diff.
# File lib/sitediff/diff.rb, line 16 def html_diffy(before_html, after_html) diff = Diffy::Diff.new(before_html, after_html) # If the diff is non-empty, convert it to string. diff.first ? diff.to_s(:html) : nil end
terminal_diffy(before_html, after_html)
click to toggle source
Generates diff for CLI output.
# File lib/sitediff/diff.rb, line 50 def terminal_diffy(before_html, after_html) args = [] args << :color if Rainbow.enabled Diffy::Diff.new(before_html, after_html, context: 3) .to_s(*args) end