lib/deadweight.rb in aanand-deadweight-0.0.2 vs lib/deadweight.rb in aanand-deadweight-0.0.3
- old
+ new
@@ -31,10 +31,17 @@
total_selectors += 1
unused_selectors << selector unless selector =~ ignore_selectors
end
end
+ # Remove selectors with pseudo classes that already have an equivalent
+ # without the pseudo class. Keep the ones that don't, we need to test
+ # them.
+ unused_selectors.reject! do |selector|
+ has_pseudo_classes(selector) && unused_selectors.include?(strip(selector))
+ end
+
pages.each do |page|
case page
when String
html = fetch(page)
else
@@ -51,11 +58,13 @@
doc = Hpricot(html)
found_selectors = []
unused_selectors.each do |selector|
- unless doc.search(selector).empty?
+ # We test against the selector stripped of any pseudo classes,
+ # but we report on the selector with its pseudo classes.
+ unless doc.search(strip(selector)).empty?
log.info(" #{selector}")
found_selectors << selector
end
end
@@ -84,14 +93,22 @@
log.warn("#{path} redirected to #{page.uri}") unless page.uri.to_s == loc
page.body
else
open(loc).read
end
- end
+ end
- private
+private
+ def has_pseudo_classes(selector)
+ selector =~ /::?[\w\-]+/
+ end
+
+ def strip(selector)
+ selector.gsub(/::?[\w\-]+/, '')
+ end
+
def log
@log ||= Logger.new(@log_file)
end
def initialize_agent
@@ -106,8 +123,8 @@
=================================================================
}
raise
end
- end
+ end
end