vendor/gems/chriseppstein-compass-0.8.10/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]
      if File.exists?(file_name)
        existing_contents = IO.read(file_name)
        if existing_contents == contents
          logger.record :identical, basename(file_name)
          skip_write = true
        elsif options[:force]
          logger.record :overwrite, basename(file_name)
        else
          msg = "File #{basename(file_name)} already exists. Run with --force to force overwrite."
          raise Compass::FilesystemConflict.new(msg)
        end
      else
        logger.record :create, basename(file_name)
      end
      if skip_write
        FileUtils.touch file_name
      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 ] if File . exists? ( file_name ) existing_contents = IO . read ( file_name ) if existing_contents == contents logger . record :identical , basename ( file_name ) skip_write = true elsif options [ :force ] logger . record :overwrite , basename ( file_name ) else msg = "File #{basename(file_name)} already exists. Run with --force to force overwrite." raise Compass :: FilesystemConflict . new ( msg ) end else logger . record :create , basename ( file_name ) end if skip_write FileUtils . touch file_name 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