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

Migrate to a newer version of garden #21

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

:dependencies [[org.clojure/clojure "1.10.0"]
[org.clojure/clojurescript "1.10.520"]
[garden "1.3.10"]
[com.lambdaisland/garden "1.5.569"]
[net.cgrand/macrovich "0.2.1"]]

:plugins [[lein-figwheel "0.5.19"]
Expand Down
17 changes: 12 additions & 5 deletions src/spade/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#?@(:clj [[garden.stylesheet]
[net.cgrand.macrovich :as macros]
[spade.runtime]])
[spade.util :refer [factory->name build-style-name]]))
[spade.util :refer [factory->name build-style-name
unpack-keyframes-nesting]]))

(defn- extract-key [style]
(:key (meta (first style))))
Expand Down Expand Up @@ -169,10 +170,16 @@
style params style-name-var)
info-map (cond->
`{:css (when ~name-var
(spade.runtime/compile-css
(garden.stylesheet/at-keyframes
~name-var
~(or base-style-var (vec style)))))
~(if base-style-var
`(spade.runtime/compile-css
(apply garden.stylesheet/at-keyframes
~name-var
(#'unpack-keyframes-nesting ~base-style-var)))
`(spade.runtime/compile-css
(garden.stylesheet/at-keyframes
~name-var
~@style))))
:style ~(str (vec style))
:name ~name-var}

key-var (assoc ::key key-var))]
Expand Down
15 changes: 15 additions & 0 deletions src/spade/util.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,18 @@

; easiest case: no key is necessary
:else base))

(defn unpack-keyframes-nesting
"In the latest versions of garden, using [:&] to return multiple
style rules from within a conditional or other structure like
`(let)` in an `(at-keyframes)` structure keeps that `&` in the
output CSS. This function 'unpacks' such structures so the compiled CSS is clean."
[style-rules]
(mapcat
(fn maybe-unpack-keyframes-nesting [style-rule]
(if (and (vector? style-rule)
(= :& (first style-rule)))
(next style-rule)
[style-rule]))
style-rules))

Loading