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|
|
%w(stand_alone rails merb).each do |lib|
|
||||||
require "compass/app_integration/#{lib}"
|
require "compass/app_integration/#{lib}"
|
||||||
end
|
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)
|
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|
|
%w(configuration_defaults installer).each do |lib|
|
||||||
require "compass/app_integration/stand_alone/#{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
|
include Compass::Installers
|
||||||
|
|
||||||
def configure!
|
def configure!
|
||||||
Compass.add_configuration(installer.default_configuration)
|
Compass.add_configuration(options[:project_type] || :stand_alone)
|
||||||
Compass.add_project_configuration
|
Compass.add_project_configuration unless respond_to?(:is_project_creation?) && is_project_creation?
|
||||||
Compass.add_configuration(options)
|
Compass.add_configuration(options)
|
||||||
Compass.add_configuration(installer.completed_configuration)
|
Compass.add_configuration(installer.completed_configuration)
|
||||||
if File.exists?(Compass.configuration.extensions_path)
|
if File.exists?(Compass.configuration.extensions_path)
|
||||||
@ -15,19 +15,16 @@ module Compass
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def installer
|
def app
|
||||||
installer_class = if options[:bare]
|
@app ||= Compass::AppIntegration.lookup(Compass.configuration.project_type)
|
||||||
"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")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Stolen from ActiveSupport
|
def installer
|
||||||
def camelize(s)
|
@installer ||= if options[:bare]
|
||||||
s.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
Compass::Installers::BareInstaller.new(*installer_args)
|
||||||
|
else
|
||||||
|
app.installer(*installer_args)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def installer_args
|
def installer_args
|
||||||
|
@ -51,7 +51,7 @@ module Compass
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
directory projectize(File.dirname(options[:configuration_file]))
|
directory File.dirname(options[:configuration_file])
|
||||||
installer.write_configuration_files(options[:configuration_file])
|
installer.write_configuration_files(options[:configuration_file])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -85,6 +85,7 @@ module Compass
|
|||||||
|
|
||||||
def http_join(*segments)
|
def http_join(*segments)
|
||||||
segments.map do |segment|
|
segments.map do |segment|
|
||||||
|
next unless segment
|
||||||
segment = http_pathify(segment)
|
segment = http_pathify(segment)
|
||||||
segment[-1..-1] == "/" ? segment[0..-2] : segment
|
segment[-1..-1] == "/" ? segment[0..-2] : segment
|
||||||
end.join("/")
|
end.join("/")
|
||||||
@ -104,4 +105,4 @@ module Compass
|
|||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -16,7 +16,16 @@ module Compass
|
|||||||
|
|
||||||
def add_configuration(config, filename = nil)
|
def add_configuration(config, filename = nil)
|
||||||
return if config.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
|
config
|
||||||
elsif config.respond_to?(:read)
|
elsif config.respond_to?(:read)
|
||||||
Compass::Configuration::Data.new_from_string(config.read, filename)
|
Compass::Configuration::Data.new_from_string(config.read, filename)
|
||||||
@ -24,12 +33,11 @@ module Compass
|
|||||||
Compass::Configuration::Data.new(config)
|
Compass::Configuration::Data.new(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)
|
||||||
|
elsif config.is_a?(Symbol)
|
||||||
|
Compass::AppIntegration.lookup(config).configuration
|
||||||
else
|
else
|
||||||
raise "I don't know what to do with: #{config.inspect}"
|
raise "I don't know what to do with: #{config.inspect}"
|
||||||
end
|
end
|
||||||
data.inherit_from!(configuration)
|
|
||||||
data.on_top!
|
|
||||||
@configuration = data
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Support for testing.
|
# Support for testing.
|
||||||
@ -57,7 +65,20 @@ module Compass
|
|||||||
# Read the configuration file for this project
|
# Read the configuration file for this project
|
||||||
def add_project_configuration(configuration_file_path = nil)
|
def add_project_configuration(configuration_file_path = nil)
|
||||||
configuration_file_path ||= detect_configuration_file
|
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
|
end
|
||||||
|
|
||||||
# Returns a full path to the relative path to the project directory
|
# 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
|
self.options[:configuration_file] = configuration_file
|
||||||
end
|
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|
|
opts.on('--sass-dir SRC_DIR', "The source directory where you keep your sass stylesheets.") do |sass_dir|
|
||||||
self.options[:sass_dir] = sass_dir
|
self.options[:sass_dir] = sass_dir
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user