diff --git a/lib/compass/commands/installer_command.rb b/lib/compass/commands/installer_command.rb index f63f5acc..7385c7f8 100644 --- a/lib/compass/commands/installer_command.rb +++ b/lib/compass/commands/installer_command.rb @@ -7,7 +7,7 @@ module Compass def configure! Compass.add_configuration(installer.default_configuration) - read_project_configuration + Compass.add_project_configuration Compass.add_configuration(options) Compass.add_configuration(installer.completed_configuration) if File.exists?(Compass.configuration.extensions_path) diff --git a/lib/compass/commands/project_base.rb b/lib/compass/commands/project_base.rb index 21776373..335c403a 100644 --- a/lib/compass/commands/project_base.rb +++ b/lib/compass/commands/project_base.rb @@ -22,14 +22,18 @@ module Compass protected def configure! - read_project_configuration + add_project_configuration if File.exists?(Compass.configuration.extensions_path) Compass::Frameworks.discover(Compass.configuration.extensions_path) end end + def add_project_configuration + Compass.add_project_configuration(options[:configuration_file]) + end + def projectize(path) - File.join(project_directory, separate(path)) + Compass.projectize(path) end def project_directory @@ -48,31 +52,6 @@ module Compass Compass.configuration.images_dir end - # Read the configuration file for this project - def read_project_configuration - if (file = detect_configuration_file) && File.readable?(file) - Compass.add_configuration(file) - end - end - - def explicit_config_file_must_be_readable? - true - end - - # TODO: Deprecate the src/config.rb location. - KNOWN_CONFIG_LOCATIONS = [".compass/config.rb", "config/compass.config", "config.rb", "src/config.rb"] - - # Finds the configuration file, if it exists in a known location. - def detect_configuration_file - if options[:configuration_file] - if explicit_config_file_must_be_readable? && !File.readable?(options[:configuration_file]) - raise Compass::Error, "Configuration file, #{file}, not found or not readable." - end - return options[:configuration_file] - end - KNOWN_CONFIG_LOCATIONS.map{|f| projectize(f)}.detect{|f| File.exists?(f)} - end - def assert_project_directory_exists! if File.exists?(project_directory) && !File.directory?(project_directory) raise Compass::FilesystemConflict.new("#{project_directory} is not a directory.") diff --git a/lib/compass/commands/write_configuration.rb b/lib/compass/commands/write_configuration.rb index 1c8c28fc..7d9604aa 100644 --- a/lib/compass/commands/write_configuration.rb +++ b/lib/compass/commands/write_configuration.rb @@ -11,6 +11,10 @@ module Compass assert_project_directory_exists! end + def add_project_configuration + Compass.add_project_configuration + end + def perform installer.write_configuration_files(options[:configuration_file]) end diff --git a/lib/compass/configuration/helpers.rb b/lib/compass/configuration/helpers.rb index ea8ad504..f779a973 100644 --- a/lib/compass/configuration/helpers.rb +++ b/lib/compass/configuration/helpers.rb @@ -53,6 +53,28 @@ module Compass def sass_engine_options configuration.to_sass_engine_options end + + # Read the configuration file for this project + def add_project_configuration(configuration_file_path = nil) + configuration_file_path ||= detect_configuration_file + Compass.add_configuration(configuration_file_path) if configuration_file_path + end + + # Returns a full path to the relative path to the project directory + def projectize(path, project_path = nil) + project_path ||= configuration.project_path + File.join(project_path, *path.split('/')) + end + + # TODO: Deprecate the src/config.rb location. + KNOWN_CONFIG_LOCATIONS = [".compass/config.rb", "config/compass.config", "config.rb", "src/config.rb"] + + # Finds the configuration file, if it exists in a known location. + def detect_configuration_file(project_path = nil) + possible_files = KNOWN_CONFIG_LOCATIONS.map{|f| projectize(f, project_path) } + possible_files.detect{|f| File.exists?(f)} + end + end end diff --git a/lib/compass/configuration/serialization.rb b/lib/compass/configuration/serialization.rb index 4a0e1c0d..4d8af6c0 100644 --- a/lib/compass/configuration/serialization.rb +++ b/lib/compass/configuration/serialization.rb @@ -13,6 +13,7 @@ module Compass data.parse(config_file) data end + def new_from_string(contents, filename) data = Data.new data.parse_string(contents, filename) @@ -23,6 +24,9 @@ module Compass module InstanceMethods # parses a configuration file which is a ruby script def parse(config_file) + unless File.readable?(config_file) + raise Compass::Error, "Configuration file, #{config_file}, not found or not readable." + end open(config_file) do |f| parse_string(f.read, config_file) end