Fix keywords and symbols in :class

Fixes #367
This commit is contained in:
Juho Teperi 2018-04-27 23:19:59 +03:00
parent 4a8ac5cd83
commit 606b321d2f
2 changed files with 19 additions and 1 deletions

View File

@ -122,12 +122,14 @@
;; Merge classes
class
(assoc :class (let [old-class (:class props)]
(if (nil? old-class) class (str class " " old-class)))))))
(if (nil? old-class) class (str class " " (name old-class))))))))
(defn stringify-class [{:keys [class] :as props}]
;; (keep name) doesn't work because class vector could contain false, which is not Named
(if (coll? class)
(->> class
(filter identity)
(map name)
(string/join " ")
(assoc props :class))
props))

View File

@ -574,6 +574,22 @@
(is (= (rstr [:p {:class #{"a" "b" "c"}}])
(rstr [:p {:class "a b c"}]))))
(deftest class-named-values
(is (= (rstr [:p {:class :a}])
(rstr [:p {:class "a"}])))
(is (= (rstr [:p.a {:class :b}])
(rstr [:p {:class "a b"}])))
(is (= (rstr [:p.a {:class 'b}])
(rstr [:p {:class "a b"}])))
(is (= (rstr [:p {:class [:a :b]}])
(rstr [:p {:class "a b"}])))
(is (= (rstr [:p {:class ['a :b]}])
(rstr [:p {:class "a b"}])))
(testing "class collection can contain false value"
(is (= (rstr [:p {:class [:a :b false nil]}])
(rstr [:p {:class "a b"}])))) )
(deftest test-force-update
(let [v (atom {:v1 0
:v2 0})