Module: Compass::Configuration::Helpers
- Included in:
- Compass
- Defined in:
- lib/compass/configuration/helpers.rb
Overview
The helpers are available as methods on the Compass module. E.g. Compass.configuration
Constant Summary collapse
- KNOWN_CONFIG_LOCATIONS =
TODO: Deprecate the src/config.rb location.
['config/compass.rb', ".compass/config.rb", "config/compass.config", "config.rb", "src/config.rb"]
Instance Method Summary collapse
- #add_configuration(config, filename = nil) ⇒ Object
-
#add_project_configuration(*args) ⇒ Object
Read the configuration file for this project.
- #compiler ⇒ Object
- #configuration ⇒ Object
- #configuration_for(config, filename = nil, defaults = nil) ⇒ Object
- #configure_sass_plugin! ⇒ Object
- #default_configuration ⇒ Object
- #deprojectize(path, project_path = nil) ⇒ Object
-
#detect_configuration_file(project_path = nil) ⇒ Object
Finds the configuration file, if it exists in a known location.
- #discover_extensions! ⇒ Object
- #handle_configuration_change! ⇒ Object
-
#projectize(path, project_path = nil) ⇒ Object
Returns a full path to the relative path to the project directory.
-
#reset_configuration! ⇒ Object
Support for testing.
- #sass_engine_options ⇒ Object
- #sass_plugin_configuration ⇒ Object
Instance Method Details
#add_configuration(config, filename = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/compass/configuration/helpers.rb', line 18 def add_configuration(config, filename = nil) return if config.nil? data = configuration_for(config, filename) # puts "New configuration: #{data.name}" # puts caller.join("\n") data.inherit_from!(configuration) data.on_top! @configuration = data end |
#add_project_configuration(*args) ⇒ Object
Read the configuration file for this project
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/compass/configuration/helpers.rb', line 92 def add_project_configuration(*args) = args.last.is_a?(Hash) ? args.pop : {} configuration_file_path = args.shift || detect_configuration_file raise ArgumentError, "Too many arguments" if args.any? if AppIntegration.default? && data = configuration_for(configuration_file_path, nil, configuration_for([:defaults])) if data.raw_project_type add_configuration(data.raw_project_type.to_sym) elsif [:project_type] add_configuration([:project_type]) else add_configuration(:stand_alone) end add_configuration(data) else add_configuration([:project_type] || configuration.project_type_without_default || (yield if block_given?) || :stand_alone) end end |
#compiler ⇒ Object
152 153 154 |
# File 'lib/compass/configuration/helpers.rb', line 152 def compiler Compass::Compiler.new(*Compass.configuration.to_compiler_arguments) end |
#configuration ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/compass/configuration/helpers.rb', line 6 def configuration @configuration ||= default_configuration if block_given? yield @configuration end @configuration end |
#configuration_for(config, filename = nil, defaults = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/compass/configuration/helpers.rb', line 31 def configuration_for(config, filename = nil, defaults = nil) if config.nil? nil elsif config.is_a?(Compass::Configuration::Data) config elsif config.respond_to?(:read) filename ||= config.to_s if config.is_a?(Pathname) Compass::Configuration::FileData.new_from_string(config.read, filename, defaults) elsif config.is_a?(Hash) Compass::Configuration::Data.new(filename, config) elsif config.is_a?(String) Compass::Configuration::FileData.new_from_file(config, defaults) elsif config.is_a?(Symbol) Compass::AppIntegration.lookup(config).configuration else raise "I don't know what to do with: #{config.inspect}" end end |
#configure_sass_plugin! ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/compass/configuration/helpers.rb', line 59 def configure_sass_plugin! require 'sass/plugin' config = sass_plugin_configuration locations = config.delete(:template_location) Sass::Plugin..merge!(config) locations.each do |sass_dir, css_dir| unless Sass::Plugin.[:load_paths].include?(sass_dir) Sass::Plugin.add_template_location sass_dir, css_dir end end unless @callbacks_loaded on_saved = Proc.new do |sass_file, css_file| Compass.configuration.run_stylesheet_saved(css_file) end if Sass::Plugin.respond_to?(:on_updated_stylesheet) Sass::Plugin.on_updated_stylesheet(&on_saved) else Sass::Plugin.on_updating_stylesheet(&on_saved) end Sass::Plugin.on_compilation_error do |e, filename, css| Compass.configuration.run_stylesheet_error(filename, e.) end @callbacks_loaded = true end end |
#default_configuration ⇒ Object
14 15 16 |
# File 'lib/compass/configuration/helpers.rb', line 14 def default_configuration Data.new('defaults').extend(Defaults).extend(Comments) end |
#deprojectize(path, project_path = nil) ⇒ Object
128 129 130 131 132 133 134 135 |
# File 'lib/compass/configuration/helpers.rb', line 128 def deprojectize(path, project_path = nil) project_path ||= configuration.project_path if path[0..(project_path.size - 1)] == project_path path[(project_path.size + 1)..-1] else path end end |
#detect_configuration_file(project_path = nil) ⇒ Object
Finds the configuration file, if it exists in a known location.
141 142 143 144 |
# File 'lib/compass/configuration/helpers.rb', line 141 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 |
#discover_extensions! ⇒ Object
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/compass/configuration/helpers.rb', line 111 def discover_extensions! Compass.shared_extension_paths.each do |extensions_path| if File.directory?(extensions_path) Compass::Frameworks.discover(extensions_path) end end if File.directory?(configuration.extensions_path) Compass::Frameworks.discover(configuration.extensions_path) end end |
#handle_configuration_change! ⇒ Object
146 147 148 149 150 |
# File 'lib/compass/configuration/helpers.rb', line 146 def handle_configuration_change! if (compiler = Compass.compiler).new_config? compiler.clean! end end |
#projectize(path, project_path = nil) ⇒ Object
Returns a full path to the relative path to the project directory
123 124 125 126 |
# File 'lib/compass/configuration/helpers.rb', line 123 def projectize(path, project_path = nil) project_path ||= configuration.project_path File.join(project_path, *path.split('/')) end |
#reset_configuration! ⇒ Object
Support for testing.
51 52 53 |
# File 'lib/compass/configuration/helpers.rb', line 51 def reset_configuration! @configuration = nil end |
#sass_engine_options ⇒ Object
87 88 89 |
# File 'lib/compass/configuration/helpers.rb', line 87 def configuration. end |
#sass_plugin_configuration ⇒ Object
55 56 57 |
# File 'lib/compass/configuration/helpers.rb', line 55 def sass_plugin_configuration configuration. end |