Module: Smurf::Stylesheet::Minifier

Defined in:
lib/smurf/stylesheet.rb

Instance Method Summary collapse

Instance Method Details

#compress_whitespaceObject

.*? is a non-greedy match on anything



20
# File 'lib/smurf/stylesheet.rb', line 20

def compress_whitespace; compress!(/\s+/, ' '); end

#remove_commentsObject



21
# File 'lib/smurf/stylesheet.rb', line 21

def remove_comments; compress!(/\/\*.*?\*\/\s?/, ''); end

#remove_spaces_inside_blockObject



25
26
27
28
29
30
# File 'lib/smurf/stylesheet.rb', line 25

def remove_spaces_inside_block
  compress!(/\{(.*?)(?=\})/) do |m|
    # remove spaces in the labels/attributes
    m.gsub(/(?:\A|\s*;)(.*?)(?::\s*|\z)/) { |n| n.gsub(/\s/, '') }.strip
  end
end

#remove_spaces_outside_blockObject



22
23
24
# File 'lib/smurf/stylesheet.rb', line 22

def remove_spaces_outside_block
  compress!(/(\A|\})(.*?)\{/) { |m| m.gsub(/\s?([}{,])\s?/, '\1') }
end

#trim_last_semicolonObject



31
# File 'lib/smurf/stylesheet.rb', line 31

def trim_last_semicolon; compress!(/;(?=\})/, ''); end