partial_inspector 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/partial_inspector/partial_tree.rb +70 -0
- data/lib/partial_inspector/reporter.rb +17 -0
- data/lib/partial_inspector/scanner.rb +5 -0
- data/lib/partial_inspector/used_partials.rb +0 -26
- data/lib/partial_inspector/utils.rb +26 -0
- data/lib/partial_inspector/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b01271288a1127081cd52384cec35879907aa6bf778d9c16c30760e37d5df700
|
4
|
+
data.tar.gz: 503dea0d0f53e11ddcab09d73f6eda69e6cb65dd52bbcbd9007c3d24e6ac016c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9ac5c9677eb732664821aa681e1fae7d6a7e35817371fd3f6b4a69e585e26fd5feaf4ecc9376c5f66211399c988c38379016fb571bdec1a84b2cd6404ae771f
|
7
|
+
data.tar.gz: d48cd66554591f92771c0fb9f1bdb26ec808ff66fc2ff6b20f17ae341c2cded972e2f6262017779ff9f6c8321b66f01bc5fadf4783300a73bcd515033b9ef532
|
data/README.md
CHANGED
@@ -34,6 +34,10 @@ gem install partial_inspector
|
|
34
34
|
```
|
35
35
|
PartialInspector.scanner.scan_unused_partials
|
36
36
|
```
|
37
|
+
2. Example Output
|
38
|
+
|
39
|
+
<img width="606" height="263" alt="image" src="https://github.com/user-attachments/assets/f7aef983-be65-4167-9703-810f29631a95" />
|
40
|
+
|
37
41
|
|
38
42
|
|
39
43
|
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require_relative 'utils'
|
2
|
+
|
3
|
+
module PartialInspector
|
4
|
+
module PartialTree
|
5
|
+
include PartialInspector::Utils
|
6
|
+
|
7
|
+
private
|
8
|
+
def data_to_build_tree(partial_path)
|
9
|
+
router(partial_path)
|
10
|
+
end
|
11
|
+
|
12
|
+
def router(path)
|
13
|
+
base_data = []
|
14
|
+
partial_path = path.split('/')[0]=='app' ? path.split('/')[2..-1].join('/') : path
|
15
|
+
files = find_base_files_rendering_partial(partial_path)
|
16
|
+
return [[path]] if files.empty?
|
17
|
+
files.each do |file|
|
18
|
+
if rendered_by_partial(file)
|
19
|
+
child_traces = router(file)
|
20
|
+
child_traces.each do |trace|
|
21
|
+
base_data << [path] + trace
|
22
|
+
end
|
23
|
+
else
|
24
|
+
base_data << [path, file]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
base_data
|
28
|
+
end
|
29
|
+
|
30
|
+
def find_base_files_rendering_partial(partial_path)
|
31
|
+
return [] if partial_path.nil? || partial_path == ''
|
32
|
+
base_files = []
|
33
|
+
|
34
|
+
files = Dir.glob("app/**/*.{rb,html.erb,js.erb,turbo_stream.erb}")
|
35
|
+
files.each do |file|
|
36
|
+
file_content = File.readlines(file)
|
37
|
+
file_content.each_with_index do |line, index|
|
38
|
+
if (line.include?('render') || line.include?('partial:')) && check_partial_exists(line, partial_path)
|
39
|
+
base_files << file
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
partial_dir = build_partial_base_dir_path(partial_path)
|
45
|
+
partial_name = extract_partial_name(partial_path)
|
46
|
+
|
47
|
+
base_files + find_base_files_rendering_partial_against_partial_name(partial_dir, partial_name)
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
def find_base_files_rendering_partial_against_partial_name(partial_dir, partial_name)
|
52
|
+
base_files = []
|
53
|
+
|
54
|
+
Dir.glob("app/views/#{partial_dir}*.*.erb").each do |file|
|
55
|
+
file_content = File.readlines(file)
|
56
|
+
file_content.each_with_index do |line, index|
|
57
|
+
if line.include?('render') && check_partial_exists(line, partial_name)
|
58
|
+
base_files << file
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
base_files
|
64
|
+
end
|
65
|
+
|
66
|
+
def rendered_by_partial(file)
|
67
|
+
file.split('/').last[0] == '_'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
require_relative "used_partials"
|
2
2
|
require_relative "unused_partials"
|
3
|
+
require_relative "partial_tree"
|
3
4
|
|
4
5
|
module PartialInspector
|
5
6
|
class Reporter
|
6
7
|
include PartialInspector::UsedPartials
|
7
8
|
include PartialInspector::UnusedPartials
|
9
|
+
include PartialInspector::PartialTree
|
8
10
|
|
9
11
|
def report_files_rendering_partial(partial_path)
|
10
12
|
files = base_scanner(partial_path)
|
@@ -46,5 +48,20 @@ module PartialInspector
|
|
46
48
|
end
|
47
49
|
return
|
48
50
|
end
|
51
|
+
|
52
|
+
def report_partial_tree(partial_path)
|
53
|
+
paths = data_to_build_tree(partial_path)
|
54
|
+
paths.each_with_index do |path, index|
|
55
|
+
puts "\e[35mTREE #{index+1}\e[0m"
|
56
|
+
space = ""
|
57
|
+
path[1..-1].each do |sub_path|
|
58
|
+
puts "#{space}-> #{sub_path}"
|
59
|
+
space = space + "\t"
|
60
|
+
end
|
61
|
+
space=""
|
62
|
+
puts "\n"
|
63
|
+
end
|
64
|
+
return
|
65
|
+
end
|
49
66
|
end
|
50
67
|
end
|
@@ -29,32 +29,6 @@ module PartialInspector
|
|
29
29
|
lines + check_partial_against_name(partial_dir, partial_name)
|
30
30
|
end
|
31
31
|
|
32
|
-
def check_partial_exists(line, partial)
|
33
|
-
partial_path = ""
|
34
|
-
line_content = line.split(' ')
|
35
|
-
line_content.each_with_index do |value, index|
|
36
|
-
if line.include?("render partial:") && value == "render"
|
37
|
-
partial_path = line_content[index + 2]
|
38
|
-
break
|
39
|
-
elsif value == "render"
|
40
|
-
partial_path = line_content[index + 1]
|
41
|
-
break
|
42
|
-
elsif value == "partial:"
|
43
|
-
partial_path = line_content[index + 1]
|
44
|
-
break
|
45
|
-
end
|
46
|
-
end
|
47
|
-
if partial_path[0] == "\""
|
48
|
-
partial_path = partial_path[1..-2]
|
49
|
-
partial_path = partial_path[0..-2] if partial_path[-1] == '"'
|
50
|
-
elsif partial_path[0] == "'"
|
51
|
-
partial_path = partial_path[1..-2]
|
52
|
-
partial_path = partial_path[0..-2] if partial_path[-1] == "'"
|
53
|
-
end
|
54
|
-
|
55
|
-
partial_path == partial
|
56
|
-
end
|
57
|
-
|
58
32
|
def build_path(path_components)
|
59
33
|
path = ''
|
60
34
|
path_components.each do |path_component|
|
@@ -24,5 +24,31 @@ module PartialInspector
|
|
24
24
|
|
25
25
|
path
|
26
26
|
end
|
27
|
+
|
28
|
+
def check_partial_exists(line, partial)
|
29
|
+
partial_path = ""
|
30
|
+
line_content = line.split(' ')
|
31
|
+
line_content.each_with_index do |value, index|
|
32
|
+
if line.include?("render partial:") && value == "render"
|
33
|
+
partial_path = line_content[index + 2]
|
34
|
+
break
|
35
|
+
elsif value == "render"
|
36
|
+
partial_path = line_content[index + 1]
|
37
|
+
break
|
38
|
+
elsif value == "partial:"
|
39
|
+
partial_path = line_content[index + 1]
|
40
|
+
break
|
41
|
+
end
|
42
|
+
end
|
43
|
+
if partial_path[0] == "\""
|
44
|
+
partial_path = partial_path[1..-2]
|
45
|
+
partial_path = partial_path[0..-2] if partial_path[-1] == '"'
|
46
|
+
elsif partial_path[0] == "'"
|
47
|
+
partial_path = partial_path[1..-2]
|
48
|
+
partial_path = partial_path[0..-2] if partial_path[-1] == "'"
|
49
|
+
end
|
50
|
+
|
51
|
+
partial_path == partial
|
52
|
+
end
|
27
53
|
end
|
28
54
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: partial_inspector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SalihaShahid
|
@@ -18,6 +18,7 @@ files:
|
|
18
18
|
- README.md
|
19
19
|
- Rakefile
|
20
20
|
- lib/partial_inspector.rb
|
21
|
+
- lib/partial_inspector/partial_tree.rb
|
21
22
|
- lib/partial_inspector/reporter.rb
|
22
23
|
- lib/partial_inspector/scanner.rb
|
23
24
|
- lib/partial_inspector/unused_partials.rb
|