diff --git a/frontend/src/app/main/ui/workspace/tokens/core.cljs b/frontend/src/app/main/ui/workspace/tokens/core.cljs index 682cefde4..695e364cb 100644 --- a/frontend/src/app/main/ui/workspace/tokens/core.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/core.cljs @@ -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}] diff --git a/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs b/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs index cecd0473d..f0d36dcef 100644 --- a/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs @@ -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] diff --git a/frontend/test/token_tests/token_core_test.cljs b/frontend/test/token_tests/token_core_test.cljs new file mode 100644 index 000000000..96e4321fd --- /dev/null +++ b/frontend/test/token_tests/token_core_test.cljs @@ -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...."))))