Sha256: 56635ff6fd5e8019d8c62ea1658eb868f783ca30e99054a7802ad8d4fa3796bc

Contents?: true

Size: 1.34 KB

Versions: 47

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_new, data_old)
      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

47 entries across 46 versions & 6 rubygems

Version Path
compass-sourcemaps-0.12.4.sourcemaps.a4836f1 test/helpers/diff.rb
archetype-0.0.1.pre.3.00dfd9a test/helpers/diff.rb
archetype-0.0.1.pre.3.83f0d7a test/helpers/diff.rb
archetype-0.0.1.pre.3.55c4182 test/helpers/diff.rb
compass-0.13.alpha.2 test/helpers/diff.rb
archetype-0.0.1.pre.3.811928f test/helpers/diff.rb
compass-0.12.2 test/helpers/diff.rb
compass-0.12.2.rc.1 test/helpers/diff.rb
compass-0.12.2.rc.0 test/helpers/diff.rb
compass-0.13.alpha.0 test/helpers/diff.rb
compass-0.12.1 test/helpers/diff.rb
compass-0.12.0 test/helpers/diff.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/compass-0.11.7/test/helpers/diff.rb
compass-0.12.rc.1 test/helpers/diff.rb
compass-0.12.rc.0 test/helpers/diff.rb
compass-0.11.7 test/helpers/diff.rb
compass-0.12.alpha.4 test/helpers/diff.rb
compass-0.12.alpha.3 test/helpers/diff.rb
compass-0.11.6 test/helpers/diff.rb
compass-0.12.alpha.2 test/helpers/diff.rb