Module: Sass::Plugin

Extended by:
Plugin
Includes:
Util
Included in:
Plugin
Defined in:
lib/sass/plugin.rb,
lib/sass/plugin/rack.rb,
lib/sass/plugin/compiler.rb,
lib/sass/plugin/configuration.rb,
lib/sass/plugin/staleness_checker.rb

Overview

This module provides a single interface to the compilation of Sass/SCSS files for an application. It provides global options and checks whether CSS files need to be updated.

This module is used as the primary interface with Sass when it's used as a plugin for various frameworks. All Rack-enabled frameworks are supported out of the box. The plugin is automatically activated for Rails and Merb. Other frameworks must enable it explicitly; see Rack.

This module has a large set of callbacks available to allow users to run code (such as logging) when certain things happen. All callback methods are of the form on_#{name}, and they all take a block that's called when the given action occurs.

Note that this class proxies almost all methods to its Compiler instance. See #compiler.

Examples:

Using a callback

Sass::Plugin.on_updating_stylesheet do |template, css|
  puts "Compiling #{template} to #{css}"
end
Sass::Plugin.update_stylesheets
  #=> Compiling app/sass/screen.scss to public/stylesheets/screen.css
  #=> Compiling app/sass/print.scss to public/stylesheets/print.css
  #=> Compiling app/sass/ie.scss to public/stylesheets/ie.css

See Also:

Defined Under Namespace

Modules: Configuration Classes: Compiler, MerbBootLoader, Rack, StalenessChecker

Constant Summary

Constants included from Util

Util::CHARSET_REGEXPS, Util::ENCODINGS_TO_CHECK, Util::RUBY_ENGINE, Util::RUBY_VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#abstract, #ap_geq?, #ap_geq_3?, #av_template_class, #caller_info, #check_encoding, #check_sass_encoding, #enum_cons, #enum_slice, #enum_with_index, #extract_values, #flatten, #has?, #inject_values, #inspect_obj, #intersperse, #ironruby?, #lcs, #map_hash, #map_keys, #map_vals, #merge_adjacent_strings, #ord, #paths, #powerset, #rails_env, #rails_root, #restrict, #ruby1_8?, #ruby1_8_6?, #sass_warn, #scope, #set_eql?, #set_hash, #silence_sass_warnings, #silence_warnings, #strip_string_array, #substitute, #to_hash, #version_geq, #version_gt, #windows?, #with_extracted_values

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block)

All other method invocations are proxied to the #compiler.

See Also:



105
106
107
108
109
110
111
# File 'lib/sass/plugin.rb', line 105

def method_missing(method, *args, &block)
  if compiler.respond_to?(method)
    compiler.send(method, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#checked_for_updatesBoolean

Whether or not Sass has ever checked if the stylesheets need to be updated (in this Ruby instance).

Returns:

  • (Boolean)


44
45
46
# File 'lib/sass/plugin.rb', line 44

def checked_for_updates
  @checked_for_updates
end

Instance Method Details

#check_for_updates

Same as #update_stylesheets, but respects #checked_for_updates and the :always_update and :always_check options.



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

def check_for_updates
  return unless !Sass::Plugin.checked_for_updates ||
      Sass::Plugin.options[:always_update] || Sass::Plugin.options[:always_check]
  update_stylesheets
end

#compilerSass::Plugin::Compiler

Returns the singleton compiler instance. This compiler has been pre-configured according to the plugin configuration.



62
63
64
# File 'lib/sass/plugin.rb', line 62

def compiler
  @compiler ||= Compiler.new
end

#force_update_stylesheets(individual_files = [])

Updates all stylesheets, even those that aren't out-of-date. Ignores the cache.

Parameters:

  • individual_files (Array<(String, String)>) (defaults to: [])

    A list of files to check for updates in addition to those specified by the :template_location option. The first string in each pair is the location of the Sass/SCSS file, the second is the location of the CSS file that it should be compiled to.

See Also:



94
95
96
97
98
99
# File 'lib/sass/plugin.rb', line 94

def force_update_stylesheets(individual_files = [])
  Compiler.new(options.dup.merge(
      :never_update => false,
      :always_update => true,
      :cache => false)).update_stylesheets(individual_files)
end

#options

There's a small speedup by not using method missing for frequently delegated methods.



119
120
121
# File 'lib/sass/plugin.rb', line 119

def options
  compiler.options
end

#respond_to?(method) ⇒ Boolean

For parity with method_missing

Returns:

  • (Boolean)


114
115
116
# File 'lib/sass/plugin.rb', line 114

def respond_to?(method)
  super || compiler.respond_to?(method)
end

#update_stylesheets(individual_files = [])

Updates out-of-date stylesheets.

Checks each Sass/SCSS file in :template_location to see if it's been modified more recently than the corresponding CSS file in :css_location. If it has, it updates the CSS file.

Parameters:

  • individual_files (Array<(String, String)>) (defaults to: [])

    A list of files to check for updates in addition to those specified by the :template_location option. The first string in each pair is the location of the Sass/SCSS file, the second is the location of the CSS file that it should be compiled to.



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

def update_stylesheets(individual_files = [])
  return if options[:never_update]
  compiler.update_stylesheets(individual_files)
end