Skip to content

Commit

Permalink
ns tree fns
Browse files Browse the repository at this point in the history
  • Loading branch information
zampino committed Aug 28, 2023
1 parent 7e07325 commit 28c09c9
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions notebooks/doc.clj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,28 @@
(when nss
(into [:div.ml-3] (map render-ns) nss))])

(defn branch-fn [nss-map ns-name]
(let [sub-nss (get nss-map ns-name)
vars (some-> ns-name symbol find-ns ns-publics not-empty vals vec)]
(cond-> {:name ns-name}
sub-nss (assoc :nss (mapv (partial branch-fn nss-map) sub-nss))
vars (assoc :vars vars))))

(defn ns-tree
([ns-matches]
(ns-tree (update-keys (group-by #(butlast (clojure.string/split % #"\.")) ns-matches)
(partial clojure.string/join "."))
ns-matches
[]))
([nss-map ns-matches acc]
(if-some [ns-name (first ns-matches)]
(recur nss-map
(remove #(str/starts-with? % ns-name) ns-matches)
(conj acc (branch-fn nss-map ns-name)))
acc)))

#_(ns-tree ns-matches)

^{::clerk/visibility {:result :show}}
(clerk/html
(let [ns-str (first ns-matches)]
Expand Down

0 comments on commit 28c09c9

Please sign in to comment.