Module: Sass::Plugin::Configuration

Included in:
Compiler
Defined in:
lib/sass/plugin/configuration.rb,
lib/sass/plugin/merb.rb,
lib/sass/plugin/rails.rb

Overview

We keep configuration in its own self-contained file so that we can load it independently in Rails 3, where the full plugin stuff is lazy-loaded.

Instance Method Summary collapse

Instance Method Details

#add_template_location(template_location, css_location = options[:css_location])

Adds a new template-location/css-location mapping. This means that Sass/SCSS files in template_location will be compiled to CSS files in css_location.

This is preferred over manually manipulating the :template_location option since the option can be in multiple formats.

Note that this method will change options[:template_location] to be in the Array format. This means that even if options[:template_location] had previously been a Hash or a String, it will now be an Array.

Parameters:

  • template_location (String)

    The location where Sass/SCSS files will be.

  • css_location (String) (defaults to: options[:css_location])

    The location where compiled CSS files will go.



51
52
53
54
# File 'lib/sass/plugin/configuration.rb', line 51

def add_template_location(template_location, css_location = options[:css_location])
  normalize_template_location!
  template_location_array << [template_location, css_location]
end

#default_options{Symbol => Object}

Returns the default options for a Sass::Plugin::Compiler.

Returns:

  • ({Symbol => Object})


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sass/plugin/merb.rb', line 6

def default_options
  @default_options ||= begin
    version = Merb::VERSION.split('.').map {|n| n.to_i}
    if version[0] <= 0 && version[1] < 5
      root = MERB_ROOT
      env  = MERB_ENV
    else
      root = Merb.root.to_s
      env  = Merb.environment
    end

    {
      :always_update      => false,
      :template_location => root + '/public/stylesheets/sass',
      :css_location      => root + '/public/stylesheets',
      :cache_location    => root + '/tmp/sass-cache',
      :always_check      => env != "production",
      :quiet             => env != "production",
      :full_exception    => env != "production"
    }.freeze
  end
end

#options{Symbol => Object}

An options hash. See the Sass options documentation.

Returns:

  • ({Symbol => Object})


31
32
33
# File 'lib/sass/plugin/configuration.rb', line 31

def options
  @options ||= default_options.dup
end

#remove_template_location(template_location, css_location = options[:css_location]) ⇒ Boolean

Removes a template-location/css-location mapping. This means that Sass/SCSS files in template_location will no longer be compiled to CSS files in css_location.

This is preferred over manually manipulating the :template_location option since the option can be in multiple formats.

Note that this method will change options[:template_location] to be in the Array format. This means that even if options[:template_location] had previously been a Hash or a String, it will now be an Array.

Parameters:

  • template_location (String)

    The location where Sass/SCSS files were, which is now going to be ignored.

  • css_location (String) (defaults to: options[:css_location])

    The location where compiled CSS files went, but will no longer go.

Returns:

  • (Boolean)

    Non-nil if the given mapping already existed and was removed, or nil if nothing was changed.



78
79
80
81
# File 'lib/sass/plugin/configuration.rb', line 78

def remove_template_location(template_location, css_location = options[:css_location])
  normalize_template_location!
  template_location_array.delete([template_location, css_location])
end

#reset!

Resets the options and clears all callbacks.



22
23
24
25
# File 'lib/sass/plugin/configuration.rb', line 22

def reset!
  @options = nil
  clear_callbacks!
end

#template_location_arrayArray<(String, String)>

Returns the template locations configured for Sass as an array of [template_location, css_location] pairs. See the :template_location option for details.

Returns:

  • (Array<(String, String)>)

    An array of [template_location, css_location] pairs.



90
91
92
93
94
95
96
# File 'lib/sass/plugin/configuration.rb', line 90

def template_location_array
  old_template_location = options[:template_location]
  normalize_template_location!
  options[:template_location]
ensure
  options[:template_location] = old_template_location
end