def save(file, output = nil)
@contents = File.read(file)
self.base = File.dirname(file)
used = []
urls(file).each do |asset|
begin
next if used.include?(asset.path)
@contents.gsub!(asset.path, asset.path(:cache_buster_type => @type))
used.push(asset.path)
rescue Errno::ENOENT
puts "Unable to locate file #{asset.path}, skipping cache buster"
rescue ArgumentError => e
if e.message =~ /No document root/
puts "Unable to resolve path #{asset.path} without :document_root option"
else
puts "Unable to locate #{asset.path}, skipping cache buster"
end
end
end
File.open(output || file, "w") { |f| f.puts @contents }
@contents = nil
end