Skip to content

Instantly share code, notes, and snippets.

@Aitem
Last active October 27, 2020 10:52
Show Gist options
  • Save Aitem/64c47912c677b889e87d05132b230320 to your computer and use it in GitHub Desktop.
Save Aitem/64c47912c677b889e87d05132b230320 to your computer and use it in GitHub Desktop.
MACRO CSS
#?(: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