CSSPool

Sanitize your CSS

Strip out non standard properties:
sac = CSS::SAC::Parser.new puts sac.parse(File.read(ARGV[0])).to_css

Easily look up a CSS rule

sac = CSS::SAC::Parser.new css_doc = sac.parse(File.read(ARGV[0])) p css_doc['h1 > p']

Find styles matching an Hpricot node

sac = CSS::SAC::Parser.new css_doc = sac.parse(File.read(ARGV[0])) html_doc = Hpricot.parse(File.read(ARGV[1])) p_tag = html_doc.search('//p').first css_doc.rules_matching(p_tag).each do |rule| p rule end

Find all rules an HTML page uses

sac = CSS::SAC::Parser.new css_doc = sac.parse(File.read(ARGV[0])) html_doc = Hpricot.parse(File.read(ARGV[1])) css_doc.find_all_rules_matching(html_doc).each do |rule| p rule end

Find all rules an HTML page does not use

sac = CSS::SAC::Parser.new css_doc = sac.parse(File.read(ARGV[0])) html_doc = Hpricot.parse(File.read(ARGV[1])) (css_doc.rules - css_doc.find_all_rules_matching(html_doc)).each do |rule| p rule end

Implement your own document handler

class MyHandler < CSS::SAC::DocumentHandler def start_selector(selectors) p selectors end end sac = CSS::SAC::Parser.new(MyHandler.new()) css_doc = sac.parse(File.read(ARGV[0]))

Some Links