Skip to content

Commit 67907a1

Browse files
committed
fix broken pseudo/nested
- turns out the env* had a lot more hidden context - fixed incorrect classnames being bandied about
1 parent 3bcb9e7 commit 67907a1

File tree

3 files changed

+26
-25
lines changed

3 files changed

+26
-25
lines changed

src/cljss/builder.clj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,22 @@
1313
nested (->> styles
1414
(filterv (comp not utils/pseudo?))
1515
(filterv utils/nested?))
16-
[mstatic mvals rule-index] (some-> styles :cljss.core/media ((partial build-media cls rule-index)))
16+
[mstatic mvals mrule-index] (some-> styles :cljss.core/media ((partial build-media cls rule-index)))
17+
rule-index (or mrule-index rule-index)
1718
styles (dissoc styles :cljss.core/media)
1819
styles (filterv #(and (not (utils/pseudo? %)) (not (utils/nested? %))) styles)
1920

2021
[static vals rule-index] (c/collect-styles cls styles rule-index)
2122
[pstyles rule-index] (c/collect-dynamic-styles
2223
rule-index
2324
pseudo
24-
(fn [rule] (str cls (subs (name rule) 1))))
25+
cls
26+
(fn [rule] (subs (name rule) 1)))
2527
[nstyles rule-index] (c/collect-dynamic-styles
2628
rule-index
2729
nested
28-
(fn [rule] (str cls " " rule)))
30+
cls
31+
(fn [rule] (str " " rule)))
2932

3033
vals (->> pstyles
3134
(mapcat second)

src/cljss/collect.clj

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,33 @@
88
(defn varid [cls idx [rule]]
99
[rule (str "--var-" cls "-" idx)])
1010

11-
(defn collect-styles [cls styles rule-index]
12-
(let [dynamic (filterv dynamic? styles)
13-
static (filterv (comp not dynamic?) styles)
14-
[vars rule-index] (reduce
15-
(fn [[vars idx] ds]
16-
(let [ret (conj vars (varid cls idx ds))]
17-
[ret (inc idx)]))
18-
[[] rule-index]
19-
dynamic)
20-
_ (println "static" static)
21-
_ (println "vars" vars)
22-
_ (println "dynamic" dynamic)
23-
vals (mapv (fn [[_ var] [_ exp]] [var exp]) vars dynamic)
24-
_ (println "vals" vals)
25-
static (->> vars
26-
(map (fn [[rule var]] [rule (str "var(" var ")")]))
27-
(concat static)
28-
(build-css cls))]
29-
[static vals rule-index]))
11+
(defn collect-styles
12+
([cls styles rule-index] (collect-styles cls styles rule-index nil))
13+
([cls styles rule-index tail-class]
14+
(let [dynamic (filterv dynamic? styles)
15+
static (filterv (comp not dynamic?) styles)
16+
[vars rule-index] (reduce
17+
(fn [[vars idx] ds]
18+
(let [ret (conj vars (varid cls idx ds))]
19+
[ret (inc idx)]))
20+
[[] rule-index]
21+
dynamic)
22+
vals (mapv (fn [[_ var] [_ exp]] [var exp]) vars dynamic)
23+
static (->> vars
24+
(map (fn [[rule var]] [rule (str "var(" var ")")]))
25+
(concat static)
26+
(build-css (str cls tail-class)))]
27+
[static vals rule-index])))
3028

31-
(defn collect-dynamic-styles [rule-index rules class-generator]
29+
(defn collect-dynamic-styles [rule-index rules cls tail-class-g]
3230
(loop
3331
[idx rule-index
3432
acc []
3533
coll rules]
3634
(if (not (seq coll))
3735
[acc idx]
3836
(let [[rule styles] (first coll)
39-
[static vals nxt-idx] (collect-styles (class-generator rule) styles idx)]
37+
[static vals nxt-idx] (collect-styles cls styles idx (tail-class-g rule))]
4038
(recur nxt-idx
4139
(conj acc [static vals])
4240
(rest coll))))))

src/cljss/media.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@
252252

253253
(defmethod compile-media :styles [{styles :styles} cls rule-index]
254254
(let [pseudo (filterv utils/pseudo? styles)
255-
[pstyles rule-index] (c/collect-dynamic-styles rule-index pseudo (fn [rule] (str cls (subs (name rule) 1))))
255+
[pstyles rule-index] (c/collect-dynamic-styles rule-index pseudo cls (fn [rule] (subs (name rule) 1)))
256256

257257
styles (filterv (comp not utils/pseudo?) styles)
258258
[static values rule-index] (c/collect-styles cls styles rule-index)

0 commit comments

Comments
 (0)