0
Fork 0
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:
Florian Schroedl 2024-06-28 13:34:54 +02:00
parent 6da855c741
commit ef5f019200
3 changed files with 24 additions and 0 deletions

View file

@ -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}]

View file

@ -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]

View 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...."))))