require 'bundler' Bundler.require namespace :assets do desc 'Update css files to correctly load background images' task :css do puts "Looking for css files containing background(-image)?:url ..." src = /background(\-image)?[\s+]?\:(.*?)url\((\W+)?([^\.]*)\.(\w+)(\W+)?\)/ dst = 'background\1:\2url(\3\4.\5%s\6)' % EL::FinderHelpers::ASSETS_EXT Dir[File.expand_path('../assets/**/*.css', __FILE__)].each do |file| css = File.read(file) if css =~ src puts "Updating #{file}" File.open(file, 'w') {|f| f << css.gsub(src, dst)} end end puts "Done" end end Bundler::GemHelper.install_tasks