class Card::Content::Diff
Attributes
result[R]
Public Class Methods
complete(a, b, opts={})
click to toggle source
# File lib/card/content/diff.rb, line 6 def complete a, b, opts={} Card::Content::Diff.new(a, b, opts).complete end
new(old_version, new_version, opts={})
click to toggle source
diff options :format => :html|:text|:pointer|:raw
:html = maintain html structure, but compare only content :text = remove all html tags; compare plain text :pointer = remove all double square brackets :raw = escape html tags and compare everything
summary: {length: <number> , joint: <string> }
# File lib/card/content/diff.rb, line 35 def initialize old_version, new_version, opts={} @result = Result.new opts[:summary] return unless new_version lcs_opts = lcs_opts_for_format opts[:diff_format] LCS.new(lcs_opts).run(old_version, new_version, @result) end
render_added_chunk(text)
click to toggle source
# File lib/card/content/diff.rb, line 14 def render_added_chunk text "<ins class='diffins diff-added'>#{text}</ins>" end
render_deleted_chunk(text, _count=true)
click to toggle source
# File lib/card/content/diff.rb, line 18 def render_deleted_chunk text, _count=true "<del class='diffdel diff-deleted'>#{text}</del>" end
summary(a, b, opts={})
click to toggle source
# File lib/card/content/diff.rb, line 10 def summary a, b, opts={} Card::Content::Diff.new(a, b, opts).summary end
Public Instance Methods
green?()
click to toggle source
# File lib/card/content/diff.rb, line 47 def green? @result.adds_cnt.positive? end
red?()
click to toggle source
# File lib/card/content/diff.rb, line 43 def red? @result.dels_cnt.positive? end
Private Instance Methods
lcs_opts_for_format(diff_format)
click to toggle source
# File lib/card/content/diff.rb, line 53 def lcs_opts_for_format diff_format opts = {} case diff_format when :html opts[:exclude] = /^</ when :text opts[:reject] = /^</ opts[:postprocess] = proc { |word| word.gsub("\n", "<br>") } when :pointer opts[:preprocess] = proc { |word| word.gsub("[[", "").gsub("]]", "<br>") } else # :raw opts[:preprocess] = proc { |word| CGI.escapeHTML(word) } end opts end