Sha256: 2850f9154b2202e24cb1117416e37a3c5516fbe01df785f5f1d05b796f0d9c64

Contents?: true

Size: 1.08 KB

Versions: 12

Compression:

Stored size: 1.08 KB

Contents

require "spec/runner/differs/load-diff-lcs"
require 'pp'

module RedClothDiffers
  unless defined?(Inline)
    class Inline
      def initialize(options)
        @options = options
      end
      
      DIFF_ASCII_COLORS = {
        "=" => "\e[0m",
        "+" => "\e[42m",
        "-" => "\e[41m",
        "!" => "\e[43m"
      }

      def diff_as_string(data_new, data_old)
        output = "\e[0m"
        last_action = nil
        sdiff = Diff::LCS.sdiff(data_old, data_new)
        sdiff.each do |change|
          unless change.action == last_action
            output << DIFF_ASCII_COLORS[change.action]
            last_action = change.action
          end
          output << case change.action
          when "+"
            change.new_element
          when "-"
            change.old_element
          when "="
            change.old_element
          when "!"
            change.old_element
          end
        end
        
        output
      end  

      def diff_as_object(target,expected)
        diff_as_string(PP.pp(target,""), PP.pp(expected,""))
      end
    end

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
RedCloth-4.2.3-x86-mswin32-60 spec/differs/inline.rb
RedCloth-4.2.3-universal-java spec/differs/inline.rb
RedCloth-4.2.3 spec/differs/inline.rb
RedCloth-4.2.2-x86-mswin32-60 spec/differs/inline.rb
RedCloth-4.2.2-universal-java spec/differs/inline.rb
RedCloth-4.2.1-x86-mswin32-60 spec/differs/inline.rb
RedCloth-4.2.1-universal-java spec/differs/inline.rb
RedCloth-4.2.1 spec/differs/inline.rb
RedCloth-4.2.2 spec/differs/inline.rb
RedCloth-4.2.0 spec/differs/inline.rb
RedCloth-4.2.0-universal-java spec/differs/inline.rb
RedCloth-4.2.0-x86-mswin32-60 spec/differs/inline.rb