Skip to content

Instantly share code, notes, and snippets.

@gfredericks
Created April 1, 2013 00:46
Show Gist options
  • Save gfredericks/5282642 to your computer and use it in GitHub Desktop.
Save gfredericks/5282642 to your computer and use it in GitHub Desktop.
css selector in laser
(let [re-1 #"([^#\.:]*)((?:[#\.][^#\.:]+)*)"
re-2 #"([#\.])([^#\.:]+)"]
(defn css
"Laser selector for css stuff. Just handles the AND format
of foo#bar.baz.bang, no ORing."
[s]
(let [[_ a b] (re-matches re-1 (name s))]
(assert (or (seq a) (seq b)) "Bad css selector.")
(apply l/and
(if (empty? a)
(constantly true)
(l/element= a))
(if (empty? b)
[]
(for [[_ type name] (re-seq re-2 b)]
((case type "#" l/id= "." l/class=)
name)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment