This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-08
Channels
- # announcements (2)
- # babashka (100)
- # beginners (25)
- # biff (7)
- # calva (13)
- # cider (24)
- # clj-kondo (39)
- # cljsrn (2)
- # clojure (22)
- # clojure-dev (13)
- # clojure-europe (12)
- # clojure-gamedev (3)
- # clojure-losangeles (2)
- # clojure-nl (1)
- # clojure-norway (3)
- # clojure-spec (11)
- # clojure-uk (2)
- # clojurescript (20)
- # core-async (8)
- # cursive (7)
- # data-science (2)
- # datomic (14)
- # emacs (6)
- # events (7)
- # fulcro (9)
- # honeysql (1)
- # kaocha (24)
- # lambdaisland (3)
- # leiningen (6)
- # lsp (30)
- # membrane (7)
- # missionary (10)
- # nbb (48)
- # nextjournal (13)
- # off-topic (6)
- # parinfer (4)
- # pathom (1)
- # polylith (1)
- # reagent (7)
- # rewrite-clj (6)
- # ring (11)
- # sci (7)
- # shadow-cljs (8)
- # sql (13)
is there any utility for converting a “tagless” hiccup keyword like :#foo.bar.baz
to {:id "#foo" :class "bar baz"}
I have a custom component that controls the “tag” part, but I still want to use the hiccup format for passing id and classes
cljs.user=> (.-id (reagent.impl.template/parse-tag :foo#bar.baz))
=> "bar"
cljs.user=> (.-className (reagent.impl.template/parse-tag :foo#bar.baz))
=> "baz"
cljs.user=> (cljs-bean.core/bean (reagent.impl.template/parse-tag :foo#bar.baz))
=> {:tag "foo", :id "bar", :className "baz", :custom false}
Something like this?If you want to make the tag optional you could achieve that with
(defn id-class [k]
(let [[?tag id className] (->> k name (re-matches #"([^\s\.#]+)?(?:#([^\s\.#]+))?(?:\.([^\s#]+))?") next)]
{:tag ?tag
:id id
:className (str/replace className #"\." " ")}))
(id-class :#foo.bar.baz)
=> {:tag nil, :id "foo", :className "bar baz"}
this is of course very easy to write— just wondering if people do this and if its builtin