在網上下載了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 閱讀(215)
評論(0) 編輯 收藏 所屬分類:
Rails