Sha256: 6b730e335a3a557e838f1036b98625e542d57c994d08fedfe7e8360bfcef4638
Contents?: true
Size: 1.9 KB
Versions: 2
Compression:
Stored size: 1.9 KB
Contents
# # File:: CSSProcessor.rb # Author:: wkm # Copyright:: 2009 # License:: GPL # # Rather lightweight CSS processor; primarily intended to minify CSS, but has # basic support for beautifcation as well # module SiteFuel module Processor require 'cssmin' require 'sitefuel/processors/AbstractStringBasedProcessor' class CSSProcessor < AbstractStringBasedProcessor # file patterns for CSS def self.file_patterns [".css"] end # # FILTER SETS # # gives the default filterset to run def self.default_filterset :minify end # gives the minify filter to run def self.filterset_minify [:minify] end # beautifies the source def self.filterset_beautify [:beautify] end # # FILTERS # # strips comments out of CSS using Regexp def filter_strip_comments @document.gsub!(/\/\/.*?$/m, '') @document.gsub!(/\*(.*?)\*/m, '') end # lightweight minification by removing excess whitespace 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 # lightweight beautifier that works through Regexp, adds whitespace above # line comments, puts each declaration on it's own line. etc. def filter_beautify @document end # uses the CSSMin gem to minify a CSS document using regular expressions def filter_minify @document = CSSMin.minify(document) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sitefuel-0.0.0b | lib/sitefuel/processors/CSSProcessor.rb |
sitefuel-0.0.0a | lib/sitefuel/processors/CSSProcessor.rb |