Skip to content

Instantly share code, notes, and snippets.

@priyank-gupta
Created September 30, 2013 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save priyank-gupta/6769446 to your computer and use it in GitHub Desktop.
Save priyank-gupta/6769446 to your computer and use it in GitHub Desktop.
Image Coverage in Rails Project
require "fileutils"
image_files = Dir.glob("**/*.jpeg") + Dir.glob("**/*.jpg") + Dir.glob("**/*.png") + Dir.glob("**/*.gif")
data_files = Dir.glob("**/*.rb") + Dir.glob("**/*.html.erb") + Dir.glob("**/*.css") + Dir.glob("**/*.css.erb") + Dir.glob("**/*.js") + Dir.glob("**/*.js.erb")
puts image_files.length.to_s + " images found & " + data_files.length.to_s + " files found to search against"
content = data_files.inject("") { |c, f| c += File.open(f, 'r').read }
#This script may not look for the images that are dynamically generated (using loop etc.)
image_files.each do |img|
name = File.basename(img)
if !(content =~ Regexp.new(name))
dirname = File.dirname(img)
FileUtils.mkdir_p("../unused/" + dirname)
FileUtils.cp(img, "../unused/" + img)
puts "Image " + img + " copied to ../unused/" + dirname + " folder"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment