Created
July 17, 2018 02:07
-
-
Save libkazz/ce3684310f66d61a94ed5906c4668f8b to your computer and use it in GitHub Desktop.
使われていない partial の簡易チェックスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def target_partial | |
Dir['app/views/front/{shared,sections,sidebar}/**/*'].each_with_object([]) do |f, list| | |
next unless File.file?(f) | |
list << [ | |
File.dirname(f).sub('app/views/', ''), | |
File.basename(f).sub(/^_/, '').sub('.slim', '').sub('.html.erb', '') | |
].join('/') | |
end | |
end | |
def rendereds(partial) | |
`git grep #{partial} app/views | grep render`.split("\n") | |
end | |
def partial_path(partial) | |
[ | |
'app/views', | |
File.dirname(partial), | |
"_#{File.basename(partial)}.slim" | |
].join('/') | |
end | |
puts <<~EOF | |
# Not rendered | |
# please run `git rm` | |
EOF | |
target_partial.each do |partial| | |
next if partial == 'front/shared/banner' | |
rendereds_count = rendereds(partial).count | |
puts "git rm #{partial_path(partial)}" if rendereds_count == 0 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment