4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/cache-with-yuicompressor.rb', line 4
def write_asset_file_contents(joined_asset_path, asset_paths)
FileUtils.mkdir_p(File.dirname(joined_asset_path))
File.atomic_write(joined_asset_path) { |cache| cache.write(join_asset_file_contents(asset_paths)) }
begin
temp_file_path = joined_asset_path + ".tmp"
f = File.open(joined_asset_path)
fo = File.new(temp_file_path, "w")
f.each {|line|
fo.puts line.gsub(/console.(log|debug|info|warn|error|assert|dir|dirxml|trace|group|groupEnd|time|timeEnd|profile|profileEnd|count)\((.*)\);?/,"");
}
fo.close
f.close
system("cp #{temp_file_path} #{joined_asset_path}")
jarpath = File.dirname(__FILE__) + "/yuicompressor-2.4.2.jar";
cmd = "java -jar #{jarpath} #{joined_asset_path} -o #{joined_asset_path}"
ret = system(cmd)
rescue
end
mt = asset_paths.map { |p| File.mtime(asset_file_path(p)) }.max
File.utime(mt, mt, joined_asset_path)
end
|