lib/juicer/css_cache_buster.rb in juicer-0.2.3 vs lib/juicer/css_cache_buster.rb in juicer-0.2.4

- old
+ new

@@ -37,17 +37,21 @@ def save(file, output = nil) @contents = File.read(file) used = [] urls(file).each do |url| - path = resolve(url, file) - next if used.include?(path) + begin + path = resolve(url, file) + next if used.include?(path) - if path != url - used << path - basename = File.basename(Juicer::CacheBuster.path(path)) - @contents.sub!(url, File.join(File.dirname(url), basename)) + if path != url + used << path + basename = File.basename(Juicer::CacheBuster.path(path, @type)) + @contents.gsub!(url, File.join(File.dirname(url), basename)) + end + rescue Errno::ENOENT + puts "Unable to locate file #{path || url}, skipping" end end File.open(output || file, "w") { |f| f.puts @contents } @contents = nil @@ -60,10 +64,10 @@ # they're resolved relative to the +file+ path. # def urls(file) @contents = File.read(file) unless @contents - @contents.scan(/url\(([^\)]*)\)/m).collect do |match| + @contents.scan(/url\([\s"']*([^\)"'\s]*)[\s"']*\)/m).collect do |match| match.first end end #