Module: DiscoverUnusedPartials

Defined in:
lib/discover-unused-partials.rb,
lib/discover-unused-partials/version.rb

Defined Under Namespace

Classes: PartialWorker

Constant Summary collapse

VERSION =
"0.3.5"

Class Method Summary collapse

Class Method Details

.find(options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/discover-unused-partials.rb', line 4

def self.find options={}
  worker = PartialWorker.new options
  tree, dynamic = Dir.chdir(options[:root]){ worker.used_partials("app") }

  tree.each do |idx, level|
    indent = " " * idx*2
    h_indent = idx == 1 ? "" : "\n" + " "*(idx-1)*2

    if idx == 1
      puts "#{h_indent}The following partials are not referenced directly by any code:"
    else
      puts "#{h_indent}The following partials are only referenced directly by the partials above:"
    end
    level[:unused].sort.each do |partial|
      puts "#{indent}#{partial}"
    end
  end

  unless dynamic.empty?
    puts "\n\nSome of the partials above (at any level) might be referenced dynamically by the following lines of code:"
    dynamic.sort.map do |file, lines|
      lines.each do |line|
        puts "  #{file}:#{line}"
      end
    end
  end
end