随笔-167  评论-65  文章-0  trackbacks-0
在网上下载了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"))
end


ref:
http://www.commandlinefu.com/commands/view/2339/uncompress-a-css-file




write by feng
posted on 2009-06-30 18:27 fl1429 阅读(198) 评论(0)  编辑  收藏 所属分类: Rails

只有注册用户登录后才能发表评论。


网站导航:
 
已访问数:
free counters