unused_view 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 Takatoshi Matsumoto
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # UnusedView
2
+ This is a Rails plugin to see unused views in you controllers
3
+
4
+ ## Usage
5
+ In your Gemfile.
6
+
7
+ ```ruby
8
+ group :development do
9
+ gem "unused_view"
10
+ end
11
+ ```
12
+
13
+ and execute rake task `unused_views`.
14
+
15
+ ```sh
16
+ # if you want to search unused views in path-to-rails-root/app/views
17
+ $ bundle exec rake unused_views
18
+ # if you want to search unused specific directory. e.g. path-to-rails-root/app/views/users
19
+ $ bundle exec rake 'unused_views[users]'
20
+ ```
21
+
22
+ then see list of unused views.
23
+
24
+ Now this is not support partial view.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'NotUsedView'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
@@ -0,0 +1,7 @@
1
+ module UnusedView
2
+ class Railtie < Rails::Railtie
3
+ rake_tasks do
4
+ load "unused_view/tasks.rake"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ desc "Show all unused views"
2
+ task :load_controllers => :environment do
3
+ puts "# Loading code in search of controllers"
4
+ Rails.application.eager_load!
5
+ end
6
+
7
+ task :unused_views, [ :path ] => :load_controllers do |task, args|
8
+ base_path = Rails.root.join('app').join('views').join(args[:path] || "")
9
+ puts "# Unused Views"
10
+ unused_views = UnusedView.find_all(base_path)
11
+ puts unused_views
12
+ end
@@ -0,0 +1,3 @@
1
+ module UnusedView
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,43 @@
1
+ require 'unused_view/railtie'
2
+
3
+ module UnusedView
4
+ extend self
5
+
6
+ def find_all(base_path)
7
+ Rails.application.instance_eval do
8
+ used_views = ApplicationController.descendants.reduce([]) do |views, controller_class|
9
+ controller = controller_class.new
10
+ views + UnusedView.find_views(controller).compact + [ UnusedView.find_layout(controller) ].compact
11
+ end.map(&:identifier).uniq
12
+
13
+ ApplicationController.view_paths.reduce([]) do |unused_views, view_path|
14
+ unused_views + Dir.glob(File.join(view_path, '**/[a-zA-Z]*')).select do |f|
15
+ File.file?(f) && used_views.exclude?(f) && f[%r{^#{base_path}}]
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ def find_views(controller)
22
+ controller.action_methods.map do |action|
23
+ controller.lookup_context.find(action, controller._prefixes) rescue nil
24
+ end
25
+ end
26
+
27
+ def find_layout(controller)
28
+ name = layout_name(controller)
29
+ if name
30
+ controller.lookup_context.find(name, 'layouts') rescue nil
31
+ end
32
+ end
33
+
34
+ def layout_name(controller)
35
+ name = controller.send(:_layout) rescue nil
36
+ case name
37
+ when String
38
+ name
39
+ when ActionView::Template
40
+ File.basename(name.identifier).split('.').first
41
+ end
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unused_view
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Takatoshi Matsumoto
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ type: :runtime
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3.2'
22
+ name: rails
23
+ prerelease: false
24
+ requirement: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.2'
30
+ - !ruby/object:Gem::Dependency
31
+ type: :development
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ name: sqlite3
39
+ prerelease: false
40
+ requirement: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ type: :development
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ name: rspec-rails
55
+ prerelease: false
56
+ requirement: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: This is a Rails plugin to see unused views in you controllers
63
+ email:
64
+ - toqoz403@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - lib/unused_view/railtie.rb
70
+ - lib/unused_view/tasks.rake
71
+ - lib/unused_view/version.rb
72
+ - lib/unused_view.rb
73
+ - MIT-LICENSE
74
+ - Rakefile
75
+ - README.md
76
+ homepage: http://github.com/ToQoz/unused_view
77
+ licenses: []
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ segments:
88
+ - 0
89
+ hash: -1427703622293713147
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ segments:
97
+ - 0
98
+ hash: -1427703622293713147
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 1.8.24
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: Rails plugin to see unused views
106
+ test_files: []