Wepricot is now checked into the Subversion repository of its Google Code project. (Commit bits are available per email, or you can just clone it.) In it are some new features as well. DOMNodeList now includes Enumerable and gets a lot of neat methods and I’m using more idiomatic Ruby code in some places (would you believe I actually instantiated an array, looped through an enumerable and added results to that array instead of just collecting them?).
The big news, though, is that DOMNodeList and DOMNode now implement / and % (querySelectorAll and querySelector, respectively, with names that harken back to Hpricot). This wasn’t easy. The contract is for those to return their values in document order, and while that’s easy for a single node, you must order them for the set of results you get by querying every child node in a node list. Fortunately, I could wrap the relatively new compareDocumentPosition DOM method to do this.
Unfortunately, another part of the contract is that you return DOMNodeLists and nothing else. (I could probably bend this rule since this code would most likely not leave Ruby, and in Ruby it’s what you offer that matters, not how, but I’ve chosen not to right now since the type soup is already muddled.)
The way I’ve done this right now is to straight-up subclass DOMNodeList, but it’s not supposed to be subclassed. It holds one private field, which is some kind of opaque struct holding a bunch of private objects. I don’t fault it for that, but I have to override finalize with an empty body or it tries to release this struct, which I will remind you I haven’t allocated nor populated.
Or, to quote the code:
def finalize
# EMPTY
# UGLY UGLY UGLY
# HACK HACK HACK
[..]
This is the part where your feedback, or your interest in writing some code, comes in handy.