Class: SiteFuel::Processor::CSSProcessor

Inherits:
AbstractStringBasedProcessor show all
Defined in:
lib/sitefuel/processors/CSSProcessor.rb

Instance Attribute Summary

Attributes inherited from AbstractStringBasedProcessor

#document

Attributes inherited from AbstractProcessor

#execution_list, #original_size, #processed_size, #resource_name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractStringBasedProcessor

filter_string, #generate, #generate_string, #open_file, #open_string, process_file, process_string, #processor_symbol, processor_type, #save

Methods inherited from AbstractProcessor

#add_filter, #add_filterset, #clear_filters, #create_file, #drop_filter, #execute, file_pattern_match?, #filter?, filter?, filters, filters_in_filterset, filterset?, filterset_ignore, filtersets, find_processors, #finish_filters, #initialize, processes_file?, processor_name, #processor_symbol, processor_type, #run_filter, #run_filterset, #save, #setup_filters

Methods included from ClassLogging

#debug, #error, #fatal, #info, #warn

Methods included from Configurable

#configuration_options, #configure, #ensure_configurable_option, #post_configuration, #pre_configuration, #set_configuration

Methods included from Logging

#debug, #error, #fatal, #info, #logger=, #warn

Constructor Details

This class inherits a constructor from SiteFuel::Processor::AbstractProcessor

Class Method Details

.default_filtersetObject

gives the default filterset to run



30
31
32
# File 'lib/sitefuel/processors/CSSProcessor.rb', line 30

def self.default_filterset
  :minify
end

.file_patternsObject

file patterns for CSS



21
22
23
# File 'lib/sitefuel/processors/CSSProcessor.rb', line 21

def self.file_patterns
  [".css"]
end

.filterset_beautifyObject

beautifies the source



40
41
42
# File 'lib/sitefuel/processors/CSSProcessor.rb', line 40

def self.filterset_beautify
  [:beautify]
end

.filterset_minifyObject

gives the minify filter to run



35
36
37
# File 'lib/sitefuel/processors/CSSProcessor.rb', line 35

def self.filterset_minify
  [:minify]
end

Instance Method Details

#filter_beautifyObject

lightweight beautifier that works through Regexp, adds whitespace above line comments, puts each declaration on it's own line. etc.



73
74
75
# File 'lib/sitefuel/processors/CSSProcessor.rb', line 73

def filter_beautify
  @document
end

#filter_clean_whitespaceObject

lightweight minification by removing excess whitespace



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/sitefuel/processors/CSSProcessor.rb', line 57

def filter_clean_whitespace
  @document.gsub!(/(\s\s+)/) do |text_block|
    # if there's a newline we keep it. This is necessary for comments.
    # in general, however, this filter should really be run after the
    # strip_comments filter because it's silly to clip whitespace but
    # not comments....
    if text_block.count("\n") > 0
      "\n"
    else
      text_block[0..0]
    end
  end
end

#filter_minifyObject

uses the CSSMin gem to minify a CSS document using regular expressions



78
79
80
# File 'lib/sitefuel/processors/CSSProcessor.rb', line 78

def filter_minify
  @document = CSSMin.minify(document)
end

#filter_strip_commentsObject

strips comments out of CSS using Regexp



51
52
53
54
# File 'lib/sitefuel/processors/CSSProcessor.rb', line 51

def filter_strip_comments
  @document.gsub!(/\/\/.*?$/m, '')
  @document.gsub!(/\*(.*?)\*/m, '')
end