Skip to content

Instantly share code, notes, and snippets.

@pesterhazy
Last active April 22, 2016 14:48
Show Gist options
  • Save pesterhazy/556cf22a2b24c9a2984503e00cb92bb7 to your computer and use it in GitHub Desktop.
Save pesterhazy/556cf22a2b24c9a2984503e00cb92bb7 to your computer and use it in GitHub Desktop.
;; Display arbitrary EDN-like values in a browser
;;
;; See https://github.com/yogthos/json-html
;;
;; in project.clj / build.boot:
;; [json-html "0.3.9"]
;; [hiccup "1.0.5"]
(require '[json-html.core :as jh]
'[hiccup.page])
(defn pretty-edn-html [v fname]
(spit fname
(hiccup.page/html5
[:head [:style (-> "json.human.css" clojure.java.io/resource slurp)]]
[:div {:style "max-width: 900px"} (jh/edn->html v)])))
(defn browse
"Display an EDN-like value in the browser"
[v]
(let [fname (java.io.File/createTempFile "filename" ".html")]
(pretty-edn-html v fname)
(clojure.java.shell/sh "open" (.getAbsolutePath fname))
nil))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment