Expose CLI config parameters at configuration parse time.
This commit is contained in:
parent
b47ff5106a
commit
f318e93764
@ -22,6 +22,10 @@ The Documentation for the [latest preview release](http://beta.compass-style.org
|
|||||||
optional based on Compass's legacy support settings.
|
optional based on Compass's legacy support settings.
|
||||||
* Added the ability to piggy back on compass's watcher within your configuration file.
|
* Added the ability to piggy back on compass's watcher within your configuration file.
|
||||||
See the [configuration reference](/help/tutorials/configuration-reference/) for details.
|
See the [configuration reference](/help/tutorials/configuration-reference/) for details.
|
||||||
|
* The options passed to the CLI can now be inspected within the compass configuration file.
|
||||||
|
The CLI options will still override the values set within the config file, but they might
|
||||||
|
inform other values. For instance `compass compile -e production` will have the environment
|
||||||
|
parameter preset to `:production` so that you can set other values in the project accordingly.
|
||||||
|
|
||||||
|
|
||||||
0.11.alpha.4 (12/08/2010)
|
0.11.alpha.4 (12/08/2010)
|
||||||
|
@ -28,7 +28,7 @@ module Compass
|
|||||||
end
|
end
|
||||||
|
|
||||||
def add_project_configuration
|
def add_project_configuration
|
||||||
Compass.add_project_configuration(options[:configuration_file]) do
|
Compass.add_project_configuration(options[:configuration_file], :defaults => Compass.configuration_for(options, "cli_defaults")) do
|
||||||
options[:project_type]
|
options[:project_type]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -27,18 +27,18 @@ module Compass
|
|||||||
@configuration = data
|
@configuration = data
|
||||||
end
|
end
|
||||||
|
|
||||||
def configuration_for(config, filename = nil)
|
def configuration_for(config, filename = nil, defaults = nil)
|
||||||
if config.nil?
|
if config.nil?
|
||||||
nil
|
nil
|
||||||
elsif config.is_a?(Compass::Configuration::Data)
|
elsif config.is_a?(Compass::Configuration::Data)
|
||||||
config
|
config
|
||||||
elsif config.respond_to?(:read)
|
elsif config.respond_to?(:read)
|
||||||
filename ||= config.to_s if config.is_a?(Pathname)
|
filename ||= config.to_s if config.is_a?(Pathname)
|
||||||
Compass::Configuration::Data.new_from_string(config.read, filename)
|
Compass::Configuration::Data.new_from_string(config.read, filename, defaults)
|
||||||
elsif config.is_a?(Hash)
|
elsif config.is_a?(Hash)
|
||||||
Compass::Configuration::Data.new(filename, config)
|
Compass::Configuration::Data.new(filename, config)
|
||||||
elsif config.is_a?(String)
|
elsif config.is_a?(String)
|
||||||
Compass::Configuration::Data.new_from_file(config)
|
Compass::Configuration::Data.new_from_file(config, defaults)
|
||||||
elsif config.is_a?(Symbol)
|
elsif config.is_a?(Symbol)
|
||||||
Compass::AppIntegration.lookup(config).configuration
|
Compass::AppIntegration.lookup(config).configuration
|
||||||
else
|
else
|
||||||
@ -76,7 +76,7 @@ module Compass
|
|||||||
options = args.last.is_a?(Hash) ? args.pop : {}
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
||||||
configuration_file_path = args.shift || detect_configuration_file
|
configuration_file_path = args.shift || detect_configuration_file
|
||||||
raise ArgumentError, "Too many arguments" if args.any?
|
raise ArgumentError, "Too many arguments" if args.any?
|
||||||
if data = configuration_for(configuration_file_path)
|
if data = configuration_for(configuration_file_path, nil, configuration_for(options[:defaults]))
|
||||||
if data.raw_project_type
|
if data.raw_project_type
|
||||||
add_configuration(data.raw_project_type.to_sym)
|
add_configuration(data.raw_project_type.to_sym)
|
||||||
elsif options[:project_type]
|
elsif options[:project_type]
|
||||||
|
@ -87,6 +87,16 @@ module Compass
|
|||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reset_inheritance!
|
||||||
|
self.inherited_data = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def with_defaults(data)
|
||||||
|
inherit_from!(data)
|
||||||
|
yield
|
||||||
|
reset_inheritance!
|
||||||
|
end
|
||||||
|
|
||||||
def unset!(attribute)
|
def unset!(attribute)
|
||||||
@set_attributes ||= {}
|
@set_attributes ||= {}
|
||||||
send("#{attribute}=", nil)
|
send("#{attribute}=", nil)
|
||||||
|
@ -8,15 +8,19 @@ module Compass
|
|||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
def new_from_file(config_file)
|
def new_from_file(config_file, defaults)
|
||||||
data = Data.new(config_file)
|
data = Data.new(config_file)
|
||||||
data._parse(config_file)
|
data.with_defaults(defaults) do
|
||||||
|
data._parse(config_file)
|
||||||
|
end
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_from_string(contents, filename)
|
def new_from_string(contents, filename, defaults)
|
||||||
data = Data.new(filename)
|
data = Data.new(filename)
|
||||||
data.parse_string(contents, filename)
|
data.with_defaults(defaults) do
|
||||||
|
data.parse_string(contents, filename)
|
||||||
|
end
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user