mirror of
https://github.com/penpot/penpot.git
synced 2025-02-07 23:08:24 -05:00
Move to token namespace
This commit is contained in:
parent
504369ec13
commit
2fa152d364
4 changed files with 28 additions and 26 deletions
|
@ -61,23 +61,6 @@
|
|||
(->> (map (fn [{:keys [name] :as token}] [name token]) tokens)
|
||||
(into {})))
|
||||
|
||||
(defn name->path
|
||||
"Splits token-name into a path vector split by `.` characters.
|
||||
|
||||
Will concatenate multiple `.` characters into one."
|
||||
[token-name]
|
||||
(str/split token-name #"\.+"))
|
||||
|
||||
(defn tokens-name-tree
|
||||
"Convert tokens into a nested tree with their `:name` as the path."
|
||||
[tokens]
|
||||
(reduce
|
||||
(fn [acc [_ {:keys [name] :as token}]]
|
||||
(when (string? name)
|
||||
(let [path (name->path name)]
|
||||
(assoc-in acc path token))))
|
||||
{} tokens))
|
||||
|
||||
(defn tokens-name-map-for-type
|
||||
"Convert tokens with `token-type` into a map with their `:name` as the key.
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
["style-dictionary$default" :as sd]
|
||||
[app.common.data :as d]
|
||||
[app.main.refs :as refs]
|
||||
[app.util.dom :as dom]
|
||||
[app.main.ui.workspace.tokens.token :as wtt]
|
||||
[cuerdas.core :as str]
|
||||
[promesa.core :as p]
|
||||
[rumext.v2 :as mf]
|
||||
|
@ -84,8 +84,7 @@
|
|||
|
||||
(defn resolve-tokens+
|
||||
[tokens & {:keys [debug?] :as config}]
|
||||
(p/let [sd-tokens (-> (wtc/tokens-name-tree tokens)
|
||||
(doto js/console.log)
|
||||
(p/let [sd-tokens (-> (wtt/token-names-tree tokens)
|
||||
(resolve-sd-tokens+ config))]
|
||||
(let [resolved-tokens (reduce
|
||||
(fn [acc ^js cur]
|
||||
|
|
20
frontend/src/app/main/ui/workspace/tokens/token.cljs
Normal file
20
frontend/src/app/main/ui/workspace/tokens/token.cljs
Normal file
|
@ -0,0 +1,20 @@
|
|||
(ns app.main.ui.workspace.tokens.token
|
||||
(:require
|
||||
[cuerdas.core :as str]))
|
||||
|
||||
(defn token-name->path
|
||||
"Splits token-name into a path vector split by `.` characters.
|
||||
|
||||
Will concatenate multiple `.` characters into one."
|
||||
[token-name]
|
||||
(str/split token-name #"\.+"))
|
||||
|
||||
(defn token-names-tree
|
||||
"Convert tokens into a nested tree with their `:name` as the path."
|
||||
[tokens]
|
||||
(reduce
|
||||
(fn [acc [_ {:keys [name] :as token}]]
|
||||
(when (string? name)
|
||||
(let [path (token-name->path name)]
|
||||
(assoc-in acc path token))))
|
||||
{} tokens))
|
|
@ -4,15 +4,15 @@
|
|||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns token-tests.token-core-test
|
||||
(ns token-tests.token-test
|
||||
(:require
|
||||
[app.main.ui.workspace.tokens.core :as wtc]
|
||||
[app.main.ui.workspace.tokens.token :as wtt]
|
||||
[cljs.test :as t :include-macros true]))
|
||||
|
||||
(t/deftest name->path-test
|
||||
(t/is (= ["foo" "bar" "baz"] (wtc/name->path "foo.bar.baz")))
|
||||
(t/is (= ["foo" "bar" "baz"] (wtc/name->path "foo..bar.baz")))
|
||||
(t/is (= ["foo" "bar" "baz"] (wtc/name->path "foo..bar.baz...."))))
|
||||
(t/is (= ["foo" "bar" "baz"] (wtt/token-name->path "foo.bar.baz")))
|
||||
(t/is (= ["foo" "bar" "baz"] (wtt/token-name->path "foo..bar.baz")))
|
||||
(t/is (= ["foo" "bar" "baz"] (wtt/token-name->path "foo..bar.baz...."))))
|
||||
|
||||
(t/deftest tokens-name-tree
|
||||
(t/is (= {"foo"
|
||||
|
@ -20,7 +20,7 @@
|
|||
{"baz" {:name "foo.bar.baz", :value "a"},
|
||||
"bam" {:name "foo.bar.bam", :value "b"}}},
|
||||
"baz" {"bar" {"foo" {:name "baz.bar.foo", :value "{foo.bar.baz}"}}}}
|
||||
(wtc/tokens-name-tree {:a {:name "foo.bar.baz"
|
||||
(wtt/token-names-tree {:a {:name "foo.bar.baz"
|
||||
:value "a"}
|
||||
:b {:name "foo.bar.bam"
|
||||
:value "b"}
|
Loading…
Add table
Reference in a new issue