Created
July 30, 2010 14:49
-
-
Save aherrman/500644 to your computer and use it in GitHub Desktop.
ruby script to beautify some compressed css. Based on script by floatless on stackoverflow: http://stackoverflow.com/questions/3372060/is-there-an-app-to-automatically-format-css-files/3372419#3372419
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
#!/usr/bin/ruby | |
#Formats CSS | |
input, output = ARGV | |
#Input | |
if input == nil or output == nil | |
puts "Syntax: #{$0} [input] [output]" | |
exit | |
end | |
#Opens file | |
unless File.exist? input | |
puts "File #{input} doesn't exist." | |
exit | |
end | |
#Reads file | |
input = File.read input | |
#Creates output file | |
output = File.new output, "w+" | |
#Processes input | |
input = input.gsub("{", " {\n ") | |
input = input.gsub(",", ", ") | |
input = input.gsub(";", ";\n ") | |
input = input.gsub(/([^;])\}/, '\1;' + "\n}\n\n") | |
input = input.gsub(/ ([^:]+):/, " " + '\1: ') | |
#Writes output | |
output.write input | |
#Closes output | |
output.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment