Skip to content

Instantly share code, notes, and snippets.

@eladkehat
Created May 13, 2010 10:44
Show Gist options
  • Save eladkehat/399714 to your computer and use it in GitHub Desktop.
Save eladkehat/399714 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Explodes a minified css file, e.g. using YUI Compressor (http://developer.yahoo.com/yui/compressor/)
# Minified css (unlike obfuscated javascript) is still easily readable if only the spaces, newlines and
# indentations are put back in. This little ruby script does this with some simple regular expressions.
fn = ARGV[0]
css = IO.read fn
replacements = [ [/\s*\{/, " {\n\t"], [/;/, ";\n\t"], [/\t?\}/, "}\n\n"], ]
replacements.each { |re, s| css.gsub! re, s }
fout = File.join(File.dirname(fn), File.basename(fn, ".*") + ".exploded." + File.extname(fn))
File.open(fout, 'w') {|f| f.write css }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment