mirror of
https://github.com/penpot/penpot.git
synced 2025-01-21 06:02:32 -05:00
Move find-token-references to token namespace
This commit is contained in:
parent
252797183c
commit
980238e27b
5 changed files with 18 additions and 28 deletions
|
@ -92,7 +92,7 @@ Token names should only contain letters and digits separated by . characters.")}
|
|||
;; When creating a new token we dont have a token name yet,
|
||||
;; so we use a temporary token name that hopefully doesn't clash with any of the users token names.
|
||||
token-name (if (str/empty? name-value) "__TOKEN_STUDIO_SYSTEM.TEMP" name-value)
|
||||
token-references (sd/find-token-references input)
|
||||
token-references (wtt/find-token-references input)
|
||||
direct-self-reference? (get token-references token-name)]
|
||||
(cond
|
||||
empty-input? (p/rejected nil)
|
||||
|
|
|
@ -23,13 +23,6 @@
|
|||
|
||||
;; Functions -------------------------------------------------------------------
|
||||
|
||||
(defn find-token-references
|
||||
"Finds token reference values in `value-string` and returns a set with all contained namespaces."
|
||||
[value-string]
|
||||
(some->> (re-seq #"\{([^}]*)\}" value-string)
|
||||
(map second)
|
||||
(into #{})))
|
||||
|
||||
(defn tokens->style-dictionary+
|
||||
"Resolves references and math expressions using StyleDictionary.
|
||||
Returns a promise with the resolved dictionary."
|
||||
|
|
|
@ -4,6 +4,13 @@
|
|||
[clojure.set :as set]
|
||||
[cuerdas.core :as str]))
|
||||
|
||||
(defn find-token-references
|
||||
"Finds token reference values in `value-string` and returns a set with all contained namespaces."
|
||||
[value-string]
|
||||
(some->> (re-seq #"\{([^}]*)\}" value-string)
|
||||
(map second)
|
||||
(into #{})))
|
||||
|
||||
(defn token-identifier [{:keys [name] :as _token}]
|
||||
name)
|
||||
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns token-tests.style-dictionary-test
|
||||
(:require
|
||||
[app.main.ui.workspace.tokens.style-dictionary :as wtsd]
|
||||
[cljs.test :as t :include-macros true]))
|
||||
|
||||
(t/deftest test-find-token-references
|
||||
;; Return references
|
||||
(t/is (= #{"foo" "bar"} (wtsd/find-token-references "{foo} + {bar}")))
|
||||
;; Ignore non reference text
|
||||
(t/is (= #{"foo.bar.baz"} (wtsd/find-token-references "{foo.bar.baz} + something")))
|
||||
;; No references found
|
||||
(t/is (nil? (wtsd/find-token-references "1 + 2")))
|
||||
;; Edge-case: Ignore unmatched closing parens
|
||||
(t/is (= #{"foo" "bar"} (wtsd/find-token-references "{foo}} + {bar}"))))
|
|
@ -9,6 +9,16 @@
|
|||
[app.main.ui.workspace.tokens.token :as wtt]
|
||||
[cljs.test :as t :include-macros true]))
|
||||
|
||||
(t/deftest find-token-references
|
||||
;; Return references
|
||||
(t/is (= #{"foo" "bar"} (wtt/find-token-references "{foo} + {bar}")))
|
||||
;; Ignore non reference text
|
||||
(t/is (= #{"foo.bar.baz"} (wtt/find-token-references "{foo.bar.baz} + something")))
|
||||
;; No references found
|
||||
(t/is (nil? (wtt/find-token-references "1 + 2")))
|
||||
;; Edge-case: Ignore unmatched closing parens
|
||||
(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
Reference in a new issue