Refactor and improve how fields are displayed
This commit is contained in:
@@ -5,27 +5,43 @@
|
||||
[marginalia.core :as marg]
|
||||
[play-clj-doclet.html :as html])
|
||||
(:import [com.sun.javadoc ClassDoc ConstructorDoc Doc ExecutableMemberDoc
|
||||
Parameter RootDoc]))
|
||||
FieldDoc Parameter RootDoc]))
|
||||
|
||||
(def targets (-> "targets.edn" io/resource slurp edn/read-string))
|
||||
|
||||
(defn camel->keyword
|
||||
[s]
|
||||
(->> (string/split (string/replace s "_" "-") #"(?<=[a-z])(?=[A-Z])")
|
||||
(map string/lower-case)
|
||||
(string/join "-")
|
||||
keyword))
|
||||
|
||||
(defn parse-param
|
||||
[^Parameter p]
|
||||
[(.typeName p) (.name p)])
|
||||
[(.typeName p) (-> (.name p) camel->keyword name)])
|
||||
|
||||
(defn parse-doc-name
|
||||
[^Doc d]
|
||||
(cond
|
||||
(isa? (type d) ConstructorDoc)
|
||||
nil
|
||||
(isa? (type d) ClassDoc)
|
||||
(subs (.name d) (+ 1 (.lastIndexOf (.name d) ".")))
|
||||
:else
|
||||
(.name d)))
|
||||
|
||||
(defn parse-doc
|
||||
[^Doc d]
|
||||
[(some-> (cond
|
||||
(isa? (type d) ConstructorDoc)
|
||||
nil
|
||||
(isa? (type d) ClassDoc)
|
||||
(subs (.name d) (+ 1 (.lastIndexOf (.name d) ".")))
|
||||
:else
|
||||
(.name d))
|
||||
html/camel->keyword)
|
||||
(.commentText d)
|
||||
(when (isa? (type d) ExecutableMemberDoc)
|
||||
(->> d .parameters (map parse-param) vec))])
|
||||
(merge {}
|
||||
(when-let [n (some-> (parse-doc-name d) camel->keyword)]
|
||||
{:name n})
|
||||
(when (> (count (.commentText d)) 0)
|
||||
{:text (.commentText d)})
|
||||
(cond
|
||||
(isa? (type d) ExecutableMemberDoc)
|
||||
{:args (->> d .parameters (map parse-param) vec)}
|
||||
(isa? (type d) FieldDoc)
|
||||
{:args [[(-> d .type .typeName) "val"]]})))
|
||||
|
||||
(defn parse-class-entry
|
||||
[^ClassDoc c type]
|
||||
|
||||
@@ -2,35 +2,28 @@
|
||||
(:require [clojure.string :as string]
|
||||
[hiccup.core :refer :all]))
|
||||
|
||||
(defn camel->keyword
|
||||
[s]
|
||||
(->> (string/split (string/replace s "_" "-") #"(?<=[a-z])(?=[A-Z])")
|
||||
(map string/lower-case)
|
||||
(string/join "-")
|
||||
keyword))
|
||||
|
||||
(defn param
|
||||
[[type-name param-name]]
|
||||
(html [:span {}
|
||||
[:span {:class "type-name"} "^" type-name]
|
||||
" "
|
||||
(-> param-name camel->keyword name)]))
|
||||
param-name]))
|
||||
|
||||
(defn item
|
||||
[[name text params]]
|
||||
[{:keys [name text args]}]
|
||||
[:div
|
||||
[:p
|
||||
[:b (str name)]
|
||||
" "
|
||||
(string/join ", " (map param params))]
|
||||
(when (> (count text) 0)
|
||||
[:i text])])
|
||||
(string/join ", " (map param args))]
|
||||
(when text [:i text])])
|
||||
|
||||
(defn create-from-file
|
||||
[parsed-file]
|
||||
(for [group (:groups parsed-file)]
|
||||
[:div
|
||||
[:h1 {} (:name group)]
|
||||
(:docstring group)
|
||||
(for [[name items] (:java group)]
|
||||
[:div
|
||||
(when (not= (:name group) name)
|
||||
|
||||
Reference in New Issue
Block a user