mirror of
https://github.com/penpot/penpot.git
synced 2025-02-25 08:16:49 -05:00
✨ Add improvements to css modules related macros
This commit is contained in:
parent
62f15f9b9d
commit
9804bd88c2
1 changed files with 25 additions and 8 deletions
|
@ -15,9 +15,18 @@
|
||||||
(def ^:dynamic *css-data* nil)
|
(def ^:dynamic *css-data* nil)
|
||||||
|
|
||||||
(def ^:private xform-css
|
(def ^:private xform-css
|
||||||
(map (fn [k]
|
(keep (fn [k]
|
||||||
(let [cn (name k)]
|
(cond
|
||||||
(or (get *css-data* (keyword cn)) cn)))))
|
(keyword? k)
|
||||||
|
(let [knm (name k)
|
||||||
|
kns (namespace k)]
|
||||||
|
(case kns
|
||||||
|
"global" knm
|
||||||
|
"old-css" (if (nil? *css-data*) knm "")
|
||||||
|
(or (get *css-data* (keyword knm)) knm)))
|
||||||
|
|
||||||
|
(string? k)
|
||||||
|
k))))
|
||||||
|
|
||||||
(defmacro css*
|
(defmacro css*
|
||||||
"Just coerces all params to strings and concats them with
|
"Just coerces all params to strings and concats them with
|
||||||
|
@ -35,7 +44,8 @@
|
||||||
(let [fname (-> *ns* meta :file)
|
(let [fname (-> *ns* meta :file)
|
||||||
path (str (subs fname 0 (- (count fname) 4)) "css.json")
|
path (str (subs fname 0 (- (count fname) 4)) "css.json")
|
||||||
data (-> (slurp (io/resource path))
|
data (-> (slurp (io/resource path))
|
||||||
(json/read-str :key-fn keyword))]
|
(json/read-str :key-fn keyword)
|
||||||
|
(or {}))]
|
||||||
|
|
||||||
(if (symbol? (first selectors))
|
(if (symbol? (first selectors))
|
||||||
`(if ~(with-meta (first selectors) {:tag 'boolean})
|
`(if ~(with-meta (first selectors) {:tag 'boolean})
|
||||||
|
@ -51,7 +61,8 @@
|
||||||
(let [fname (-> *ns* meta :file)
|
(let [fname (-> *ns* meta :file)
|
||||||
path (str (subs fname 0 (- (count fname) 4)) "css.json")]
|
path (str (subs fname 0 (- (count fname) 4)) "css.json")]
|
||||||
(-> (slurp (io/resource path))
|
(-> (slurp (io/resource path))
|
||||||
(json/read-str :key-fn keyword))))
|
(json/read-str :key-fn keyword)
|
||||||
|
(or {}))))
|
||||||
|
|
||||||
(def ^:private xform-css-case
|
(def ^:private xform-css-case
|
||||||
(comp
|
(comp
|
||||||
|
@ -59,8 +70,13 @@
|
||||||
(keep (fn [[k v]]
|
(keep (fn [[k v]]
|
||||||
(let [cls (cond
|
(let [cls (cond
|
||||||
(keyword? k)
|
(keyword? k)
|
||||||
(let [cn (name k)]
|
(let [knm (name k)
|
||||||
(or (get *css-data* (keyword cn)) cn))
|
kns (namespace k)]
|
||||||
|
(case kns
|
||||||
|
"global" knm
|
||||||
|
"old-css" (if (nil? *css-data*) knm "")
|
||||||
|
(or (get *css-data* (keyword knm)) knm)))
|
||||||
|
|
||||||
(string? k)
|
(string? k)
|
||||||
k)]
|
k)]
|
||||||
(when cls
|
(when cls
|
||||||
|
@ -75,7 +91,8 @@
|
||||||
(let [fname (-> *ns* meta :file)
|
(let [fname (-> *ns* meta :file)
|
||||||
path (str (subs fname 0 (- (count fname) 4)) "css.json")
|
path (str (subs fname 0 (- (count fname) 4)) "css.json")
|
||||||
data (-> (slurp (io/resource path))
|
data (-> (slurp (io/resource path))
|
||||||
(json/read-str :key-fn keyword))]
|
(json/read-str :key-fn keyword)
|
||||||
|
(or {}))]
|
||||||
|
|
||||||
(if (symbol? (first params))
|
(if (symbol? (first params))
|
||||||
`(if ~(with-meta (first params) {:tag 'boolean})
|
`(if ~(with-meta (first params) {:tag 'boolean})
|
||||||
|
|
Loading…
Add table
Reference in a new issue