Last active
February 2, 2018 17:51
-
-
Save piranha/d57c3201cab7285ceb73cba15daf162f to your computer and use it in GitHub Desktop.
This file contains 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
(defmacro cx [& classes] | |
"This macro compiles this: | |
(cx :one true :two true :three false :four (pos? 1)) | |
Into this: | |
[ \"one two\", 1 > 0 ? \"four\" : null ].join(\" \") | |
" | |
(let [class-map# (partition 2 classes) | |
groups# (group-by (fn [[k v]] | |
(cond | |
(= v 'true) true | |
(= v 'false) false | |
:else nil)) | |
class-map#) | |
true-class# (get groups# true) | |
check-class# (get groups# nil)] | |
`(.join (cljs.core/array | |
~(str/join " " (map #(name (first %)) true-class#)) | |
~@(for [[class# test#] check-class#] | |
`(when ~test# ~(name class#)))) | |
" "))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment