Class: Compass::Configuration
- Inherits:
-
Object
- Object
- Compass::Configuration
- Includes:
- Singleton
- Defined in:
- lib/compass/configuration.rb
Constant Summary collapse
- ATTRIBUTES =
[ :project_type, :project_path, :http_path, :css_dir, :sass_dir, :images_dir, :javascripts_dir, :output_style, :environment, :relative_assets, :http_images_path, :http_stylesheets_path, :http_javascripts_path, :additional_import_paths, :sass_options ]
Instance Attribute Summary collapse
-
#required_libraries ⇒ Object
Returns the value of attribute required_libraries.
Class Method Summary collapse
Instance Method Summary collapse
- #absolute_path?(path) ⇒ Boolean
- #add_import_path(*paths) ⇒ Object
-
#asset_cache_buster(&block) ⇒ Object
When called with a block, defines the cache buster strategy to be used.
-
#asset_host(&block) ⇒ Object
When called with a block, defines the asset host url to be used.
- #comment_for_http_path ⇒ Object
- #comment_for_relative_assets ⇒ Object
- #css_path ⇒ Object
- #default_all(options) ⇒ Object
- #default_css_dir ⇒ Object
- #default_for(attribute) ⇒ Object
- #default_http_path ⇒ Object
- #default_images_dir ⇒ Object
- #default_line_comments ⇒ Object
- #default_output_style ⇒ Object
- #default_sass_dir ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #issue_deprecation_warnings ⇒ Object
-
#parse(config_file) ⇒ Object
parses a manifest file which is a ruby script evaluated in a Manifest instance context.
- #parse_string(contents, filename) ⇒ Object
- #relative_assets? ⇒ Boolean
- #require(lib) ⇒ Object
-
#reset! ⇒ Object
Support for testing.
- #resolve_additional_import_paths ⇒ Object
- #root_relative(path) ⇒ Object
- #sass_load_paths ⇒ Object
- #sass_path ⇒ Object
- #serialize ⇒ Object
- #set_all(options) ⇒ Object
- #set_default_unless_set(attribute, value) ⇒ Object
- #set_defaults! ⇒ Object
- #set_maybe(options) ⇒ Object
- #to_compiler_arguments(additional_options) ⇒ Object
- #to_sass_engine_options ⇒ Object
- #to_sass_plugin_options ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
29 30 31 |
# File 'lib/compass/configuration.rb', line 29 def initialize self.required_libraries = [] end |
Instance Attribute Details
#required_libraries ⇒ Object
Returns the value of attribute required_libraries.
27 28 29 |
# File 'lib/compass/configuration.rb', line 27 def required_libraries @required_libraries end |
Class Method Details
.serialize_property(prop, value) ⇒ Object
217 218 219 |
# File 'lib/compass/configuration.rb', line 217 def self.serialize_property(prop, value) %Q(#{prop} = #{value.inspect}\n) end |
Instance Method Details
#absolute_path?(path) ⇒ Boolean
290 291 292 293 |
# File 'lib/compass/configuration.rb', line 290 def absolute_path?(path) # This is only going to work on unix, gonna need a better implementation. path.index(File::SEPARATOR) == 0 end |
#add_import_path(*paths) ⇒ Object
153 154 155 156 157 158 159 160 |
# File 'lib/compass/configuration.rb', line 153 def add_import_path(*paths) # The @added_import_paths variable works around an issue where # the additional_import_paths gets overwritten during parse @added_import_paths ||= [] @added_import_paths += paths self.additional_import_paths ||= [] self.additional_import_paths += paths end |
#asset_cache_buster(&block) ⇒ Object
When called with a block, defines the cache buster strategy to be used. The block must return nil or a string that can be appended to a url as a query parameter. The returned string must not include the starting ‘?’. The block will be passed the root-relative url of the asset. If the block accepts two arguments, it will also be passed a File object that points to the asset on disk – which may or may not exist. When called without a block, returns the block that was previously set.
181 182 183 184 185 186 187 |
# File 'lib/compass/configuration.rb', line 181 def asset_cache_buster(&block) if block_given? @asset_cache_buster = block else @asset_cache_buster end end |
#asset_host(&block) ⇒ Object
When called with a block, defines the asset host url to be used. The block must return a string that starts with a protocol (E.g. http). The block will be passed the root-relative url of the asset. When called without a block, returns the block that was previously set.
166 167 168 169 170 171 172 |
# File 'lib/compass/configuration.rb', line 166 def asset_host(&block) if block_given? @asset_host = block else @asset_host end end |
#comment_for_http_path ⇒ Object
104 105 106 |
# File 'lib/compass/configuration.rb', line 104 def comment_for_http_path "# Set this to the root of your project when deployed:\n" end |
#comment_for_relative_assets ⇒ Object
113 114 115 116 117 118 119 120 121 |
# File 'lib/compass/configuration.rb', line 113 def comment_for_relative_assets unless relative_assets %q{# To enable relative paths to assets via compass helper functions. Uncomment: # relative_assets = true } else "" end end |
#css_path ⇒ Object
141 142 143 144 145 |
# File 'lib/compass/configuration.rb', line 141 def css_path if project_path && css_dir File.join(project_path, css_dir) end end |
#default_all(options) ⇒ Object
67 68 69 70 71 |
# File 'lib/compass/configuration.rb', line 67 def default_all() ATTRIBUTES.each do |a| set_default_unless_set(a, [a]) end end |
#default_css_dir ⇒ Object
92 93 94 |
# File 'lib/compass/configuration.rb', line 92 def default_css_dir "stylesheets" end |
#default_for(attribute) ⇒ Object
83 84 85 86 |
# File 'lib/compass/configuration.rb', line 83 def default_for(attribute) method = "default_#{attribute}".to_sym self.send(method) if respond_to?(method) end |
#default_http_path ⇒ Object
100 101 102 |
# File 'lib/compass/configuration.rb', line 100 def default_http_path "/" end |
#default_images_dir ⇒ Object
96 97 98 |
# File 'lib/compass/configuration.rb', line 96 def default_images_dir "images" end |
#default_line_comments ⇒ Object
131 132 133 |
# File 'lib/compass/configuration.rb', line 131 def default_line_comments environment == :development end |
#default_output_style ⇒ Object
123 124 125 126 127 128 129 |
# File 'lib/compass/configuration.rb', line 123 def default_output_style if environment == :development :expanded else :compact end end |
#default_sass_dir ⇒ Object
88 89 90 |
# File 'lib/compass/configuration.rb', line 88 def default_sass_dir "src" end |
#issue_deprecation_warnings ⇒ Object
279 280 281 282 283 |
# File 'lib/compass/configuration.rb', line 279 def issue_deprecation_warnings if http_images_path == :relative puts "DEPRECATION WARNING: Please set relative_assets = true to enable relative paths." end end |
#parse(config_file) ⇒ Object
parses a manifest file which is a ruby script evaluated in a Manifest instance context
35 36 37 38 39 |
# File 'lib/compass/configuration.rb', line 35 def parse(config_file) open(config_file) do |f| parse_string(f.read, config_file) end end |
#parse_string(contents, filename) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/compass/configuration.rb', line 41 def parse_string(contents, filename) bind = binding eval(contents, bind, filename) ATTRIBUTES.each do |prop| value = eval(prop.to_s, bind) rescue nil self.send("#{prop}=", value) if value end if @added_import_paths self.additional_import_paths ||= [] self.additional_import_paths += @added_import_paths end issue_deprecation_warnings end |
#relative_assets? ⇒ Boolean
108 109 110 111 |
# File 'lib/compass/configuration.rb', line 108 def relative_assets? # the http_images_path is deprecated, but here for backwards compatibility. relative_assets || http_images_path == :relative end |
#require(lib) ⇒ Object
285 286 287 288 |
# File 'lib/compass/configuration.rb', line 285 def require(lib) required_libraries << lib super end |
#reset! ⇒ Object
Support for testing.
269 270 271 272 273 274 275 276 277 |
# File 'lib/compass/configuration.rb', line 269 def reset! ATTRIBUTES.each do |attr| send("#{attr}=", nil) end @asset_cache_buster = nil @asset_host = nil @added_import_paths = nil self.required_libraries = [] end |
#resolve_additional_import_paths ⇒ Object
241 242 243 244 245 246 247 248 249 |
# File 'lib/compass/configuration.rb', line 241 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 |
#root_relative(path) ⇒ Object
147 148 149 150 151 |
# File 'lib/compass/configuration.rb', line 147 def root_relative(path) hp = http_path || default_http_path hp = hp[0..-2] if hp[-1..-1] == "/" "#{hp}/#{path}" end |
#sass_load_paths ⇒ Object
258 259 260 261 262 263 264 265 266 |
# File 'lib/compass/configuration.rb', line 258 def sass_load_paths load_paths = [] load_paths << sass_path if sass_path Compass::Frameworks::ALL.each do |framework| load_paths << framework.stylesheets_directory if File.exists?(framework.stylesheets_directory) end load_paths += resolve_additional_import_paths load_paths end |
#sass_path ⇒ Object
135 136 137 138 139 |
# File 'lib/compass/configuration.rb', line 135 def sass_path if project_path && sass_dir File.join(project_path, sass_dir) end end |
#serialize ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/compass/configuration.rb', line 190 def serialize if asset_cache_buster raise Compass::Error, "Cannot serialize a configuration with asset_cache_buster set." end if asset_host raise Compass::Error, "Cannot serialize a configuration with asset_host set." end 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) if respond_to?("comment_for_#{prop}") contents << send("comment_for_#{prop}") end if block_given? && (to_emit = yield(prop, value)) contents << to_emit else contents << Configuration.serialize_property(prop, value) unless value.nil? end end contents end |
#set_all(options) ⇒ Object
55 56 57 58 59 |
# File 'lib/compass/configuration.rb', line 55 def set_all() ATTRIBUTES.each do |a| self.send("#{a}=", [a]) if .has_key?(a) end end |
#set_default_unless_set(attribute, value) ⇒ Object
73 74 75 |
# File 'lib/compass/configuration.rb', line 73 def set_default_unless_set(attribute, value) self.send("#{attribute}=", value) unless self.send(attribute) end |
#set_defaults! ⇒ Object
77 78 79 80 81 |
# File 'lib/compass/configuration.rb', line 77 def set_defaults! ATTRIBUTES.each do |a| set_default_unless_set(a, default_for(a)) end end |
#set_maybe(options) ⇒ Object
61 62 63 64 65 |
# File 'lib/compass/configuration.rb', line 61 def set_maybe() ATTRIBUTES.each do |a| self.send("#{a}=", [a]) if [a] end end |
#to_compiler_arguments(additional_options) ⇒ Object
221 222 223 |
# File 'lib/compass/configuration.rb', line 221 def to_compiler_arguments() [project_path, sass_path, css_path, .merge()] end |
#to_sass_engine_options ⇒ Object
251 252 253 254 255 256 |
# File 'lib/compass/configuration.rb', line 251 def engine_opts = {:load_paths => sass_load_paths} engine_opts[:style] = output_style if output_style engine_opts[:line_comments] = default_line_comments if environment engine_opts.merge!( || {}) end |
#to_sass_plugin_options ⇒ Object
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/compass/configuration.rb', line 225 def 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] = default_line_comments if environment plugin_opts.merge!( || {}) plugin_opts end |