class Compass::Commands::UpdateProject

Public Class Methods

absolutize(*paths) click to toggle source
# File lib/compass/commands/update_project.rb, line 141
def absolutize(*paths)
  paths.map {|path| File.expand_path(path) }
end
description(command) click to toggle source
# File lib/compass/commands/update_project.rb, line 121
def description(command)
  "Compile Sass stylesheets to CSS"
end
new(working_path, options) click to toggle source
Calls superclass method Compass::Commands::ProjectBase.new
# File lib/compass/commands/update_project.rb, line 40
def initialize(working_path, options)
  super
  assert_project_directory_exists!
end
option_parser(arguments) click to toggle source
# File lib/compass/commands/update_project.rb, line 108
def option_parser(arguments)
  parser = Compass::Exec::CommandOptionParser.new(arguments)
  parser.extend(Compass::Exec::GlobalOptionsParser)
  parser.extend(Compass::Exec::ProjectOptionsParser)
  parser.extend(CompileProjectOptionsParser)
end
parse!(arguments) click to toggle source
# File lib/compass/commands/update_project.rb, line 125
def parse!(arguments)
  parser = option_parser(arguments)
  parser.parse!
  parse_arguments!(parser, arguments)
  parser.options
end
parse_arguments!(parser, arguments) click to toggle source
# File lib/compass/commands/update_project.rb, line 132
def parse_arguments!(parser, arguments)
  if arguments.size > 0
    parser.options[:project_name] = arguments.shift if File.directory?(arguments.first)
    unless arguments.empty?
      parser.options[:only_sass_files] = absolutize(*arguments)
    end
  end
end
primary() click to toggle source
# File lib/compass/commands/update_project.rb, line 119
def primary; true; end
usage() click to toggle source
# File lib/compass/commands/update_project.rb, line 115
def usage
  option_parser([]).to_s
end

Public Instance Methods

check_for_sass_files!(compiler) click to toggle source
# File lib/compass/commands/update_project.rb, line 81
def check_for_sass_files!(compiler)
  file_list = compiler.file_list
  if file_list.empty?
    message = "Compass can't find any Sass files to compile.\nIs your compass configuration correct?.\nIf you're trying to start a new project, you have left off the directory argument.\n"
    message << "Run \"compass -h\" to get help."
    raise Compass::Error, message
  elsif missing = file_list.find {|(sass_file, _, _)| !File.exist?(sass_file)}
    raise Compass::Error, "File not found: #{missing[0]}"
  end
end
compiler_options() click to toggle source
# File lib/compass/commands/update_project.rb, line 96
def compiler_options
  transfer_options(options, {}, :time, :debug_info, :only_sass_files, :force, :quiet)
end
new_compiler_instance() click to toggle source
# File lib/compass/commands/update_project.rb, line 92
def new_compiler_instance
  Compass::SassCompiler.new(compiler_options)
end
new_config?(compiler) click to toggle source

Determines if the configuration file is newer than any css file

# File lib/compass/commands/update_project.rb, line 71
def new_config?(compiler)
  config_file = Compass.detect_configuration_file
  return false unless config_file
  config_mtime = File.mtime(config_file)
  compiler.file_list.each do |(_, css_filename, _)|
    return config_file if File.exists?(css_filename) && config_mtime > File.mtime(css_filename)
  end
  nil
end
perform() click to toggle source
# File lib/compass/commands/update_project.rb, line 45
def perform
  compiler = new_compiler_instance
  check_for_sass_files!(compiler)
  prepare_project!(compiler)
  compiler.compile!
  if compiler.error_count > 0
    compiler.logger.red do
      compiler.logger.log "Compilation failed in #{compiler.error_count} files."
    end
    failed! 
  end
end
prepare_project!(compiler) click to toggle source
# File lib/compass/commands/update_project.rb, line 58
def prepare_project!(compiler)
  if options[:project_name]
    Compass.configuration.project_path = File.expand_path(options[:project_name])
  end

  if config_file = new_config?(compiler)
    compiler.logger.record :modified, relativize(config_file)
    compiler.logger.record :clean, relativize(Compass.configuration.css_path)
    compiler.clean!
  end
end
transfer_options(from, to, *keys) click to toggle source
# File lib/compass/commands/update_project.rb, line 100
def transfer_options(from, to, *keys)
  keys.each do |k|
    to[k] = from[k] unless from[k].nil?
  end
  to
end