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

Instance Method Details

#add_configuration(config, filename = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/compass/configuration/helpers.rb', line 17

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

Raises:

  • (ArgumentError)


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/compass/configuration/helpers.rb', line 69

def add_project_configuration(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  configuration_file_path = args.shift || detect_configuration_file
  raise ArgumentError, "Too many arguments" if args.any?
  if configuration_file_path

    data = configuration_for(configuration_file_path)

    if data.raw_project_type
      add_configuration(data.raw_project_type.to_sym)
    elsif options[:project_type]
      add_configuration(options[:project_type])
    else
      add_configuration(:stand_alone)
    end

    add_configuration(data)
  else
    add_configuration(options[:project_type] || configuration.project_type || :stand_alone)
  end
end

#configurationObject



5
6
7
8
9
10
11
# File 'lib/compass/configuration/helpers.rb', line 5

def configuration
  @configuration ||= default_configuration
  if block_given?
    yield @configuration
  end
  @configuration
end

#configuration_for(config, filename = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/compass/configuration/helpers.rb', line 30

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)
  elsif config.is_a?(Hash)
    Compass::Configuration::Data.new(filename, 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
end

#configure_sass_plugin!Object



55
56
57
58
# File 'lib/compass/configuration/helpers.rb', line 55

def configure_sass_plugin!
  @sass_plugin_configured = true
  Sass::Plugin.options.merge!(sass_plugin_configuration)
end

#default_configurationObject



13
14
15
# File 'lib/compass/configuration/helpers.rb', line 13

def default_configuration
  Data.new('defaults').extend(Defaults).extend(Comments)
end

#deprojectize(path, project_path = nil) ⇒ Object



97
98
99
100
101
102
103
104
# File 'lib/compass/configuration/helpers.rb', line 97

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.



110
111
112
113
# File 'lib/compass/configuration/helpers.rb', line 110

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

#projectize(path, project_path = nil) ⇒ Object

Returns a full path to the relative path to the project directory



92
93
94
95
# File 'lib/compass/configuration/helpers.rb', line 92

def projectize(path, project_path = nil)
  project_path ||= configuration.project_path
  File.join(project_path, *path.split('/'))
end

#reset_configuration!Object

Support for testing.



47
48
49
# File 'lib/compass/configuration/helpers.rb', line 47

def reset_configuration!
  @configuration = nil
end

#sass_engine_optionsObject



64
65
66
# File 'lib/compass/configuration/helpers.rb', line 64

def sass_engine_options
  configuration.to_sass_engine_options
end

#sass_plugin_configurationObject



51
52
53
# File 'lib/compass/configuration/helpers.rb', line 51

def sass_plugin_configuration
  configuration.to_sass_plugin_options
end

#sass_plugin_configured?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/compass/configuration/helpers.rb', line 60

def sass_plugin_configured?
  @sass_plugin_configured
end