0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-21 06:02:32 -05:00

Move json encode functionalities to tokens namespace

This commit is contained in:
Akshay Gupta 2024-06-24 17:50:24 +05:30
parent 0a73cbc6f1
commit 2b3f602312
No known key found for this signature in database
3 changed files with 16 additions and 15 deletions

View file

@ -273,12 +273,5 @@
(binding [cfeat/*current* cfeat/default-features]
(File. (fb/create-file name))))
(defn export-tokens-file [tokens-json]
(let [file-name "tokens.json"
file-content (json/encode-tokens tokens-json)
blob (wapi/create-blob (clj->js file-content) "application/json")]
(dom/trigger-download file-name blob)))
(defn exports []
#js {:createFile create-file-export
:exportTokens export-tokens-file})
#js {:createFile create-file-export})

View file

@ -18,6 +18,8 @@
[app.main.refs :as refs]
[app.main.store :as st]
[app.main.ui.workspace.tokens.style-dictionary :as sd]
[app.util.dom :as dom]
[app.util.webapi :as wapi]
[promesa.core :as p]))
;; Helpers ---------------------------------------------------------------------
@ -131,6 +133,18 @@
(dwsl/update-layout [shape-id] layout-update)))))
;; JSON export functions -------------------------------------------------------
(defn encode-tokens
[data]
(-> data
(clj->js)
(js/JSON.stringify nil 2)))
(defn export-tokens-file [tokens-json]
(let [file-name "tokens.json"
file-content (encode-tokens tokens-json)
blob (wapi/create-blob (clj->js file-content) "application/json")]
(dom/trigger-download file-name blob)))
(defn transform-tokens-into-json-format [tokens]
(let [grouped-tokens (group-by (comp keyword :type second) tokens)
map-token (fn [[_ token]]
@ -147,7 +161,7 @@
(defn download-tokens-as-json []
(let [all-tokens (deref refs/workspace-tokens)
transformed-tokens-json (transform-tokens-into-json-format all-tokens)]
(fb/export-tokens-file transformed-tokens-json)))
(export-tokens-file transformed-tokens-json)))
;; Token types -----------------------------------------------------------------

View file

@ -17,9 +17,3 @@
(-> data
(clj->js)
(js/JSON.stringify)))
(defn encode-tokens
[data]
(-> data
(clj->js)
(js/JSON.stringify nil 2)))