forked from helpshift/hydrox
/
core.clj
109 lines (99 loc) · 3.07 KB
/
core.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
(ns hydrox.core
(:require [hydrox.meta :as meta]
[hydrox.doc :as doc]
[hydrox.core.regulator :as regulator]
[hydrox.core.patch :as patch]
[hydrox.common.util :as util]
[hara.component :as component]
[clojure.java.io :as io]
[clojure.string :as string]))
(defn direct-path
[path file]
(if (string/ends-with? path "deps.edn")
(util/deps-read-project file)
(util/read-project file)))
(defn submerged?
"checks if dive has started"
{:added "0.1"}
([] (submerged? regulator/*running*))
([regs]
(if (empty? regs) false true)))
(defn single-use
"returns a working regulator for a given project file"
{:added "0.1"}
([] (single-use "deps.edn"))
([path]
(patch/patch-read-keyword)
(let [proj (direct-path path (io/file path))
folio (-> proj
(regulator/create-folio)
(regulator/init-folio))
state (atom folio)]
(regulator/regulator state proj))))
(defn import-docstring
"imports docstrings given a regulator"
{:added "0.1"}
([]
(if (submerged?)
(mapv #(import-docstring % :all) regulator/*running*)
(println "call `dive` first before running this function")))
([reg] (import-docstring reg :all))
([reg ns] (import-docstring reg ns nil))
([{:keys [state project] :as reg} ns var]
(let [{:keys [references]
lu :namespace-lu} @state]
(cond (= ns :all)
(doall (meta/import-project project references))
:else
(if-let [file (get lu ns)]
(if var
(meta/import-var file var references)
(meta/import-file file references)))))))
(defn purge-docstring
"purges docstrings given a regulator"
{:added "0.1"}
([]
(if (submerged?)
(mapv #(purge-docstring % :all) regulator/*running*)
(println "call `dive` first before running this function")))
([reg] (purge-docstring reg :all))
([reg ns] (purge-docstring reg ns nil))
([{:keys [state project] :as reg} ns var]
(let [{lu :namespace-lu} @state]
(cond (= ns :all)
(doall (meta/purge-project project))
:else
(if-let [file (get lu ns)]
(if var
(meta/purge-var file var)
(meta/purge-file file)))))))
(defn generate-docs
"generates html docs for :documentation entries in project.clj"
{:added "0.1"}
([]
(if (submerged?)
(mapv generate-docs regulator/*running*)
(println "call `dive` first before running this function")))
([{:keys [state] :as reg}]
(doc/render-all @state))
([{:keys [state] :as reg} name]
(doc/render-single @state name)))
(defn dive
"starts a dive"
{:added "0.1"}
([] (dive "deps.edn"))
([path] (dive path {}))
([path opts]
(patch/patch-read-keyword)
(->> (io/file path)
(direct-path path)
(merge opts)
(regulator/regulator)
(component/start))))
(defn surface
"finishes a dive"
{:added "0.1"}
([] (doseq [reg regulator/*running*]
(surface reg)))
([regulator]
(component/stop regulator)))