Created
April 1, 2013 00:46
-
-
Save gfredericks/5282642 to your computer and use it in GitHub Desktop.
css selector in laser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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