Created
March 28, 2011 21:22
-
-
Save ashaw/891314 to your computer and use it in GitHub Desktop.
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
def minify_css(css) | |
# take out new lines | |
css.gsub!(/\n/,'') | |
# take out spaces between selectors and rule blocks | |
css.gsub!(/([\.a-zA-Z_\-\#]+?)\s*\{\s*([^\{\}\s])?/,'\1{\2') | |
# take out spaces between rule block endings and selectors | |
css.gsub!(/\}\s*([\.a-zA-Z_\-\#]+?)/,'}\1') | |
# take out spaces between rules | |
css.gsub!(/(:|;)(\s+)?([\.a-zA-Z_0-9]+)?/,'\1\3') | |
# take out comments | |
css.gsub!(/(\/\*.*\*\/)/,' ') | |
css | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment