javaeye3/script/pack_css.rb

29 lines
643 B
Ruby

#!/usr/bin/env ruby
DIR_PATH = "public/stylesheets"
IMPORT_EXP = /@import url\( (.*) \);/
COMMENT_EXP = /^\/\*(.*)\*\/$/
def pack(file_name)
file_path = File.expand_path(file_name)
dir_name = File.dirname(file_path)
f = File.new(file_path, "r")
result = ""
while (line = f.gets)
if m = IMPORT_EXP.match(line)
result << pack("#{dir_name}/#{m[1]}")
else
result << line unless line =~ COMMENT_EXP
end
end
result
end
Dir.foreach(DIR_PATH) { |f|
if f =~ /.css$/
file_name = "#{DIR_PATH}/#{f}"
result = pack(file_name)
File.open(file_name, "w") do |file|
file.puts result
end
end
}