Tenderlove Making

More CSSPool Fun

I 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
  def start_selector(selectors)
    selectors.each { |sel| p sel if sel =~ @node }
parser = CSS::SAC::Parser.new(DH.new(some_hpricot_node))

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.

« go back