mirror of
https://github.com/status-im/re-frame-10x.git
synced 2025-01-11 22:54:14 +00:00
Clean jsonml rendering code
This commit is contained in:
parent
4c5b4b8194
commit
5a832abab4
@ -5,31 +5,6 @@
|
|||||||
|
|
||||||
[cljs.pprint :refer [pprint]]))
|
[cljs.pprint :refer [pprint]]))
|
||||||
|
|
||||||
(defn css-munge
|
|
||||||
[string]
|
|
||||||
(str/replace string #"\.|/" "-"))
|
|
||||||
|
|
||||||
(defn namespace-css
|
|
||||||
[classname]
|
|
||||||
(str "re-frame-trace--" classname))
|
|
||||||
|
|
||||||
(defn type-string
|
|
||||||
[obj]
|
|
||||||
(cond
|
|
||||||
(number? obj) "number"
|
|
||||||
(boolean? obj) "boolean"
|
|
||||||
(string? obj) "string"
|
|
||||||
(nil? obj) "nil"
|
|
||||||
(keyword? obj) "keyword"
|
|
||||||
(symbol? obj) "symbol"
|
|
||||||
:else (pr-str (type obj))))
|
|
||||||
|
|
||||||
(defn view
|
|
||||||
[data]
|
|
||||||
(if (coll? data)
|
|
||||||
[:div {:class (str (namespace-css "collection") " " (namespace-css (css-munge (type-string data))))}]
|
|
||||||
[:span {:class (str (namespace-css "primative") " " (namespace-css (css-munge (type-string data))))} (str data)]))
|
|
||||||
|
|
||||||
(defn string->css [css-string]
|
(defn string->css [css-string]
|
||||||
(->> (map #(str/split % #":") (str/split (get css-string "style") #";"))
|
(->> (map #(str/split % #":") (str/split (get css-string "style") #";"))
|
||||||
(reduce (fn [acc [property value]]
|
(reduce (fn [acc [property value]]
|
||||||
@ -42,12 +17,6 @@
|
|||||||
(= string ", ") " "
|
(= string ", ") " "
|
||||||
:else string))
|
:else string))
|
||||||
|
|
||||||
(defn crawl
|
|
||||||
[data]
|
|
||||||
(if (coll? data)
|
|
||||||
(into (view data) (mapv crawl data))
|
|
||||||
(view data)))
|
|
||||||
|
|
||||||
(declare jsonml->hiccup)
|
(declare jsonml->hiccup)
|
||||||
|
|
||||||
(defn data-structure
|
(defn data-structure
|
||||||
@ -68,10 +37,11 @@
|
|||||||
[jsonml]
|
[jsonml]
|
||||||
(cond
|
(cond
|
||||||
(and (array? jsonml)
|
(and (array? jsonml)
|
||||||
(= "object" (get jsonml 0))) [data-structure jsonml]
|
(= "object" (first jsonml))) [data-structure jsonml]
|
||||||
(array? jsonml) (mapv jsonml->hiccup jsonml)
|
(array? jsonml) (mapv jsonml->hiccup jsonml)
|
||||||
(object? jsonml) {:style (string->css (js->clj jsonml))}
|
(object? jsonml) {:style (string->css (js->clj jsonml))}
|
||||||
:else (str->hiccup jsonml)))
|
(or (string? jsonml)
|
||||||
|
(integer? jsonml)) (str->hiccup jsonml)))
|
||||||
|
|
||||||
(defn tab [data]
|
(defn tab [data]
|
||||||
[:div {:style {:flex "1 0 auto" :width "100%" :height "100%" :display "flex" :flex-direction "column"}}
|
[:div {:style {:flex "1 0 auto" :width "100%" :height "100%" :display "flex" :flex-direction "column"}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user