Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom selector support #55

Open
OliverM opened this issue Jul 7, 2015 · 1 comment
Open

custom selector support #55

OliverM opened this issue Jul 7, 2015 · 1 comment

Comments

@OliverM
Copy link
Contributor

OliverM commented Jul 7, 2015

Custom selectors like the following work fine in Enlive but aren't supported in Kioo yet:

(defn text= [s] (pred #(= s (text %))))

Attempting to use text= in a kioo selector currently gives a null-pointer error on compilation.

@jaen
Copy link
Contributor

jaen commented Sep 2, 2015

If I remember how kioo works correctly then this is caused by symbols in selector being resolved inside net.cgrand.enlive-html- https://github.com/ckirkendall/kioo/blob/master/src/kioo/core.clj#L74-L75.
If your symbol isn't there it won't get resolved and you'll get a nil which causes the NPE.

A possible fix would be to leave a symbol as-is if resolve-enlive-var can't find it, for example like so:

(defn eval-selector [sel]
  (reduce
    (fn [sel-acc sel-frag]
      (conj sel-acc
          (cond
           (list? sel-frag) (apply (resolve-enlive-var (first sel-frag)) (eval-selector (rest sel-frag)))
           (or (vector? sel-frag)
               (map? sel-frag)
               (set? sel-frag)) (eval-selector sel-frag)
           (symbol? sel-frag) (if [resolved-var (resolve-enlive-var sel-frag)]
                                 resolved-var
                                 sel-frag)
            :else sel-frag)))
   (cond
    (vector? sel) []
    (set? sel) #{}
    (map? sel) {}
    :else []) sel))

Feel free to clone kioo and see if it works. If that doesn't help then the maintainer would have to step in and offer a suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants