Skip to content

Commit

Permalink
Migrate to a newer version of garden (#21)
Browse files Browse the repository at this point in the history
* Migrate to the lambdaisland-maintained version of garden

* Fix support for complex defkeyframes in the latest garden version
  • Loading branch information
dhleong authored Nov 1, 2024
1 parent e3ee554 commit 22d87ce
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
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))

0 comments on commit 22d87ce

Please sign in to comment.