mirror of
https://github.com/penpot/penpot.git
synced 2025-06-03 03:21:44 +02:00
Move over token value reference check function
This commit is contained in:
parent
d58932c2e5
commit
5de1f450c1
5 changed files with 24 additions and 13 deletions
|
@ -93,7 +93,7 @@ Token names should only contain letters and digits separated by . characters.")}
|
|||
|
||||
(defn token-self-reference?
|
||||
[token-name input]
|
||||
(let [token-references (wtt/find-token-references input)
|
||||
(let [token-references (ctob/find-token-value-references input)
|
||||
self-reference? (get token-references token-name)]
|
||||
self-reference?))
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
["@tokens-studio/sd-transforms" :as sd-transforms]
|
||||
["style-dictionary$default" :as sd]
|
||||
[app.common.logging :as l]
|
||||
[app.common.types.tokens-lib :as ctob]
|
||||
[app.main.refs :as refs]
|
||||
[app.main.ui.workspace.tokens.errors :as wte]
|
||||
[app.main.ui.workspace.tokens.tinycolor :as tinycolor]
|
||||
|
@ -85,7 +86,7 @@
|
|||
{:value value :unit (tinycolor/color-format tc)}
|
||||
{:errors [(wte/error-with-value :error.token/invalid-color value)]})
|
||||
(or (wtt/parse-token-value value)
|
||||
(if-let [references (-> (wtt/find-token-references value)
|
||||
(if-let [references (-> (ctob/find-token-value-references value)
|
||||
(seq))]
|
||||
{:errors [(wte/error-with-value :error.style-dictionary/missing-reference references)]
|
||||
:references references}
|
||||
|
|
|
@ -25,16 +25,6 @@
|
|||
(t/testing "doesnt accept invalid double"
|
||||
(t/is (nil? (wtt/parse-token-value ".3")))))
|
||||
|
||||
(t/deftest find-token-references
|
||||
(t/testing "finds references inside curly braces in a string"
|
||||
(t/is (= #{"foo" "bar"} (wtt/find-token-references "{foo} + {bar}")))
|
||||
(t/testing "ignores extra text"
|
||||
(t/is (= #{"foo.bar.baz"} (wtt/find-token-references "{foo.bar.baz} + something"))))
|
||||
(t/testing "ignores string without references"
|
||||
(t/is (nil? (wtt/find-token-references "1 + 2"))))
|
||||
(t/testing "handles edge-case for extra curly braces"
|
||||
(t/is (= #{"foo" "bar"} (wtt/find-token-references "{foo}} + {bar}"))))))
|
||||
|
||||
(t/deftest remove-attributes-for-token-id
|
||||
(t/testing "removes attributes matching the `token`, keeps other attributes"
|
||||
(t/is (= {:ry "b"}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue