Created
July 2, 2017 12:17
-
-
Save YurySolovyov/834e9cd6258f36d6f333fd3d0806c238 to your computer and use it in GitHub Desktop.
class-names for ClojureScript
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
(defn class-names [& args] | |
(clojure.string/join " " | |
(mapv name | |
(reduce (fn [arr arg] | |
(cond | |
(or (string? arg) | |
(symbol? arg) | |
(keyword? arg)) (conj arr arg) | |
(vector? arg) (vec (concat arr arg)) | |
(map? arg) (vec (concat arr | |
(reduce-kv (fn [map-arr key value] | |
(if (true? value) | |
(conj map-arr key) | |
map-arr)) [] arg))) | |
:else arr)) [] args)))) | |
; (class-names "foo" "bar" :bax { :active true :seleced false }) | |
; -> "foo bar bax active" | |
; (class-names "foo" "bar" nil) | |
; -> "foo bar" | |
; (class-names "foo" "bar" :bax { :active true :seleced false } 'nox { :more-classes-in-map true }) | |
; -> "foo bar bax active nox more-classes-in-map" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment