Skip to content

Commit 12f843e

Browse files
committed
Support docstrings, fix defined-garden
1 parent 26b1ef4 commit 12f843e

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
## Added
44

5+
- Support docstrings, they come after the tagname, before any styles or tokens
6+
57
## Fixed
68

7-
## Changed
9+
- Fix `defined-garden`
810

911
# 1.12.107 (2023-09-27 / 2444e34)
1012

src/lambdaisland/ornament.cljc

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@
570570
(defmacro defstyled [sym tagname & styles]
571571
(let [varsym (symbol (name (ns-name *ns*)) (name sym))
572572
css-class (classname-for varsym)
573+
[docstring & styles] (if (string? (first styles)) styles (cons nil styles))
573574
[styles fn-tails] (split-with (complement fn-tail?) styles)
574575
tag (if (keyword? tagname)
575576
tagname
@@ -651,7 +652,10 @@
651652
;; the component with the appropriate classes, it has no knowledge of the
652653
;; actual styles, which are expected to be rendered on the backend or
653654
;; during compilation.
654-
`(def ~(with-meta sym {::css true :ornament (dissoc (get @registry varsym) :component :fn-tails)})
655+
`(def ~(with-meta sym (cond-> {::css true
656+
:ornament (dissoc (get @registry varsym) :component :fn-tails)}
657+
docstring
658+
(assoc :doc docstring)))
655659
(styled '~varsym
656660
~css-class
657661
~tag
@@ -661,10 +665,11 @@
661665

662666
#?(:clj
663667
(defn defined-garden []
664-
(for [{:keys [css-class rules]} (->> @registry
665-
vals
666-
(sort-by :index))]
667-
(into [(str "." css-class)] (process-rules rules)))))
668+
(->> @registry
669+
vals
670+
(sort-by :index)
671+
(map (fn [{:keys [var tag rules classname]}]
672+
(as-garden (styled var classname tag rules nil)))))))
668673

669674
#?(:clj
670675
(defn defined-styles
@@ -676,18 +681,12 @@
676681
[& [{:keys [preflight? tw-version]
677682
:or {preflight? false
678683
tw-version 2}}]]
679-
;; Use registry, instead of inspecting metadata, for better cljs-only
680-
;; support
681-
(let [registry-css (->> @registry
682-
vals
683-
(sort-by :index)
684-
(map (fn [{:keys [var tag rules classname]}]
685-
(css (styled var classname tag rules nil)))))]
686-
(cond->> registry-css
687-
preflight? (into [(gc/compile-css (case tw-version
688-
2 girouette-preflight/preflight-v2_0_3
689-
3 girouette-preflight/preflight-v3_0_24))])
690-
:always (str/join "\n")))))
684+
(gc/compile-css
685+
{:pretty-print? false}
686+
(cond->> (defined-garden)
687+
preflight? (concat (case tw-version
688+
2 girouette-preflight/preflight-v2_0_3
689+
3 girouette-preflight/preflight-v3_0_24))))))
691690

692691
#?(:clj
693692
(defn cljs-restore-registry

0 commit comments

Comments
 (0)