Clean jsonml rendering code

This commit is contained in:
chris (daiyi) 2017-09-19 17:43:48 +02:00 committed by Daniel Compton
parent 4c5b4b8194
commit 5a832abab4

View File

@ -5,31 +5,6 @@
[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]
(->> (map #(str/split % #":") (str/split (get css-string "style") #";"))
(reduce (fn [acc [property value]]
@ -42,12 +17,6 @@
(= string ", ") " "
:else string))
(defn crawl
[data]
(if (coll? data)
(into (view data) (mapv crawl data))
(view data)))
(declare jsonml->hiccup)
(defn data-structure
@ -68,10 +37,11 @@
[jsonml]
(cond
(and (array? jsonml)
(= "object" (get jsonml 0))) [data-structure jsonml]
(= "object" (first jsonml))) [data-structure jsonml]
(array? jsonml) (mapv jsonml->hiccup jsonml)
(object? jsonml) {:style (string->css (js->clj jsonml))}
:else (str->hiccup jsonml)))
(or (string? jsonml)
(integer? jsonml)) (str->hiccup jsonml)))
(defn tab [data]
[:div {:style {:flex "1 0 auto" :width "100%" :height "100%" :display "flex" :flex-direction "column"}}