f59ca512ce
configuration. Configuration is now a singly linked list of configuration objects that inherit values and defaults from the next configuration instance. All instances hold a reference to the top of the configuration chain. There is now a consistent API for reading configuration property values: <attr>: Reads the fully-resolved attribute after taking configuration inheritance and defaults into account. raw_<attr>: reads attribute from a configuration object without inheritance or defaults. default_for(<attr>): reads the default value for an attribute default_for_<attr>: specifies the default value for an attribute. <attr>_without_default: reads the inherited attribute without applying defaults. comment_for_<attr>: Specifies a comment that will be emitted above the property when serializing the configuration to a file. Additionally, method_missing and respond_to both work down the configuration chain, so any method that is added to a configuration instance, can be accessed from the top level. The distinction between default and explicitly set values allows compass to more correctly manage the serialization of attributes when creating configuration files for projects. The compass configuration can still be accessed via Compass.configuration, however, the configuration object is no longer a singleton. This means that you can build several configuration chains to track several projects at once. This should ease the use of compass in other frameworks and plugins that want to use compass internally.
60 lines
2.0 KiB
Ruby
60 lines
2.0 KiB
Ruby
module Compass
|
|
module Configuration
|
|
# The adapters module provides methods that make configuration data from a compass project
|
|
# adapt to various consumers of configuration data
|
|
module Adapters
|
|
def to_compiler_arguments(additional_options)
|
|
[project_path, sass_path, css_path, to_sass_engine_options.merge(additional_options)]
|
|
end
|
|
|
|
def to_sass_plugin_options
|
|
locations = {}
|
|
locations[sass_path] = css_path if sass_path && css_path
|
|
Compass::Frameworks::ALL.each do |framework|
|
|
locations[framework.stylesheets_directory] = css_path || css_dir || "."
|
|
end
|
|
resolve_additional_import_paths.each do |additional_path|
|
|
locations[additional_path] = File.join(css_path || css_dir || ".", File.basename(additional_path))
|
|
end
|
|
plugin_opts = {:template_location => locations}
|
|
plugin_opts[:style] = output_style if output_style
|
|
plugin_opts[:line_comments] = line_comments if environment
|
|
plugin_opts.merge!(sass_options || {})
|
|
plugin_opts
|
|
end
|
|
|
|
def resolve_additional_import_paths
|
|
(additional_import_paths || []).map do |path|
|
|
if project_path && !absolute_path?(path)
|
|
File.join(project_path, path)
|
|
else
|
|
path
|
|
end
|
|
end
|
|
end
|
|
|
|
def absolute_path?(path)
|
|
# This is only going to work on unix, gonna need a better implementation.
|
|
path.index(File::SEPARATOR) == 0
|
|
end
|
|
|
|
def to_sass_engine_options
|
|
engine_opts = {:load_paths => sass_load_paths}
|
|
engine_opts[:style] = output_style if output_style
|
|
engine_opts[:line_comments] = line_comments if environment
|
|
engine_opts.merge!(sass_options || {})
|
|
end
|
|
|
|
def sass_load_paths
|
|
load_paths = []
|
|
load_paths << sass_path if sass_path
|
|
Compass::Frameworks::ALL.each do |framework|
|
|
load_paths << framework.stylesheets_directory
|
|
end
|
|
load_paths += resolve_additional_import_paths
|
|
load_paths
|
|
end
|
|
end
|
|
end
|
|
end
|