Sha256: ff475efb960c53a851d7a4ae5b126b93c0848dc0bf05094c09e178295200197b

Contents?: true

Size: 1.08 KB

Versions: 9

Compression:

Stored size: 1.08 KB

Contents

module CompassRails
  module Test
    module FileHelper
      include DebugHelper

      delegate :mkdir_p, :rm, :rm_rf, :cp_r, :touch, to: ::FileUtils

      def cd(path, &block)
        debug "Entering: #{path}"
        Dir.chdir(path, &block)
      end

      def inject_at_bottom(file_name, string)
        content = File.read(file_name)
        content = "#{content}#{string}"
        File.open(file_name, 'w') { |file| file << content }
      end

      def inject_into_file(file_name, replacement, position, anchor)
        case position
        when :after
          replace(file_name, Regexp.escape(anchor), "#{anchor}#{replacement}")
        when :before
          replace(file_name, Regexp.escape(anchor), "#{replacement}#{anchor}")
        else
          raise Compass::FilesystemConflict.new("You need to specify :before or :after")
        end
      end

      def replace(destination, regexp, string)
        content = File.read(destination)
        content.gsub!(Regexp.new(regexp), string)
        File.open(destination, 'wb') { |file| file.write(content) }
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
compass-rails-4.0.0 test/helpers/file_helper.rb
compass-rails-3.1.0 test/helpers/file_helper.rb
compass-rails-3.0.2 test/helpers/file_helper.rb
compass-rails-3.0.1 test/helpers/file_helper.rb
compass-rails-3.0.0 test/helpers/file_helper.rb
glebtv-compass-rails-2.0.4 test/helpers/file_helper.rb
compass-rails-2.0.5 test/helpers/file_helper.rb
compass-rails-2.0.4 test/helpers/file_helper.rb
compass-rails-2.0.3 test/helpers/file_helper.rb