Refactor and improve how fields are displayed

This commit is contained in:
oakes
2014-03-31 01:01:06 -04:00
parent adfdb9bc95
commit 499ecf3fc7
2 changed files with 34 additions and 25 deletions

View File

@@ -5,27 +5,43 @@
[marginalia.core :as marg] [marginalia.core :as marg]
[play-clj-doclet.html :as html]) [play-clj-doclet.html :as html])
(:import [com.sun.javadoc ClassDoc ConstructorDoc Doc ExecutableMemberDoc (:import [com.sun.javadoc ClassDoc ConstructorDoc Doc ExecutableMemberDoc
Parameter RootDoc])) FieldDoc Parameter RootDoc]))
(def targets (-> "targets.edn" io/resource slurp edn/read-string)) (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 (defn parse-param
[^Parameter p] [^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 (defn parse-doc
[^Doc d] [^Doc d]
[(some-> (cond (merge {}
(isa? (type d) ConstructorDoc) (when-let [n (some-> (parse-doc-name d) camel->keyword)]
nil {:name n})
(isa? (type d) ClassDoc) (when (> (count (.commentText d)) 0)
(subs (.name d) (+ 1 (.lastIndexOf (.name d) "."))) {:text (.commentText d)})
:else (cond
(.name d)) (isa? (type d) ExecutableMemberDoc)
html/camel->keyword) {:args (->> d .parameters (map parse-param) vec)}
(.commentText d) (isa? (type d) FieldDoc)
(when (isa? (type d) ExecutableMemberDoc) {:args [[(-> d .type .typeName) "val"]]})))
(->> d .parameters (map parse-param) vec))])
(defn parse-class-entry (defn parse-class-entry
[^ClassDoc c type] [^ClassDoc c type]

View File

@@ -2,35 +2,28 @@
(:require [clojure.string :as string] (:require [clojure.string :as string]
[hiccup.core :refer :all])) [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 (defn param
[[type-name param-name]] [[type-name param-name]]
(html [:span {} (html [:span {}
[:span {:class "type-name"} "^" type-name] [:span {:class "type-name"} "^" type-name]
" " " "
(-> param-name camel->keyword name)])) param-name]))
(defn item (defn item
[[name text params]] [{:keys [name text args]}]
[:div [:div
[:p [:p
[:b (str name)] [:b (str name)]
" " " "
(string/join ", " (map param params))] (string/join ", " (map param args))]
(when (> (count text) 0) (when text [:i text])])
[:i text])])
(defn create-from-file (defn create-from-file
[parsed-file] [parsed-file]
(for [group (:groups parsed-file)] (for [group (:groups parsed-file)]
[:div [:div
[:h1 {} (:name group)] [:h1 {} (:name group)]
(:docstring group)
(for [[name items] (:java group)] (for [[name items] (:java group)]
[:div [:div
(when (not= (:name group) name) (when (not= (:name group) name)