0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-22 14:39:45 -05:00

Simplify tranform tokens function

This commit is contained in:
Akshay Gupta 2024-06-24 20:44:08 +05:30
parent 29e3171bd9
commit ee057c498e
No known key found for this signature in database

View file

@ -134,9 +134,6 @@
(dwsl/update-layout [shape-id] layout-update))))) (dwsl/update-layout [shape-id] layout-update)))))
;; JSON export functions ------------------------------------------------------- ;; JSON export functions -------------------------------------------------------
(defn kebab-to-camel [token-type]
(let [parts (str/split token-type #"-")]
(apply str (first parts) (str/capital (second parts)))))
(defn encode-tokens (defn encode-tokens
[data] [data]
@ -151,15 +148,12 @@
(dom/trigger-download file-name blob))) (dom/trigger-download file-name blob)))
(defn transform-tokens-into-json-format [tokens] (defn transform-tokens-into-json-format [tokens]
(let [grouped-tokens (group-by #(keyword (:name (second %))) tokens) (let [global (reduce
map-token (fn [token] (fn [acc [_ {:keys [name value type]}]]
{:value (:value token) (assoc acc name {:value value
:type (kebab-to-camel (name (:type token)))})] :type (str/camel type)}))
{:global (into (sorted-map) (sorted-map) tokens)]
(map (fn [[name tokens]] {:global global}))
[(keyword name)
(map-token (second (first tokens)))])
grouped-tokens))}))
(defn download-tokens-as-json [] (defn download-tokens-as-json []
(let [all-tokens (deref refs/workspace-tokens) (let [all-tokens (deref refs/workspace-tokens)