Class: Rack::Less::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/less/config.rb

Overview

Handles configuration for Rack::Less Available config settings: :cache

whether to cache the compilation output to
a corresponding static file. Also determines
what value config#combinations(:key) returns

:compress

whether to remove extraneous whitespace from
compilation output

:combinations

Rack::Less uses combinations as directives for
combining the output of many stylesheets and
serving them as a single resource.  Combinations
are defined using a hash, where the key is the
resource name and the value is an array of
names specifying the stylesheets to combine
as that resource.  For example:
  Rack::Less.config.combinations = {
    'web'    => ['reset', 'common', 'app_web'],
    'mobile' => ['reset', 'iui', 'common', 'app_mobile']
  }

:cache_bust

whether to append a timestamp to the sheet requests generated by combinations

Constant Summary collapse

ATTRIBUTES =
[:cache, :compress, :combinations, :cache_bust]
DEFAULTS =
{
  :cache        => false,
  :compress     => false,
  :combinations => {},
  :cache_bust   => nil
}

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}) ⇒ Config

Returns a new instance of Config.



38
39
40
41
42
# File 'lib/rack/less/config.rb', line 38

def initialize(settings={})
  ATTRIBUTES.each do |a|
    instance_variable_set("@#{a}", settings[a].nil? ? DEFAULTS[a] : settings[a])
  end
end

Instance Method Details

#cache?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/rack/less/config.rb', line 44

def cache?
  !!@cache
end

#combinations(key = nil) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rack/less/config.rb', line 52

def combinations(key=nil)
  if key.nil?
    @combinations
  else
    if cache?
      stylesheet_filename(key)
    else
      (@combinations[key] || []).collect do |combo|
        stylesheet_filename(combo)
      end
    end
  end
end

#compress?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/rack/less/config.rb', line 48

def compress?
  !!@compress
end

#stylesheet(key) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/rack/less/config.rb', line 66

def stylesheet(key)
  if @combinations[key]
    combinations(key.to_s)
  else
    stylesheet_filename(key.to_s)
  end
end