Class: Compass::Commands::UpdateProject

Inherits:
ProjectBase show all
Defined in:
lib/compass/commands/update_project.rb

Direct Known Subclasses

CleanProject, ProjectStats, WatchProject

Instance Attribute Summary

Attributes inherited from ProjectBase

#options, #project_name

Attributes inherited from Base

#options, #working_path

Attributes included from Actions

#logger

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ProjectBase

#execute

Methods inherited from Base

#execute, #failed!, register, #successful?

Methods included from Actions

#basename, #copy, #directory, #log_action, #process_erb, #relativize, #remove, #separate, #strip_trailing_separator, #write_file

Constructor Details

#initialize(working_path, options) ⇒ UpdateProject

Returns a new instance of UpdateProject.



40
41
42
43
# File 'lib/compass/commands/update_project.rb', line 40

def initialize(working_path, options)
  super
  assert_project_directory_exists!
end

Class Method Details

.absolutize(*paths) ⇒ Object



141
142
143
# File 'lib/compass/commands/update_project.rb', line 141

def absolutize(*paths)
  paths.map {|path| File.expand_path(path) }
end

.description(command) ⇒ Object



121
122
123
# File 'lib/compass/commands/update_project.rb', line 121

def description(command)
  "Compile Sass stylesheets to CSS"
end

.option_parser(arguments) ⇒ Object



108
109
110
111
112
113
# 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) ⇒ Object



125
126
127
128
129
130
# 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) ⇒ Object



132
133
134
135
136
137
138
139
# 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

.primaryObject



119
# File 'lib/compass/commands/update_project.rb', line 119

def primary; true; end

.usageObject



115
116
117
# File 'lib/compass/commands/update_project.rb', line 115

def usage
  option_parser([]).to_s
end

Instance Method Details

#check_for_sass_files!(compiler) ⇒ Object



81
82
83
84
85
86
87
88
89
90
# 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_optionsObject



96
97
98
# 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_instanceObject



92
93
94
# File 'lib/compass/commands/update_project.rb', line 92

def new_compiler_instance
  Compass::SassCompiler.new(compiler_options)
end

#new_config?(compiler) ⇒ Boolean

Determines if the configuration file is newer than any css file

Returns:

  • (Boolean)


71
72
73
74
75
76
77
78
79
# 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

#performObject



45
46
47
48
49
50
51
52
53
54
55
56
# 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) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
# 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) ⇒ Object



100
101
102
103
104
105
# 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