forked from babashka/babashka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
portal.clj
executable file
·54 lines (43 loc) · 1.34 KB
/
portal.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env bb
(ns portal
(:require [babashka.deps :as deps]
[cheshire.core :as json]
[clj-yaml.core :as yaml]
[clojure.data.xml :as xml]
[clojure.edn :as edn]
[clojure.string :as str]))
(deps/add-deps '{:deps {djblue/portal {:mvn/version "0.9.0"}}})
(require '[portal.api :as p])
(.addShutdownHook (Runtime/getRuntime)
(Thread. (fn [] (p/close))))
(def file (first *command-line-args*))
(when-not file
(binding [*out* *err*]
(println "Usage: portal.clj <file.(edn|json|xml|yaml)>"))
(System/exit 1))
(defn xml->hiccup [xml]
(if-let [t (:tag xml)]
(let [elt [t]
elt (if-let [attrs (:attr xml)]
(conj elt attrs)
elt)]
(into elt (map xml->hiccup (:content xml))))
xml))
(def extension (last (str/split file #"\.")))
(def contents (slurp file))
(def data (case extension
("edn")
(edn/read-string contents)
("json")
(json/parse-string contents)
("yml" "yaml")
(yaml/parse-string contents)
("xml")
(-> (xml/parse-str contents
:skip-whitespace true
:namespace-aware false)
(xml->hiccup))))
(p/open)
(p/tap)
(tap> data)
@(promise)