Guest User

Untitled

a guest
May 1st, 2012
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #! /usr/local/bin/ruby
  2. require 'rubygems'
  3. require 'nokogiri'
  4. require 'css_parser'
  5. puts "Report of Unused CSS Rules\n---\nHTML Path:\t" + ARGV[0] + "\n"
  6. htmls = (`ack '' #{ARGV[0]} -l --type html`).split("\n").map { |html| Nokogiri::HTML(File.read(html)) }
  7. styles = (1..ARGV.length-1).inject(Array.new) { |a, i| a | (`ack '' #{ARGV[i]} -l --type css`).split("\n") }
  8. puts "\t- Checking " + htmls.length.to_s + " HTML file(s) against " + styles.length.to_s + " stylesheet(s)\n\n"
  9. styles.each do |style|
  10. puts "Stylesheet:\t" + style
  11. (css = CssParser::Parser.new).load_file!(style)
  12. css.each_selector do |sel, dec, spe|
  13. begin
  14. if (htmls.inject(false) { |a, html| a ||= html.css(sel).empty? }) then puts "\t- " + sel end
  15. rescue
  16. puts "\t- IGNORING: #{sel}"
  17. end
  18. end
  19. puts "\n"
  20. end
Advertisement
Add Comment
Please, Sign In to add comment