Sha256: 5ca7926e0472e3c65da9ea13165bde3ac43032d9ae086fe23ab58744054cec9d

Contents?: true

Size: 1.34 KB

Versions: 28

Compression:

Stored size: 1.34 KB

Contents

require 'diff/lcs'
require 'diff/lcs/hunk'
module Compass
  module Diff
    #stole this from rspec who stole this from the gem
    def diff_as_string(data_old, data_new)
      data_old = data_old.split(/\n/).map! { |e| e.chomp }
      data_new = data_new.split(/\n/).map! { |e| e.chomp }
      output = ""
      diffs = ::Diff::LCS.diff(data_old, data_new)
      return output if diffs.empty?
      oldhunk = hunk = nil  
      file_length_difference = 0
      diffs.each do |piece|
        begin
          hunk = ::Diff::LCS::Hunk.new(
            data_old, data_new, piece, context_lines, file_length_difference
          )
          file_length_difference = hunk.file_length_difference      
          next unless oldhunk      
          # Hunks may overlap, which is why we need to be careful when our
          # diff includes lines of context. Otherwise, we might print
          # redundant lines.
          if (context_lines > 0) and hunk.overlaps?(oldhunk)
            hunk.unshift(oldhunk)
          else
            output << oldhunk.diff(format)
          end
        ensure
          oldhunk = hunk
          output << "\n"
        end
      end  
      #Handle the last remaining hunk
      output << oldhunk.diff(format) << "\n"
    end
  
    protected

      def format
        :unified
      end

      def context_lines
        3
      end
  
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
arcabouco-0.2.13 vendor/bundle/gems/compass-1.0.3/test/helpers/diff.rb
compass-1.0.3 test/helpers/diff.rb
compass-1.1.0.alpha.3 test/helpers/diff.rb
compass-1.1.0.alpha.2 test/helpers/diff.rb
compass-1.1.0.alpha.1 test/helpers/diff.rb
compass-1.1.0.alpha.0 test/helpers/diff.rb
compass-1.0.1 test/helpers/diff.rb
compass-1.0.0 test/helpers/diff.rb
compass-1.0.0.rc.1 test/helpers/diff.rb
compass-1.0.0.rc.0 test/helpers/diff.rb
compass-1.0.0.alpha.21 test/helpers/diff.rb
compass-1.0.0.alpha.20 test/helpers/diff.rb
compass-1.0.0.alpha.19 test/helpers/diff.rb
compass-1.0.0.alpha.18 test/helpers/diff.rb
compass-1.0.0.alpha.17 test/helpers/diff.rb
compass-1.0.0.alpha.16 test/helpers/diff.rb
compass-1.0.0.alpha.15 test/helpers/diff.rb
compass-1.0.0.alpha.14 test/helpers/diff.rb
compass-1.0.0.alpha.13 test/helpers/diff.rb
compass-0.13.alpha.12 test/helpers/diff.rb