2
3
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
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/redundant.rb', line 2
def self.search(args=nil)
puts "Searching for redundant assets"
path = args || Dir.pwd
puts path
assets = self.findAssets(path);
puts "Existing Assets: #{assets.size}"
checkFolders = ['assets/stylesheets', 'assets/javascripts', 'helpers', 'views']
checkFolders.each do |folder|
if (File.directory?("#{path}/app/#{folder}"))
Find.find("#{path}/app/#{folder}").each do |file|
if (File.file?(file) && file !~ /\.DS_Store/)
file_contents = File.open(file, "r")
data = file_contents.read
file_contents.close
data.scan(/\/assets\/(.*?\.(jpg|jpeg|png|gif|webp))/i).each do |image|
assets.delete("/app/assets/images/#{image.first}")
end
data.scan(/image_tag.*?"(.*?)"/).each do |image|
assets.delete("/app/assets/images/#{image.first}")
end
end
end
else
puts "The directory #{path}/app/#{folder} does not exist"
end
end
puts "==============================="
puts "Unused Assets (#{assets.size})"
puts "==============================="
assets.each do |asset|
puts asset
end
return ""
end
|