在网上下载了css,经常是被压缩过的,急需要转化一下,如果你是用的linux,你可以用awk command line来解决:
$ cat somefile.css | awk '{gsub(/{|}|;/,"&\n"); print}' >> uncompressed.css后来个人用ruby写了个转化的代码:
输出到控制台:
path = '/home/feng/compress.css'
string = File.read(path)
puts string.gsub!(/;/,";\n").gsub!(/\}/,"\n}\n").gsub!(/\{/,"\n{\n")输出到文件:
path = '/home/feng/compress.css'
file = File.new(path, "r")
path1 = '/home/feng/uncompress.css'
File.open(path1, "wb") do |f|
f.write(file.readline().gsub!(/;/,";\n").gsub!(/\}/,"\n}\n").gsub!(/\{/,"\n{\n"))
endref:
http://www.commandlinefu.com/commands/view/2339/uncompress-a-css-file
posted on 2009-06-30 18:27
fl1429 阅读(206)
评论(0) 编辑 收藏 所属分类:
Rails