Class: Compass::Configuration

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/compass/configuration.rb

Constant Summary collapse

ATTRIBUTES =
[
  :project_path,
  :css_dir,
  :sass_dir,
  :images_dir,
  :javascripts_dir,
  :output_style,
  :environment
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



21
22
23
# File 'lib/compass/configuration.rb', line 21

def initialize
  self.required_libraries = []
end

Instance Attribute Details

#required_librariesObject

Returns the value of attribute required_libraries.



19
20
21
# File 'lib/compass/configuration.rb', line 19

def required_libraries
  @required_libraries
end

Instance Method Details

#default_all(options) ⇒ Object



53
54
55
56
57
# File 'lib/compass/configuration.rb', line 53

def default_all(options)
  ATTRIBUTES.each do |a|
    self.send("#{a}=", options[a]) unless self.send(a)
  end
end

#default_css_dirObject



72
73
74
# File 'lib/compass/configuration.rb', line 72

def default_css_dir
  "stylesheets"
end

#default_for(attribute) ⇒ Object



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

def default_for(attribute)
  method = "default_#{attribute}".to_sym
  self.send(method) if respond_to?(method)
end

#default_output_styleObject



76
77
78
79
80
81
82
# File 'lib/compass/configuration.rb', line 76

def default_output_style
  if environment == :development
    :expanded
  else
    :compact
  end
end

#default_sass_dirObject



68
69
70
# File 'lib/compass/configuration.rb', line 68

def default_sass_dir
  "src"
end

#parse(config_file) ⇒ Object

parses a manifest file which is a ruby script evaluated in a Manifest instance context



27
28
29
30
31
# File 'lib/compass/configuration.rb', line 27

def parse(config_file)
  open(config_file) do |f|
    parse_string(f.read, config_file)
  end
end

#parse_string(contents, filename) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/compass/configuration.rb', line 33

def parse_string(contents, filename)
  eval(contents, binding, filename)
  ATTRIBUTES.each do |prop|
    value = eval(prop.to_s, binding) rescue nil
    self.send("#{prop}=", value) if value
  end
end

#require(lib) ⇒ Object



137
138
139
140
# File 'lib/compass/configuration.rb', line 137

def require(lib)
  required_libraries << lib
  super
end

#reset!Object

Support for testing.



130
131
132
133
134
135
# File 'lib/compass/configuration.rb', line 130

def reset!
  ATTRIBUTES.each do |attr|
    send("#{attr}=", nil)
  end
  self.required_libraries = []
end

#serializeObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/compass/configuration.rb', line 84

def serialize
  contents = ""
  required_libraries.each do |lib|
    contents << %Q{require '#{lib}'\n}
  end
  contents << "# Require any additional compass plugins here.\n"
  contents << "\n" if required_libraries.any?
  ATTRIBUTES.each do |prop|
    value = send(prop)
    unless value.nil?
      contents << %Q(#{prop} = #{value.inspect}\n)
    end
  end
  contents
end

#set_all(options) ⇒ Object



41
42
43
44
45
# File 'lib/compass/configuration.rb', line 41

def set_all(options)
  ATTRIBUTES.each do |a|
    self.send("#{a}=", options[a]) if options.has_key?(a)
  end
end

#set_defaults!Object



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

def set_defaults!
  default_all(ATTRIBUTES.inject({}){|m, a| m[a] = default_for(a); m})
end

#set_maybe(options) ⇒ Object



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

def set_maybe(options)
  ATTRIBUTES.each do |a|
    self.send("#{a}=", options[a]) if options[a]
  end
end

#to_sass_engine_optionsObject



116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/compass/configuration.rb', line 116

def to_sass_engine_options
  load_paths = []
  if project_path && sass_dir
    load_paths << File.join(project_path, sass_dir)
  end
  Compass::Frameworks::ALL.each do |framework|
    load_paths << framework.stylesheets_directory
  end
  engine_opts = {:load_paths => load_paths}
  engine_opts[:style] = output_style if output_style
  engine_opts
end

#to_sass_plugin_optionsObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/compass/configuration.rb', line 100

def to_sass_plugin_options
  if project_path && sass_dir && css_dir
    proj_sass_path = File.join(project_path, sass_dir)
    proj_css_path = File.join(project_path, css_dir)
    locations = {proj_sass_path => proj_css_path}
  else
    locations = {}
  end
  Compass::Frameworks::ALL.each do |framework|
    locations[framework.stylesheets_directory] = proj_css_path || css_dir || "."
  end
  plugin_opts = {:template_location => locations}
  plugin_opts[:style] = output_style if output_style
  plugin_opts
end