Separate the project type default configuration from the installer.
This commit is contained in:
parent
ba33c5a5a6
commit
22cdcf2cb5
@ -1,3 +1,24 @@
|
||||
%w(stand_alone rails merb).each do |lib|
|
||||
require "compass/app_integration/#{lib}"
|
||||
end
|
||||
|
||||
module Compass
|
||||
module AppIntegration
|
||||
module Helpers
|
||||
def lookup(project_type)
|
||||
eval "Compass::AppIntegration::#{camelize(project_type)}"
|
||||
rescue NameError
|
||||
raise Compass::Error, "No application integration exists for #{project_type}"
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Stolen from ActiveSupport
|
||||
def camelize(s)
|
||||
s.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
||||
end
|
||||
|
||||
end
|
||||
extend Helpers
|
||||
end
|
||||
end
|
||||
|
@ -5,4 +5,22 @@ end
|
||||
require 'compass/app_integration/rails/runtime' if defined?(ActionController::Base)
|
||||
|
||||
|
||||
module Compass
|
||||
module AppIntegration
|
||||
module Rails
|
||||
|
||||
extend self
|
||||
|
||||
def installer(*args)
|
||||
Installer.new(*args)
|
||||
end
|
||||
|
||||
def configuration
|
||||
Compass::Configuration::Data.new.
|
||||
extend(ConfigurationDefaults)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,3 +1,22 @@
|
||||
%w(configuration_defaults installer).each do |lib|
|
||||
require "compass/app_integration/stand_alone/#{lib}"
|
||||
end
|
||||
end
|
||||
|
||||
module Compass
|
||||
module AppIntegration
|
||||
module StandAlone
|
||||
|
||||
extend self
|
||||
|
||||
def installer(*args)
|
||||
Installer.new(*args)
|
||||
end
|
||||
|
||||
def configuration
|
||||
Compass::Configuration::Data.new.
|
||||
extend(ConfigurationDefaults)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -6,8 +6,8 @@ module Compass
|
||||
include Compass::Installers
|
||||
|
||||
def configure!
|
||||
Compass.add_configuration(installer.default_configuration)
|
||||
Compass.add_project_configuration
|
||||
Compass.add_configuration(options[:project_type] || :stand_alone)
|
||||
Compass.add_project_configuration unless respond_to?(:is_project_creation?) && is_project_creation?
|
||||
Compass.add_configuration(options)
|
||||
Compass.add_configuration(installer.completed_configuration)
|
||||
if File.exists?(Compass.configuration.extensions_path)
|
||||
@ -15,19 +15,16 @@ module Compass
|
||||
end
|
||||
end
|
||||
|
||||
def installer
|
||||
installer_class = if options[:bare]
|
||||
"Compass::Installers::BareInstaller"
|
||||
else
|
||||
project_type = options[:project_type] || Compass.configuration.project_type
|
||||
"Compass::AppIntegration::#{camelize(project_type)}::Installer"
|
||||
end
|
||||
@installer = eval("#{installer_class}.new *installer_args")
|
||||
def app
|
||||
@app ||= Compass::AppIntegration.lookup(Compass.configuration.project_type)
|
||||
end
|
||||
|
||||
# Stolen from ActiveSupport
|
||||
def camelize(s)
|
||||
s.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
||||
def installer
|
||||
@installer ||= if options[:bare]
|
||||
Compass::Installers::BareInstaller.new(*installer_args)
|
||||
else
|
||||
app.installer(*installer_args)
|
||||
end
|
||||
end
|
||||
|
||||
def installer_args
|
||||
|
@ -51,7 +51,7 @@ module Compass
|
||||
end
|
||||
end
|
||||
else
|
||||
directory projectize(File.dirname(options[:configuration_file]))
|
||||
directory File.dirname(options[:configuration_file])
|
||||
installer.write_configuration_files(options[:configuration_file])
|
||||
end
|
||||
end
|
||||
|
@ -85,6 +85,7 @@ module Compass
|
||||
|
||||
def http_join(*segments)
|
||||
segments.map do |segment|
|
||||
next unless segment
|
||||
segment = http_pathify(segment)
|
||||
segment[-1..-1] == "/" ? segment[0..-2] : segment
|
||||
end.join("/")
|
||||
@ -104,4 +105,4 @@ module Compass
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -16,7 +16,16 @@ module Compass
|
||||
|
||||
def add_configuration(config, filename = nil)
|
||||
return if config.nil?
|
||||
data = if config.is_a?(Compass::Configuration::Data)
|
||||
|
||||
data = configuration_for(config, filename)
|
||||
|
||||
data.inherit_from!(configuration)
|
||||
data.on_top!
|
||||
@configuration = data
|
||||
end
|
||||
|
||||
def configuration_for(config, filename = nil)
|
||||
if config.is_a?(Compass::Configuration::Data)
|
||||
config
|
||||
elsif config.respond_to?(:read)
|
||||
Compass::Configuration::Data.new_from_string(config.read, filename)
|
||||
@ -24,12 +33,11 @@ module Compass
|
||||
Compass::Configuration::Data.new(config)
|
||||
elsif config.is_a?(String)
|
||||
Compass::Configuration::Data.new_from_file(config)
|
||||
elsif config.is_a?(Symbol)
|
||||
Compass::AppIntegration.lookup(config).configuration
|
||||
else
|
||||
raise "I don't know what to do with: #{config.inspect}"
|
||||
end
|
||||
data.inherit_from!(configuration)
|
||||
data.on_top!
|
||||
@configuration = data
|
||||
end
|
||||
|
||||
# Support for testing.
|
||||
@ -57,7 +65,20 @@ module Compass
|
||||
# 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
|
||||
if configuration_file_path
|
||||
|
||||
data = configuration_for(configuration_file_path)
|
||||
|
||||
if data.raw_project_type
|
||||
add_configuration(data.raw_project_type.to_sym)
|
||||
else
|
||||
add_configuration(:stand_alone)
|
||||
end
|
||||
|
||||
add_configuration(data)
|
||||
else
|
||||
add_configuration(configuration.project_type || :stand_alone)
|
||||
end
|
||||
end
|
||||
|
||||
# Returns a full path to the relative path to the project directory
|
||||
|
@ -8,6 +8,10 @@ module Compass::Exec::ProjectOptionsParser
|
||||
self.options[:configuration_file] = configuration_file
|
||||
end
|
||||
|
||||
opts.on('--app APP', 'Tell compass what kind of application it is integrating with. E.g. rails') do |project_type|
|
||||
self.options[:project_type] = project_type.to_sym
|
||||
end
|
||||
|
||||
opts.on('--sass-dir SRC_DIR', "The source directory where you keep your sass stylesheets.") do |sass_dir|
|
||||
self.options[:sass_dir] = sass_dir
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user