Q
Version: 0.13.alpha.0

Configuration Reference

The compass configuration file is a ruby file, which means that we can do some clever things if we want to. But don’t let it frighten you; it’s really quite easy to set up your project.

Basic format

Most configuration properties are a simple assignment to a configuration property. For example:

css_dir = "stylesheets"

Most configuration properties have a value that is a “basic” type. There are three basic types that can be set to a property:

  • String – Text is surrounded by either single or double quotes. E.g. "this is a string"
  • Symbol – A symbol starts with a colon and has no spaces in it. Symbols are used to represent values where the set of possible values are limited. E.g. :foo or :foo_bar_baz
  • Booleantrue or false

There are two kinds of composite values:

  • Array – An Array is a comma delimited list of basic values surrounded by square brackets. E.g. ["one", "two", "three"].
  • Hash – A Hash is an association or mapping of one value to another. It is a comma delimited list of associations surrounded by curly brackets. An association is two values separated by =>. E.g. {:foo => "aaa", :bar => "zzz"}

Comments

Use the hash sign # to comment out everything from the hash sign to the end of the line.

Import Note for Windows Users

The backslash character (\) is a special character in a string delimited by double quotes ("). If you are working with folders in your paths, you should either use single quotes to delimit your strings or escape your backslash by doubling it like "some\\path".

Loading Compass Plugins

Compass relies on the ruby require mechanism to load other libraries of code. To load a compass-compatible plugin, simply require it at the top of your configuration file. If you used the -r option to access another library at project creation time, this will already be set up for you.

Example:

require 'ninesixty'
require 'susy'

Overriding Configuration Settings

When using the compass command line, configuration options that you set on the command line will override the corresponding settings in your configuration file.

Inspecting Configuration Settings passed via the Command Line

When using the compass command line, configuration options that you set on the command line can be inspected within the configuration file. For instance, if you set the environment:

$ compass compile -e production --force

Then you can inspect the value like so:

output_style = (environment == :production) ? :compressed : :expanded

Values that are not set on the CLI will be nil even though they will have a default value later on.

Configuration Properties

Property Name Type Description
project_type Symbol Can be :stand_alone or :rails. Defaults to :stand_alone.
environment Symbol The environment mode. Defaults to :production, can also be :development
project_path String Not needed in :stand_alone mode where it can be inferred by context. Sets the path to the root of the project.
http_path String The path to the project when running within the web server. Defaults to "/".
css_dir String The directory where the css stylesheets are kept. It is relative to the project_path. Defaults to "stylesheets".
css_path String The full path to where css stylesheets are kept. Defaults to <project_path>/<css_dir>.
http_stylesheets_path String The full http path to stylesheets on the web server. Defaults to http_path + "/" + css_dir.
sass_dir String The directory where the sass stylesheets are kept. It is relative to the project_path. Defaults to "sass".
sass_path String The full path to where sass stylesheets are kept. Defaults to <project_path>/<sass_dir>.
images_dir String The directory where the images are kept. It is relative to the project_path. Defaults to "images".
images_path String The full path to where images are kept. Defaults to <project_path>/<images_dir>.
http_images_path String The full http path to images on the web server. Defaults to http_path + "/" + images_dir.
generated_images_dir String The directory where generated images are kept. It is relative to the project_path. Defaults to the value of images_dir.
generated_images_path String The full path to where generated images are kept. Defaults to the value of <project_path>/<generated_images_dir>.
http_generated_images_path String The full http path to generated images on the web server. Defaults to http_path + "/" + generated_images_dir.
javascripts_dir String The directory where the javascripts are kept. It is relative to the project_path. Defaults to "javascripts".
javascripts_path String The full path to where javascripts are kept. Defaults to <project_path>/<javascripts_dir>.
http_javascripts_path String The full http path to javascripts on the web server. Defaults to http_path + "/" + javascripts_dir.
output_style Symbol The output style for the compiled css. One of: :nested, :expanded, :compact, or :compressed.
relative_assets Boolean Indicates whether the compass helper functions should generate relative urls from the generated css to assets, or absolute urls using the http path for that asset type.
additional_import_paths Array of Strings Other paths on your system from which to import sass files. See the add_import_path function for a simpler approach.
disable_warnings Boolean Set this to true to silence deprecation warnings.
sass_options Hash These options are passed directly to the Sass compiler. For more details on the format of sass options, please read the sass options documentation.
line_comments Boolean Indicates whether line comments should be added to compiled css that says where the selectors were defined. Defaults to false in production mode, true in development mode.
preferred_syntax Symbol Can be :scss or :sass. Defaults to :scss.
fonts_dir String The directory where the font files are kept. Standalone projects will default to <css_dir>/fonts. Rails projects will default to "public/fonts".
fonts_path String The full path to where font files are kept. Defaults to <project_path>/<fonts_dir>.
http_fonts_path String The full http path to font files on the web server.
http_fonts_dir String The relative http path to font files on the web server.
sprite_engine Symbol Defaults to :chunky_png
chunky_png_options Hash Defaults to {:compression => Zlib::BEST_COMPRESSION}. See the chunky_png wiki for more information
sprite_load_path Array Defaults to [images_path]

Configuration Functions

add_import_path – Call this function to add a path to the list of sass import paths for your compass project. E.g.:

add_import_path "/Users/chris/work/shared_sass"

asset_host – Pass this function a block of code that will define 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. For example, this picks one of four asset hosts numbered 0-3, depending on the name of the asset:

asset_host do |asset|
  "http://assets%d.example.com" % (asset.hash % 4)
end

By default there is no asset host used. When relative_assets is true the asset host configuration is ignored.


asset_cache_buster – Pass this function a block of code that defines the cache buster strategy to be used. The block must return nil, a string or a hash. If the returned value is a hash the values of :path and/or :query is used to generate a cache busted path to the asset. If a string value is returned, it is added as a query string. The returned values for query strings 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 path that points to the asset on disk — which may or may not exist.

# Increment the deploy_version before every release to force cache busting.
deploy_version = 1
asset_cache_buster do |http_path, real_path|
  if File.exists?(real_path)
    File.mtime(real_path).strftime("%s")
  else
    "v=#{deploy_version}"
  end
end

Busting the cache via path:

asset_cache_buster do |path, real_path|
  if File.exists?(real_path)
    pathname = Pathname.new(path)
    modified_time = File.mtime(real_path).strftime("%s")
    new_path = "%s/%s-%s%s" % [pathname.dirname, pathname.basename(pathname.extname), modified_time, pathname.extname]

    {:path => new_path, :query => nil}
  end
end

To disable the asset cache buster:

asset_cache_buster :none

watch -- React to changes to arbitrary files within your project. Can be invoked more than once. Example:

watch "images/**/*" do |project_dir, relative_path|
  if File.exists?(File.join(project_dir, relative_path))
    puts "File size of #{relative_path} is: #{File.size(File.join(project_dir, relative_path))}"
  end
end

This code will be called if the file is added, updated, or removed. Be sure to check for existence to avoid crashing the watcher in the case where the file has been removed.

Callbacks

on_sprite_saved -- Pass this function a block of code that gets executed after a sprite is saved to disk. The block will be passed the filename. Can be invoked more then once. Example:

on_sprite_saved do |filename|
  post_process(filename) if File.exists?(filename)
end

on_sprite_generated -- Pass this function a block of code that gets executed after a sprite is generated but before its saved to disk. The block will be passed an instance of ChunkyPNG::Image. Can be invoked more then once. Example:

on_sprite_generated do |sprite_data|
  sprite_data.metadata['Caption'] = "This Image is &copy; My Company 2011"
end

on_stylesheet_saved -- Pass this function a block of code that gets executed after a stylesheet is processed. The block will be passed the filename. Can be invoked more then once. Example:

on_stylesheet_saved do |filename|
  Growl.notify {
     self.message = "#{File.basename(filename)} updated!"
     self.icon = '/path/to/success.jpg'
   }
end

on_stylesheet_error -- Pass this function a block of code that gets executed if a stylesheet has an error while processing. The block will be passed the filename and the error message. Can be invoked more then once. Example:

on_stylesheet_error do |filename, message|
  Growl.notify {
    self.message = "#{File.basename(filename)}: #{message}"
    self.icon = '/path/to/fail.jpg'
    sticky!
  }
end