Skip to content

Instantly share code, notes, and snippets.

@d4rkie
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d4rkie/9681760 to your computer and use it in GitHub Desktop.
Save d4rkie/9681760 to your computer and use it in GitHub Desktop.
simple method to "prettify" compressed CSS. useful with compass in config.rb
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