Skip to content

Instantly share code, notes, and snippets.

@piranha
Last active February 2, 2018 17:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piranha/d57c3201cab7285ceb73cba15daf162f to your computer and use it in GitHub Desktop.
Save piranha/d57c3201cab7285ceb73cba15daf162f to your computer and use it in GitHub Desktop.
(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