mirror of
https://github.com/penpot/penpot.git
synced 2026-05-13 03:53:51 +00:00
📎 Add minor cosmetic reoriganization on tokens-lib
This commit is contained in:
parent
667a995e66
commit
e6ab57f719
@ -305,6 +305,35 @@
|
||||
(-clj->js [this]
|
||||
(clj->js (datafy this)))))
|
||||
|
||||
(def ^:private set-prefix "S-")
|
||||
|
||||
(def ^:private set-group-prefix "G-")
|
||||
|
||||
(def ^:private set-separator "/")
|
||||
|
||||
(defn get-set-path
|
||||
[token-set]
|
||||
(cpn/split-path (get-name token-set) :separator set-separator))
|
||||
|
||||
(defn split-set-name
|
||||
[name]
|
||||
(cpn/split-path name :separator set-separator))
|
||||
|
||||
(defn join-set-path [path]
|
||||
(cpn/join-path path :separator set-separator :with-spaces? false))
|
||||
|
||||
(defn normalize-set-name
|
||||
"Normalize a set name (ensure that there are no extra spaces, like ' group / set' -> 'group/set').
|
||||
|
||||
If `relative-to` is provided, the normalized name will preserve the same group prefix as reference name."
|
||||
([name]
|
||||
(-> (split-set-name name)
|
||||
(cpn/join-path :separator set-separator :with-spaces? false)))
|
||||
([name relative-to]
|
||||
(-> (concat (butlast (split-set-name relative-to))
|
||||
(split-set-name name))
|
||||
(cpn/join-path :separator set-separator :with-spaces? false))))
|
||||
|
||||
(defn token-set?
|
||||
[o]
|
||||
(instance? TokenSet o))
|
||||
@ -359,6 +388,7 @@
|
||||
(def check-token-set
|
||||
(sm/check-fn schema:token-set :hint "expected valid token set"))
|
||||
|
||||
|
||||
(defn map->token-set
|
||||
[& {:as attrs}]
|
||||
(TokenSet. (:id attrs)
|
||||
@ -377,35 +407,6 @@
|
||||
(check-token-set-attrs)
|
||||
(map->token-set)))
|
||||
|
||||
(def ^:private set-prefix "S-")
|
||||
|
||||
(def ^:private set-group-prefix "G-")
|
||||
|
||||
(def ^:private set-separator "/")
|
||||
|
||||
(defn get-set-path
|
||||
[token-set]
|
||||
(cpn/split-path (get-name token-set) :separator set-separator))
|
||||
|
||||
(defn split-set-name
|
||||
[name]
|
||||
(cpn/split-path name :separator set-separator))
|
||||
|
||||
(defn join-set-path [path]
|
||||
(cpn/join-path path :separator set-separator :with-spaces? false))
|
||||
|
||||
(defn normalize-set-name
|
||||
"Normalize a set name (ensure that there are no extra spaces, like ' group / set' -> 'group/set').
|
||||
|
||||
If `relative-to` is provided, the normalized name will preserve the same group prefix as reference name."
|
||||
([name]
|
||||
(-> (split-set-name name)
|
||||
(cpn/join-path :separator set-separator :with-spaces? false)))
|
||||
([name relative-to]
|
||||
(-> (concat (butlast (split-set-name relative-to))
|
||||
(split-set-name name))
|
||||
(cpn/join-path :separator set-separator :with-spaces? false))))
|
||||
|
||||
(defn normalized-set-name?
|
||||
"Check if a set name is normalized (no extra spaces)."
|
||||
[name]
|
||||
|
||||
@ -10,20 +10,26 @@
|
||||
[app.common.types.token :as cto]
|
||||
[clojure.test :as t]))
|
||||
|
||||
(t/deftest test-valid-token-name-schema
|
||||
(t/deftest test-valid-token-name
|
||||
;; Allow regular namespace token names
|
||||
(t/is (true? (sm/validate cto/schema:token-name "Foo")))
|
||||
(t/is (true? (sm/validate cto/schema:token-name "foo")))
|
||||
(t/is (true? (sm/validate cto/schema:token-name "FOO")))
|
||||
(t/is (true? (sm/validate cto/schema:token-name "Foo.Bar.Baz")))
|
||||
;; Disallow trailing tokens
|
||||
;; Allow $ inside or at the end of the name, but not at the beginning
|
||||
(t/is (true? (sm/validate cto/schema:token-name "Foo$Bar$Baz")))
|
||||
(t/is (true? (sm/validate cto/schema:token-name "Foo$Bar$Baz$")))
|
||||
(t/is (false? (sm/validate cto/schema:token-name "$Foo$Bar$Baz")))
|
||||
;; Disallow starting and trailing dots
|
||||
(t/is (false? (sm/validate cto/schema:token-name "....Foo.Bar.Baz")))
|
||||
(t/is (false? (sm/validate cto/schema:token-name "Foo.Bar.Baz....")))
|
||||
;; Disallow multiple separator dots
|
||||
(t/is (false? (sm/validate cto/schema:token-name "Foo..Bar.Baz")))
|
||||
;; Disallow any special characters
|
||||
(t/is (false? (sm/validate cto/schema:token-name "Hey Foo.Bar")))
|
||||
(t/is (false? (sm/validate cto/schema:token-name "Hey😈Foo.Bar")))
|
||||
(t/is (false? (sm/validate cto/schema:token-name "Hey%Foo.Bar"))))
|
||||
(t/is (false? (sm/validate cto/schema:token-name "HeyÅFoo.Bar")))
|
||||
(t/is (false? (sm/validate cto/schema:token-name "Hey%Foo.Bar")))
|
||||
(t/is (false? (sm/validate cto/schema:token-name "Hey / Foo/Bar"))))
|
||||
|
||||
|
||||
(t/deftest token-value-with-refs
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user