Raynes / laser

HTML transformation/templating for people who do that sort of thing and stuff
120 stars 16 forks source link

`select` gives a cast exception when passed a zipper over a sequence of nodes #20

Closed gfredericks closed 11 years ago

gfredericks commented 11 years ago

Despite

=> (doc laser/zip)
-------------------------
me.raynes.laser/zip
([n])
  Get a zipper suitable for passing to fragment, document, or select, from
   a hickory node or a sequence of hickory nodes.

this happens (in version 1.1.1):

(let [html [{:type :element,
             :attrs {:class "post"},
             :tag :div,
             :content ["\n"]}]]
  (l/select (l/zip html)
            (l/class= "post_body")))

;; ClassCastException clojure.lang.LazySeq cannot be cast to clojure.lang.IFn  clojure.zip/end? (zip.clj:262)

Am I misunderstanding something? I find that is usually the case.

Raynes commented 11 years ago

You're applying select to a collection of zippers. You want to apply it to exactly one zipper. There is no 'fragment' equivalent for selectors. You're going to have to map it or something.

gfredericks commented 11 years ago

So should I change the docs for zip to say that it might return a sequence of zippers as well? As written it made me think that whatever it returned could be passed to select.

Raynes commented 11 years ago

That'd be good. I encourage you to do that a lot for things you don't understand. It's harder for me to document things that I clearly understand whereas they might come out clearer if written by someone who doesn't have quite as clear an understanding of it.