Class: Compass::Commands::WriteConfiguration

Inherits:
ProjectBase show all
Includes:
InstallerCommand
Defined in:
lib/compass/commands/write_configuration.rb

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 included from InstallerCommand

#app, #configure!, #installer

Methods inherited from ProjectBase

#execute

Methods inherited from Base

#execute, register

Methods included from Actions

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

Constructor Details

#initialize(working_path, options) ⇒ WriteConfiguration

Returns a new instance of WriteConfiguration.



33
34
35
36
# File 'lib/compass/commands/write_configuration.rb', line 33

def initialize(working_path, options)
  super
  assert_project_directory_exists!
end

Class Method Details

.description(command) ⇒ Object



88
89
90
# File 'lib/compass/commands/write_configuration.rb', line 88

def description(command)
  "Generate a configuration file for the provided command line options."
end

.option_parser(arguments) ⇒ Object



77
78
79
80
81
82
# File 'lib/compass/commands/write_configuration.rb', line 77

def option_parser(arguments)
  parser = Compass::Exec::CommandOptionParser.new(arguments)
  parser.extend(Compass::Exec::GlobalOptionsParser)
  parser.extend(Compass::Exec::ProjectOptionsParser)
  parser.extend(ConfigurationOptionsParser)
end

.parse!(arguments) ⇒ Object



92
93
94
95
96
97
# File 'lib/compass/commands/write_configuration.rb', line 92

def parse!(arguments)
  parser = option_parser(arguments)
  parser.parse!
  parse_arguments!(parser, arguments)
  parser.options
end

.parse_arguments!(parser, arguments) ⇒ Object



99
100
101
102
103
104
105
106
107
# File 'lib/compass/commands/write_configuration.rb', line 99

def parse_arguments!(parser, arguments)
  if arguments.size == 1
    parser.options[:configuration_file] = arguments.shift
  elsif arguments.size == 0
    # default to the current directory.
  else
    raise Compass::Error, "Too many arguments were specified."
  end
end

.usageObject



84
85
86
# File 'lib/compass/commands/write_configuration.rb', line 84

def usage
  option_parser([]).to_s
end

Instance Method Details

#add_project_configurationObject



38
39
40
# File 'lib/compass/commands/write_configuration.rb', line 38

def add_project_configuration
  Compass.add_project_configuration
end

#explicit_config_file_must_be_readable?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/compass/commands/write_configuration.rb', line 71

def explicit_config_file_must_be_readable?
  false
end

#installer_argsObject



67
68
69
# File 'lib/compass/commands/write_configuration.rb', line 67

def installer_args
  [nil, project_directory, options]
end

#performObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/compass/commands/write_configuration.rb', line 42

def perform
  if options[:debug]
    puts "Configuration sources:"
    c = Compass.configuration
    while c
      print c.name
      c = c.inherited_data
      print ", " if c
    end
    print "\n"
    Compass.configuration.debug.each do |prop, values|
      if options[:debug].is_a?(Symbol)
        next unless prop == options[:debug]
      end
      puts "***** #{prop} = #{values.first[:resolved].inspect} *****"
      [:default, :value, :raw, :resolved].each do |kind|
        puts "#{kind}: " + values.inject([]){|m, v| m << v[kind]}.map{|v| v.nil? ? '-' : v.inspect}.join(", ")
      end
    end
  else
    directory File.dirname(options[:configuration_file])
    installer.write_configuration_files(options[:configuration_file])
  end
end