Last active
August 29, 2015 13:57
-
-
Save d4rkie/9681760 to your computer and use it in GitHub Desktop.
simple method to "prettify" compressed CSS. useful with compass in config.rb
This file contains 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 unminify(filename) | |
raise "file not found #{filename}" unless File.exists? filename | |
text = [] | |
File.open(filename, 'r:UTF-8') do |f| | |
f.each_line do |line| | |
line.strip! | |
code = line | |
.split("\t").join(" ") | |
.gsub(/\s*{\s*/i, " {\n ") | |
.gsub(/;\s*/i, ";\n ") | |
.gsub(/,\s*/i, ", ") | |
.gsub(/[ ]*}\s*/i, "}\n") | |
.gsub(/\}/i, "\n}") | |
.gsub(/\n (?<r>[^:]+):\s*/i, "\n " + '\k<r>: ') | |
.gsub(/ @/, '@') | |
.gsub(/\*\/((?<r>.*))/, "*/\n" + '\k<r>') | |
text.push(code) | |
end | |
end | |
File.open(filename, 'w:UTF-8') do |f| | |
f.write(text.join("\n").strip + "\n") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment