mirror of
https://github.com/status-im/reagent.git
synced 2025-01-26 03:39:21 +00:00
Allow Hiccup tags to be strings and symbols as well
This commit is contained in:
parent
ed4cf4e389
commit
b041427e94
@ -17,6 +17,15 @@
|
||||
|
||||
(def dont-camel-case #{"aria" "data"})
|
||||
|
||||
(defn hiccup-tag? [x]
|
||||
(or (keyword? x)
|
||||
(symbol? x)
|
||||
(string? x)))
|
||||
|
||||
(defn valid-tag? [x]
|
||||
(or (hiccup-tag? x)
|
||||
(ifn? x)))
|
||||
|
||||
(defn capitalize [s]
|
||||
(if (< (count s) 2)
|
||||
(string/upper-case s)
|
||||
@ -195,7 +204,7 @@
|
||||
wrapf))
|
||||
|
||||
(defn as-class [tag]
|
||||
(if (keyword? tag)
|
||||
(if (hiccup-tag? tag)
|
||||
(cached-wrapper tag)
|
||||
(do
|
||||
(let [cached-class (.-cljsReactClass tag)]
|
||||
@ -207,9 +216,7 @@
|
||||
|
||||
(defn vec-to-comp [v level]
|
||||
(assert (pos? (count v)) "Hiccup form should not be empty")
|
||||
(assert (let [tag (v 0)]
|
||||
(or (keyword? tag)
|
||||
(ifn? tag)))
|
||||
(assert (valid-tag? (v 0))
|
||||
(str "Invalid Hiccup form: " (pr-str v)))
|
||||
(let [props (get v 1)
|
||||
c (as-class (v 0))
|
||||
|
@ -284,3 +284,19 @@
|
||||
(as-string [:div [comp :foo]])))
|
||||
(is (re-find #"bardiv"
|
||||
(as-string [:div [comp :bar]])))))
|
||||
|
||||
(deftest symbol-string-tag []
|
||||
(is (re-find #"foobar"
|
||||
(as-string ['div "foobar"])))
|
||||
(is (re-find #"foobar"
|
||||
(as-string ["div" "foobar"])))
|
||||
(is (re-find #"id=.foo"
|
||||
(as-string ['div#foo "x"])))
|
||||
(is (re-find #"id=.foo"
|
||||
(as-string ["div#foo" "x"])))
|
||||
(is (re-find #"class=.foo bar"
|
||||
(as-string ['div.foo {:class "bar"}])))
|
||||
(is (re-find #"class=.foo bar"
|
||||
(as-string ["div.foo.bar"])))
|
||||
(is (re-find #"id=.foo"
|
||||
(as-string ['div#foo.foo.bar]))))
|
||||
|
Loading…
x
Reference in New Issue
Block a user