mirror of
https://github.com/penpot/penpot.git
synced 2025-01-21 06:02:32 -05:00
Add helper utility to convert name to path
This commit is contained in:
parent
6da855c741
commit
ef5f019200
3 changed files with 24 additions and 0 deletions
|
@ -76,6 +76,12 @@
|
|||
(cond-> (assoc item :label name)
|
||||
(token-applied? item shape (or selected-attributes attributes)) (assoc :selected? true))))))
|
||||
|
||||
(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 #"\.+"))
|
||||
|
||||
;; Update functions ------------------------------------------------------------
|
||||
|
||||
(defn on-apply-token [{:keys [token token-type-props selected-shapes] :as _props}]
|
||||
|
|
|
@ -91,9 +91,12 @@
|
|||
(assoc-in acc name-path token))))
|
||||
{} tokens))
|
||||
|
||||
(tokens-name-tree @refs/workspace-tokens)
|
||||
|
||||
(defn resolve-tokens+
|
||||
[tokens & {:keys [debug?] :as config}]
|
||||
(p/let [sd-tokens (-> (tokens-name-tree tokens)
|
||||
(doto js/console.log)
|
||||
(resolve-sd-tokens+ config))]
|
||||
(let [resolved-tokens (reduce
|
||||
(fn [acc ^js cur]
|
||||
|
|
15
frontend/test/token_tests/token_core_test.cljs
Normal file
15
frontend/test/token_tests/token_core_test.cljs
Normal file
|
@ -0,0 +1,15 @@
|
|||
;; 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.token-core-test
|
||||
(:require
|
||||
[app.main.ui.workspace.tokens.core :as wtc]
|
||||
[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...."))))
|
Loading…
Add table
Reference in a new issue