redundant 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/redundant +9 -0
- data/lib/redundant.rb +66 -0
- metadata +49 -0
data/bin/redundant
ADDED
data/lib/redundant.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
class Redundant
|
2
|
+
def self.search(args=nil)
|
3
|
+
puts "Searching for redundant assets"
|
4
|
+
|
5
|
+
path = args || Dir.pwd
|
6
|
+
|
7
|
+
puts path
|
8
|
+
|
9
|
+
assets = self.findAssets(path);
|
10
|
+
puts "Existing Assets: #{assets.size}"
|
11
|
+
|
12
|
+
checkFolders = ['assets/stylesheets', 'assets/javascripts', 'helpers', 'views']
|
13
|
+
|
14
|
+
checkFolders.each do |folder|
|
15
|
+
if (File.directory?("#{path}/app/#{folder}"))
|
16
|
+
Find.find("#{path}/app/#{folder}").each do |file|
|
17
|
+
if (File.file?(file) && file !~ /\.DS_Store/)
|
18
|
+
file_contents = File.open(file, "r")
|
19
|
+
data = file_contents.read
|
20
|
+
file_contents.close
|
21
|
+
|
22
|
+
data.scan(/\/assets\/(.*?\.(jpg|jpeg|png|gif|webp))/i).each do |image|
|
23
|
+
assets.delete("/app/assets/images/#{image.first}")
|
24
|
+
end
|
25
|
+
|
26
|
+
data.scan(/image_tag.*?"(.*?)"/).each do |image|
|
27
|
+
|
28
|
+
assets.delete("/app/assets/images/#{image.first}")
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
else
|
34
|
+
puts "The directory #{path}/app/#{folder} does not exist"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
puts "==============================="
|
39
|
+
puts "Unused Assets (#{assets.size})"
|
40
|
+
puts "==============================="
|
41
|
+
|
42
|
+
assets.each do |asset|
|
43
|
+
puts asset
|
44
|
+
end
|
45
|
+
|
46
|
+
return ""
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.findAssets(path)
|
50
|
+
require 'find'
|
51
|
+
|
52
|
+
|
53
|
+
assets = []
|
54
|
+
|
55
|
+
if File.directory? "#{path}/app/assets/images/"
|
56
|
+
Find.find("#{path}/app/assets/images/").each do |asset|
|
57
|
+
assets.push asset.gsub(/#{path}/, '') if asset.match(/(png|jpg|jpeg|gif|webp)/i)
|
58
|
+
end
|
59
|
+
else
|
60
|
+
puts "Can't find an assets image directory (#{path}/app/assets/images/)"
|
61
|
+
end
|
62
|
+
return assets
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
end
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redundant
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Graham Hadgraft
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-21 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Check which image assets are no longer used
|
15
|
+
email: graham.hadgrtaft@gmail.com
|
16
|
+
executables:
|
17
|
+
- redundant
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/redundant.rb
|
22
|
+
- bin/redundant
|
23
|
+
homepage: http://github.com/bitscraps/redundant
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 1.8.23
|
45
|
+
signing_key:
|
46
|
+
specification_version: 3
|
47
|
+
summary: Redundant!
|
48
|
+
test_files: []
|
49
|
+
has_rdoc:
|