Module: SeeLessEssEss

Defined in:
lib/see-less-ess-ess.rb

Defined Under Namespace

Classes: Checker, Extractor, RemoveUnusedRules

Constant Summary collapse

VERSION =
'0.0.2'

Class Method Summary collapse

Class Method Details

.initObject



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/see-less-ess-ess.rb', line 139

def self.init
  if not defined? ::Compass or initialised?
    return
  end
  @@initialised = true

  Compass::Configuration.add_configuration_property(
    :templates_glob, "Glob to scan for template files") do

    "#{project_path}/**/*.html"
  end
  Compass::Configuration.add_configuration_property(
    :used_css_classes, "CSS classes to explicity declare as 'used'") do

    []
  end

  Sass::Engine.class_eval do
    alias_method :_slss_to_tree, :_to_tree
    def _to_tree
      conf = Compass.configuration
      extractor = SeeLessEssEss::Extractor.new(conf.templates_glob)
      checker = SeeLessEssEss::Checker.new(extractor, conf.used_css_classes)

      tree = _slss_to_tree
      if @options[:filename] == @options[:original_filename]
        meta = class << tree; self; end
        meta.send(:define_method, :render) do
          # Taken verbatim from real #render
          Sass::Tree::Visitors::CheckNesting.visit(self)
          result = Sass::Tree::Visitors::Perform.visit(self)
          # Check again to validate mixins
          Sass::Tree::Visitors::CheckNesting.visit(result)
          result, extends = Sass::Tree::Visitors::Cssize.visit(result)
          Sass::Tree::Visitors::Extend.visit(result, extends)
          # The next line is our modification
          SeeLessEssEss::RemoveUnusedRules.new(checker).visit(result)
          result.to_s
        end
      end
      tree
    end
  end

end

.initialised?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/see-less-ess-ess.rb', line 136

def self.initialised?
  @@initialised ||= false
end