Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Use reagent components as parent & other small fixes #27

Draft
wants to merge 3 commits into
base: ornament-next
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions src/lambdaisland/ornament.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
props-registry
(atom {})))

#?(:clj
(defonce ^{:doc "Store of passed in custom options/tokens"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this about?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would store all the tokens set from different places and show the last overriden tokens. This means options like pretty-print? can then be accessed later in the ornament code.

options
(atom {:pretty-print? false})))

(def ^:dynamic *strip-prefixes*
"Prefixes to be stripped from class names in generated CSS"
nil)
Expand Down Expand Up @@ -103,29 +108,28 @@
- `:fonts`: map from keyword to font stack (comman separated string)
- `:components`: sequence of Girouette components, each a map with
`:id` (keyword), `:rules` (string, instaparse, can be omitted), and
`:garden` (map, or function taking instaparse results and returning Garden
map)
`:garden` (map, vector, or function; see below for details)
- `:tw-version`: which Girouette defaults to use, either based on Tailwind
v2, or v3. Valid values: 2, 3.

If `:rules` is omitted we assume this is a static token, and we'll
generate a rule of the form `token-id = <'token-id'>`.

`:garden` can be a function, in which case it receives a map with a
`:compoent-data` key containing the instaparse parse tree. Literal maps or
`:component-data` key containing the instaparse parse tree. Literal maps or
vectors are wrapped in a function, in case the returned Garden is fixed. The
resulting Garden styles are processed again as in `defstyled`, so you can use
other Girouette or other tokens in there as well. Use `[:&]` for returning
multiple tokens/maps/stylesUse `[:&]` for returning multiple
tokens/maps/styles.
multiple tokens/maps/styles.

By default these are added to the Girouette defaults, which are in terms
based on the Tailwind defaults. We still default to v2 (to avoid breaking
changes), but you can opt-in to Tailwind v3 by adding `:tw-version 3`. Use
meta-merge annotations (e.g. `{:colors ^:replace {...}}`) to change that
behaviour."
based on the Tailwind defaults. Use meta-merge annotations (e.g. `{:colors
^:replace {...}}`) to change that behaviour. We still default to v2 (to
avoid breaking changes), but you can opt-in to Tailwind v3 by adding
`:tw-version 3`."
[{:keys [components colors fonts tw-version]
:or {tw-version 2}}]
:or {tw-version 2}
:as configuration}]
(let [{:keys [components colors fonts]}
(meta-merge/meta-merge
(case tw-version
Expand All @@ -149,6 +153,7 @@
:fonts (into (empty fonts)
(map (juxt (comp name key) val))
fonts)})]
(swap! options merge configuration)
(reset! girouette-api
(girouette/make-api
components
Expand Down Expand Up @@ -480,7 +485,7 @@
(into [(str "." (classname this))]
(process-rules rules)))
(css [this] (gc/compile-css
{:pretty-print? false}
{:pretty-print? (:pretty-print? @options)}
(as-garden this)))
(rules [_] rules)
(tag [_] tag)
Expand Down Expand Up @@ -660,9 +665,11 @@
css-class (classname-for varsym)
[docstring & styles] (if (string? (first styles)) styles (cons nil styles))
[styles fn-tails] (split-with (complement fn-tail?) styles)
qualified-symbol (qualify-sym &env tagname)
tag (if (keyword? tagname)
tagname
(get-in @registry [(qualify-sym &env tagname) :tag]))
(or (get-in @registry [qualified-symbol :tag])
qualified-symbol))
rules (cond
(keyword? tagname)
(vec styles)
Expand Down
Loading