discover-unused-partials 0.0.2

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.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 PotHix and ViniBaggio
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.
@@ -0,0 +1,17 @@
1
+ == Description
2
+
3
+ This utility script (which someday will be a Rails plug-in) was made in order to
4
+ help developers to find out unused partials. Beware that dynamic named partials
5
+ (such as +render @post+ or render :partial => my_var) are NOT detected, so
6
+ you need to be careful while checking that list.
7
+
8
+
9
+ == Usage
10
+
11
+ To use this script, simply run it in your RAILS_ROOT. It will return a list of
12
+ unmentioned partials. It supports detection of Haml and Erb (both .erb and
13
+ .rhtml) templates.
14
+
15
+ === Thanks
16
+ Special thanks goes to Willian Molinari (PotHix) and Mateus Linhares
17
+ (mateuslinhares) that helped me writing this little script.
@@ -0,0 +1,31 @@
1
+ require 'jeweler'
2
+ require 'rubygems'
3
+ require 'rake'
4
+ require 'spec/rake/spectask'
5
+ require 'rake/rdoctask'
6
+
7
+ Spec::Rake::SpecTask.new(:spec) do |spec|
8
+ spec.libs << 'lib' << 'spec'
9
+ spec.spec_files = FileList['spec/**/*_spec.rb']
10
+ end
11
+
12
+ task :spec => :check_dependencies
13
+ task :default => :spec
14
+
15
+ Rake::RDocTask.new do |rdoc|
16
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
17
+
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = "discover-unused-partials #{version}"
20
+ rdoc.rdoc_files.include('README*')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
23
+
24
+ Jeweler::Tasks.new do |gemspec|
25
+ gemspec.name = "discover-unused-partials"
26
+ gemspec.summary = "Discover your unused partials"
27
+ gemspec.description = "A script to help you finding out unused partials. Good for big projects or projects under heavy refactoring"
28
+ gemspec.email = "vinibaggio@gmail.com"
29
+ gemspec.homepage = "http://github.com/vinibaggio/discover-unused-partials"
30
+ gemspec.authors = ["Vinicius Baggio", "Willian Molinari (a.k.a PotHix)"]
31
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'discover-unused-partials'
4
+ require 'optparse'
5
+
6
+ options = Hash.new
7
+ OptionParser.new do |opts|
8
+ opts.banner = "Usage: discover-unused-partials [options]"
9
+
10
+ opts.on_tail("-h", "--help", "Show this message") do
11
+ puts opts
12
+ exit
13
+ end
14
+
15
+ opts.parse!
16
+ end
17
+
18
+ DiscoverUnusedPartials::find_in options
@@ -0,0 +1,53 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{discover-unused-partials}
8
+ s.version = "0.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Vinicius Baggio", "Willian Molinari (a.k.a PotHix)"]
12
+ s.date = %q{2009-12-17}
13
+ s.default_executable = %q{discover-unused-partials}
14
+ s.description = %q{A script to help you finding out unused partials. Good for big projects or projects under heavy refactoring}
15
+ s.email = %q{vinibaggio@gmail.com}
16
+ s.executables = ["discover-unused-partials"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "bin/discover-unused-partials",
27
+ "discover-unused-partials.gemspec",
28
+ "lib/discover-unused-partials.rb",
29
+ "spec/discover-unused-partials_spec.rb",
30
+ "spec/spec.opts",
31
+ "spec/spec_helper.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/vinibaggio/discover-unused-partials}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.5}
37
+ s.summary = %q{Discover your unused partials}
38
+ s.test_files = [
39
+ "spec/spec_helper.rb",
40
+ "spec/discover-unused-partials_spec.rb"
41
+ ]
42
+
43
+ if s.respond_to? :specification_version then
44
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
48
+ else
49
+ end
50
+ else
51
+ end
52
+ end
53
+
@@ -0,0 +1,83 @@
1
+ module DiscoverUnusedPartials
2
+
3
+ def self.find_in directory
4
+ worker = PartialWorker.new
5
+
6
+ existent = worker.existent_partials("app").sort
7
+ used = worker.used_partials("app").sort
8
+
9
+ unless (existent & used) == existent
10
+ unused = (existent - used)
11
+ puts unused * "\n"
12
+ end
13
+ end
14
+
15
+ class PartialWorker
16
+
17
+ def existent_partials root
18
+ partials = []
19
+ each_file(root) do |file|
20
+ if file =~ /^.*\/_.*$/
21
+ partials << file.strip
22
+ end
23
+ end
24
+
25
+ partials.sort
26
+ end
27
+
28
+ def used_partials root
29
+ partials = []
30
+ each_file(root) do |file|
31
+ File.open(file) do |f|
32
+ f.each do |line|
33
+ line.strip!
34
+ if line =~ /:partial\s+=>\s+\"([a-zA-Z_\/]+)\"/
35
+ match = $1
36
+ if match[0] == ?/ or match[0] == '/'
37
+ match = match[1..-1]
38
+ end
39
+
40
+ if match.index("/")
41
+
42
+ path = match.split('/')[0...-1].join('/')
43
+ file_name = "_#{match.split('/')[-1]}"
44
+
45
+ full_path = "app/views/#{path}/#{file_name}"
46
+ else
47
+ if file =~ /app\/controllers\/(.*)_controller.rb/
48
+ full_path = "app/views/#{$1}/_#{match}"
49
+ else
50
+ full_path = "#{file.split('/')[0...-1].join('/')}/_#{match}"
51
+ end
52
+ end
53
+ partials << check_extension_path(full_path)
54
+ end
55
+ end
56
+ end
57
+ end
58
+ partials.uniq.sort
59
+ end
60
+
61
+ def check_extension_path(file)
62
+ if File.exists? file + ".html.erb"
63
+ file += ".html.erb"
64
+ elsif File.exists? file + ".html.haml"
65
+ file += ".html.haml"
66
+ else
67
+ file += ".rhtml"
68
+ end
69
+ file
70
+ end
71
+
72
+ def each_file(root, &block)
73
+ files = Dir.glob("#{root}/*")
74
+ files.each do |file|
75
+ if File.directory? file
76
+ each_file(file) {|file| yield file}
77
+ else
78
+ yield file
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "DiscoverUnusedPartials" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'discover-unused-partials'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: discover-unused-partials
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Vinicius Baggio
8
+ - Willian Molinari (a.k.a PotHix)
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-12-17 00:00:00 -02:00
14
+ default_executable: discover-unused-partials
15
+ dependencies: []
16
+
17
+ description: A script to help you finding out unused partials. Good for big projects or projects under heavy refactoring
18
+ email: vinibaggio@gmail.com
19
+ executables:
20
+ - discover-unused-partials
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - LICENSE
25
+ - README.rdoc
26
+ files:
27
+ - LICENSE
28
+ - README.rdoc
29
+ - Rakefile
30
+ - VERSION
31
+ - bin/discover-unused-partials
32
+ - discover-unused-partials.gemspec
33
+ - lib/discover-unused-partials.rb
34
+ - spec/discover-unused-partials_spec.rb
35
+ - spec/spec.opts
36
+ - spec/spec_helper.rb
37
+ has_rdoc: true
38
+ homepage: http://github.com/vinibaggio/discover-unused-partials
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options:
43
+ - --charset=UTF-8
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ requirements: []
59
+
60
+ rubyforge_project:
61
+ rubygems_version: 1.3.5
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: Discover your unused partials
65
+ test_files:
66
+ - spec/spec_helper.rb
67
+ - spec/discover-unused-partials_spec.rb