Class: Rails::CssUnused::Report
- Inherits:
-
Object
- Object
- Rails::CssUnused::Report
- Defined in:
- lib/rails/css_unused/report.rb
Defined Under Namespace
Classes: Ghost
Instance Method Summary collapse
- #ghost_classes ⇒ Object
-
#initialize(root:, output: $stdout, config: CssUnused.configuration) ⇒ Report
constructor
A new instance of Report.
- #print_summary ⇒ Object
Constructor Details
#initialize(root:, output: $stdout, config: CssUnused.configuration) ⇒ Report
Returns a new instance of Report.
8 9 10 11 12 |
# File 'lib/rails/css_unused/report.rb', line 8 def initialize(root:, output: $stdout, config: CssUnused.configuration) @root = Pathname(root) @output = output @config = config end |
Instance Method Details
#ghost_classes ⇒ Object
14 15 16 17 18 |
# File 'lib/rails/css_unused/report.rb', line 14 def ghost_classes used = ViewScanner.new(root: @root, config: @config).used_classes defined = StylesheetScanner.new(root: @root, config: @config).defined_classes (defined - used).sort.map { |name| Ghost.new(class_name: name) } end |
#print_summary ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rails/css_unused/report.rb', line 20 def print_summary ghosts = ghost_classes used_count = ViewScanner.new(root: @root, config: @config).used_classes.size defined_count = StylesheetScanner.new(root: @root, config: @config).defined_classes.size @output.puts @output.puts "rails-css_unused — Ghost Class Report" @output.puts "=" * 40 @output.puts "Project root: #{@root}" @output.puts "Classes in stylesheets: #{defined_count}" @output.puts "Classes referenced in views: #{used_count}" @output.puts "Ghost classes (in CSS, not in views): #{ghosts.size}" @output.puts if ghosts.empty? @output.puts "No ghost classes found. Nice and tidy!" else @output.puts "Ghost classes:" ghosts.each { |g| @output.puts " #{g.class_name}" } end @output.puts @output.puts "Note: Dynamic class names and Tailwind utilities compiled at build time" @output.puts "may produce false positives. See README for configuration." @output.puts ghosts end |