Parent

Class Index [+]

Quicksearch

Sass::Plugin::StalenessChecker

The class handles `.s[ca]ss` file staleness checks via their mtime timestamps.

To speed things up two level of caches are employed:

Usage:

Constants

DELETED

Attributes

dependencies_cache[RW]

@private

Public Class Methods

new() click to toggle source

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

    # File lib/sass/plugin/staleness_checker.rb, line 35
35:       def initialize
36:         @dependencies = self.class.dependencies_cache
37: 
38:         # Entries in the following instance-level caches are never explicitly expired.
39:         # Instead they are supposed to automaticaly go out of scope when a series of staleness checks
40:         # (this instance of StalenessChecker was created for) is finished.
41:         @mtimes, @dependencies_stale = {}, {}
42:       end
stylesheet_needs_update?(css_file, template_file) 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`.
    # File lib/sass/plugin/staleness_checker.rb, line 66
66:       def self.stylesheet_needs_update?(css_file, template_file)
67:         new.stylesheet_needs_update?(css_file, template_file)
68:       end

Public Instance Methods

stylesheet_needs_update?(css_file, template_file) 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`.
    # File lib/sass/plugin/staleness_checker.rb, line 50
50:       def stylesheet_needs_update?(css_file, template_file)
51:         template_file, css_mtime = File.expand_path(template_file), mtime(css_file)
52: 
53:         css_mtime == DELETED || dependency_updated?(css_mtime).call(template_file)
54:       end

Private Instance Methods

compute_dependencies(filename) click to toggle source
     # File lib/sass/plugin/staleness_checker.rb, line 114
114:       def compute_dependencies(filename)
115:         Files.tree_for(filename, Plugin.engine_options).grep(Tree::ImportNode) do |n|
116:           File.expand_path(n.full_filename) unless n.full_filename =~ /\.css$/
117:         end.compact
118:       rescue Sass::SyntaxError => e
119:         [] # If the file has an error, we assume it has no dependencies
120:       end
dependencies(filename) click to toggle source
     # File lib/sass/plugin/staleness_checker.rb, line 93
 93:       def dependencies(filename)
 94:         stored_mtime, dependencies = @dependencies[filename]
 95: 
 96:         if !stored_mtime || stored_mtime < mtime(filename)
 97:           @dependencies[filename] = [mtime(filename), dependencies = compute_dependencies(filename)]
 98:         end
 99: 
100:         dependencies
101:       end
dependencies_stale?(template_file, css_mtime) click to toggle source
    # File lib/sass/plugin/staleness_checker.rb, line 72
72:       def dependencies_stale?(template_file, css_mtime)
73:         timestamps = @dependencies_stale[template_file] ||= {}
74:         timestamps.each_pair do |checked_css_mtime, is_stale|
75:           if checked_css_mtime <= css_mtime && !is_stale
76:             return false
77:           elsif checked_css_mtime > css_mtime && is_stale
78:             return true
79:           end
80:         end
81:         timestamps[css_mtime] = dependencies(template_file).any?(&dependency_updated?(css_mtime))
82:       end
dependency_updated?(css_mtime) click to toggle source
     # File lib/sass/plugin/staleness_checker.rb, line 103
103:       def dependency_updated?(css_mtime)
104:         lambda do |dep|
105:           begin
106:             mtime(dep) > css_mtime || dependencies_stale?(dep, css_mtime)
107:           rescue Sass::SyntaxError
108:             # If there's an error finding depenencies, default to recompiling.
109:             true
110:           end
111:         end
112:       end
mtime(filename) click to toggle source
    # File lib/sass/plugin/staleness_checker.rb, line 84
84:       def mtime(filename)
85:         @mtimes[filename] ||= begin
86:           File.mtime(filename).to_i
87:         rescue Errno::ENOENT
88:           @dependencies.delete(filename)
89:           DELETED
90:         end
91:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.