Created
September 19, 2012 12:10
-
-
Save gnepud/3749324 to your computer and use it in GitHub Desktop.
CSS Compressor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CssCompressor | |
def compress(css) | |
#define formatting around the characters | |
colon = ':' | |
semicolon = ';' | |
comma = ',' | |
open_brace = '{' | |
close_brace = '}' | |
#one block per line | |
css.gsub!(/\n/,' ') | |
#no tab | |
css.gsub!(/\t/, '') | |
#get rid of comments | |
css.gsub!(/\/\*.*?\*\//m,'') | |
#apply formatting defined above | |
css.gsub!(/\s*:\s*/,colon) | |
css.gsub!(/\s*;\s*/,semicolon) | |
css.gsub!(/\s*,\s*/,comma) | |
css.gsub!(/\s*\{\s*/,open_brace) | |
css.gsub!(/\s*;\}\s*/,close_brace) | |
css.gsub!(/\s* \}\s*/,close_brace) | |
#single spacing | |
css.gsub!(/\s\s+/,' ') | |
return css | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment