class Sass::Plugin::StalenessChecker

The class handles `.sss` file staleness checks via their mtime timestamps.

To speed things up two level of caches are employed:

Usage:

Attributes

dependencies_cache[RW]

TODO: attach this to a compiler instance. @private

Public Class Methods

new(options) click to toggle source

Creates a new StalenessChecker for checking the staleness of several stylesheets at once.

@param options [{Symbol => Object}]

See {file:SASS_REFERENCE.md#sass_options the Sass options documentation}.
# File lib/sass/plugin/staleness_checker.rb, line 39
def initialize(options)
  @dependencies = self.class.dependencies_cache

  # Entries in the following instance-level caches are never explicitly expired.
  # Instead they are supposed to automaticaly go out of scope when a series of staleness checks
  # (this instance of StalenessChecker was created for) is finished.
  @mtimes, @dependencies_stale, @parse_trees = {}, {}, {}
  @options = Sass::Engine.normalize_options(options)
end
stylesheet_modified_since?(template_file, mtime, importer = nil) click to toggle source

Returns whether a Sass or SCSS stylesheet has been modified since a given time.

The distinction between this method and the instance-level {#stylesheet_modified_since?} is that the instance method preserves mtime and stale-dependency caches, so it's better to use when checking multiple stylesheets at once.

@param template_file [String] The location of the Sass or SCSS template. @param mtime [Fixnum] The modification time to check against. @param importer [Sass::Importers::Base] The importer used to locate the stylesheet.

Defaults to the filesystem importer.

@return [Boolean] Whether the stylesheet has been modified.

# File lib/sass/plugin/staleness_checker.rb, line 104
def self.stylesheet_modified_since?(template_file, mtime, importer = nil)
  new(Plugin.engine_options).stylesheet_modified_since?(template_file, mtime, importer)
end
stylesheet_needs_update?(css_file, template_file, importer = nil) click to toggle source

Returns whether or not a given CSS file is out of date and needs to be regenerated.

The distinction between this method and the instance-level {#stylesheet_needs_update?} is that the instance method preserves mtime and stale-dependency caches, so it's better to use when checking multiple stylesheets at once.

@param css_file [String] The location of the CSS file to check. @param template_file [String] The location of the Sass or SCSS template

that is compiled to `css_file`.

@return [Boolean] Whether the stylesheet needs to be updated.

# File lib/sass/plugin/staleness_checker.rb, line 89
def self.stylesheet_needs_update?(css_file, template_file, importer = nil)
  new(Plugin.engine_options).stylesheet_needs_update?(css_file, template_file, importer)
end

Public Instance Methods

stylesheet_modified_since?(template_file, mtime, importer = nil) click to toggle source

Returns whether a Sass or SCSS stylesheet has been modified since a given time.

@param template_file [String] The location of the Sass or SCSS template. @param mtime [Fixnum] The modification time to check against. @param importer [Sass::Importers::Base] The importer used to locate the stylesheet.

Defaults to the filesystem importer.

@return [Boolean] Whether the stylesheet has been modified.

# File lib/sass/plugin/staleness_checker.rb, line 73
def stylesheet_modified_since?(template_file, mtime, importer = nil)
  importer ||= @options[:filesystem_importer].new(".")
  dependency_updated?(mtime).call(template_file, importer)
end
stylesheet_needs_update?(css_file, template_file, importer = nil) click to toggle source

Returns whether or not a given CSS file is out of date and needs to be regenerated.

@param css_file [String] The location of the CSS file to check. @param template_file [String] The location of the Sass or SCSS template

that is compiled to `css_file`.

@return [Boolean] Whether the stylesheet needs to be updated.

# File lib/sass/plugin/staleness_checker.rb, line 56
def stylesheet_needs_update?(css_file, template_file, importer = nil)
  template_file = File.expand_path(template_file)
  begin
    css_mtime = File.mtime(css_file)
  rescue Errno::ENOENT
    return true
  end
  stylesheet_modified_since?(template_file, css_mtime, importer)
end