compass/src/test/testData/gems/compass-0.13.alpha.2/lib/compass/actions.rb
# Write a file given the file contents as a string
Write a file given the file contents as a string
Write a file given the file contents as a string
def write_file(file_name, contents, options = nil, binary = false)
      options ||= self.options if self.respond_to?(:options)
      skip_write = options[:dry_run]
      contents = process_erb(contents, options[:erb]) if options[:erb]
      if File.exists?(file_name)
        existing_contents = IO.read(file_name)
        if existing_contents == contents
          log_action :identical, basename(file_name), options
          skip_write = true
        elsif options[:force]
          log_action :overwrite, basename(file_name), options
        else
          msg = "File #{basename(file_name)} already exists. Run with --force to force overwrite."
          raise Compass::FilesystemConflict.new(msg)
        end
      else
        log_action :create, basename(file_name), options
      end
      if skip_write
        FileUtils.touch file_name unless options[:dry_run]
      else
        mode = "w"
        mode << "b" if binary
        open(file_name, mode) do |file|
          file.write(contents)
        end
      end
    end
def write_file ( file_name , contents , options = nil , binary = false ) options ||= self . options if self . respond_to? ( :options ) skip_write = options [ :dry_run ] contents = process_erb ( contents , options [ :erb ] ) if options [ :erb ] if File . exists? ( file_name ) existing_contents = IO . read ( file_name ) if existing_contents == contents log_action :identical , basename ( file_name ) , options skip_write = true elsif options [ :force ] log_action :overwrite , basename ( file_name ) , options else msg = "File #{basename(file_name)} already exists. Run with --force to force overwrite." raise Compass :: FilesystemConflict . new ( msg ) end else log_action :create , basename ( file_name ) , options end if skip_write FileUtils . touch file_name unless options [ :dry_run ] else mode = "w" mode << "b" if binary open ( file_name , mode ) do | file | file . write ( contents ) end end end
Write a file given the file contents as a string
Write a file given the file contents as a string
file_name
contents
options
binary