Last active
October 27, 2020 10:52
-
-
Save Aitem/64c47912c677b889e87d05132b230320 to your computer and use it in GitHub Desktop.
MACRO CSS
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
#?(:clj | |
(defonce styles (atom {}))) | |
#?(:clj | |
(defn gen-macro-css [stls] | |
(->> stls | |
(reduce-kv | |
(fn [acc k v] | |
(str acc "@import '" k "';\n")) | |
"") | |
(spit (str "build/css/app/macro.css"))))) | |
#?(:clj | |
(defn add-static-style [css-name hash] | |
(-> (swap! styles assoc css-name hash) | |
gen-macro-css))) | |
#?(:clj | |
(defmacro def-css | |
[css-name styles] | |
(let [file-path (str (str *ns*) "-" (name css-name) ".css") | |
class-name (keyword (str (name css-name) (hash styles)))] | |
(spit file-path (garden/css (into [(str "." class-name)] styles))) | |
(add-static-style file-path (hash styles)) | |
`(def ~css-name ~class-name)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment