More CSSPool Fun
Nov 15, 2007 @ 1:08 amI just finished up a matching method on CSSPool. So you can pass an hpricot node to a selector AST, and determine whether the node matches or not.
Lets say for example that you had an html document and a css document, and you wanted to know what selectors matched a given hpricot node, you could do something like this:
class DH < CSS::SAC::DocumentHandler
def initialize(node)
@node = node
end
def start_selector(selectors)
selectors.each { |sel| p sel if sel =~ @node }
end
end
parser = CSS::SAC::Parser.new(DH.new(some_hpricot_node))
parser.parse(File.read(ARGV[0]))
I think I will probably release what I have in trunk soon. I will probably add a new document handler for 0.2.0 that collects all selectors and properties together, and give a nice interface for finding styles that apply to an hpricot node.