Class: Compass::Configuration::Data

Inherits:
Object
  • Object
show all
Includes:
Adapters, Inheritance, Serialization
Defined in:
lib/compass/configuration/data.rb

Overview

The Compass configuration data storage class manages configuration data that comes from a variety of different sources and aggregates them together into a consistent API Some of the possible sources of configuration data:

* Compass default project structure for stand alone projects
* App framework specific project structures for rails, etc.
* User supplied explicit configuration
* Configuration data provided via the command line interface

There are two kinds of configuration data that doesn’t come from the user:

  1. Configuration data that is defaulted as if the user had provided it themselves. This is useful for providing defaults that the user is likely to want to edit but shouldn’t have to provide explicitly when getting started

  2. Configuration data that is defaulted behind the scenes because some value is required.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Adapters

#absolute_path?, #resolve_additional_import_paths, #sass_load_paths, #to_compiler_arguments, #to_sass_engine_options, #to_sass_plugin_options

Methods included from Serialization

included

Methods included from Inheritance

included

Constructor Details

#initialize(name, attr_hash = nil) ⇒ Data

Returns a new instance of Data.



29
30
31
32
33
34
35
# File 'lib/compass/configuration/data.rb', line 29

def initialize(name, attr_hash = nil)
  raise "I need a name!" unless name
  @name = name
  self.required_libraries = []
  set_all(attr_hash) if attr_hash
  self.top_level = self
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#required_librariesObject

Returns the value of attribute required_libraries.



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

def required_libraries
  @required_libraries
end

Instance Method Details

#add_import_path(*paths) ⇒ Object



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

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.



74
75
76
77
78
79
80
# File 'lib/compass/configuration/data.rb', line 74

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.



59
60
61
62
63
64
65
# File 'lib/compass/configuration/data.rb', line 59

def asset_host(&block)
  if block_given?
    @asset_host = block
  else
    @asset_host
  end
end

#relative_assets?Boolean

Returns:

  • (Boolean)


88
89
90
91
# File 'lib/compass/configuration/data.rb', line 88

def relative_assets?
  # the http_images_path is deprecated, but here for backwards compatibility.
  relative_assets || http_images_path == :relative
end

#require(lib) ⇒ Object

Require a compass plugin and capture that it occured so that the configuration serialization works next time.



83
84
85
86
# File 'lib/compass/configuration/data.rb', line 83

def require(lib)
  required_libraries << lib
  super
end

#set_all(attr_hash) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/compass/configuration/data.rb', line 37

def set_all(attr_hash)
  # assert_valid_keys!(attr_hash)
  attr_hash.each do |a, v|
    if self.respond_to?("#{a}=")
      self.send("#{a}=", v)
    end
  end
end