Skip to content

Commit 93132b6

Browse files
committed
Add generic help
1 parent 857a238 commit 93132b6

File tree

4 files changed

+29
-20
lines changed

4 files changed

+29
-20
lines changed

src/cljfx/dev.clj

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,8 @@
108108
(fn [x]
109109
(instance? c x)))
110110

111-
(defn- desc-of [c-sym]
112-
(fn [desc]
113-
(let [type (:fx/type desc)
114-
id (*type->id* type)]
115-
(if (nil? id)
116-
true
117-
(if-let [of (-> @registry :types id :of)]
118-
(cond
119-
(symbol? of) (isa? (resolve of) (resolve c-sym))
120-
(keyword? of) (recur (get desc of))
121-
:else (throw (ex-info (str "Unknown 'instance of' definition: " of)
122-
{:of of})))
123-
true)))))
124-
125111
(defmulti keyword-prop->spec-form :type)
112+
126113
(defn prop->spec-form [prop]
127114
(let [{:keys [type]} prop]
128115
(if (symbol? type)
@@ -153,9 +140,9 @@
153140
(apply register-type! id :spec (make-composite-spec id :req req) :of of (when req
154141
[:req req])))
155142

156-
(load "definitions")
143+
(load "dev/definitions")
157144

158-
(load "extensions")
145+
(load "dev/extensions")
159146

160147
(defmulti short-keyword-prop-help-string :type)
161148
(defmethod short-keyword-prop-help-string :default [{:keys [type]}]
@@ -173,9 +160,18 @@
173160
(str "Instance of:\n" type)
174161
(long-keyword-prop-help-syntax prop)))
175162

176-
(load "help")
163+
(load "dev/help")
177164

178165
(defn help
166+
([]
167+
(let [ts (->> @registry :types)]
168+
(println "Available cljfx types:")
169+
(println
170+
(str-table
171+
(->> ts keys (sort-by str))
172+
{:label "Cljfx type" :fn identity}
173+
{:label "Instance class" :fn #(let [of (:of (get ts %))]
174+
(if (symbol? of) (str of) ""))}))))
179175
([fx-type]
180176
(cond
181177
(or (keyword? fx-type) (qualified-symbol? fx-type))
@@ -244,10 +240,10 @@
244240
(println '???))))
245241

246242
;; next steps:
247-
;; 1. api for looking up type and prop information:
248-
;; - generic help?
249-
;; 2. dev cljfx type->lifecycle wrapper that validates and contextualizes errors
243+
;; 1. dev cljfx type->lifecycle wrapper that validates and contextualizes errors
250244
;; in terms of a cljfx component hierarchy
245+
;; 2. documentation
246+
;; 3. release on clojars
251247
;; stretch goals
252248
;; 3. ui reference for searching the props/types/etc
253249
;; 4. dev cljfx type->lifecycle wrapper that adds inspector capabilities.

src/cljfx/definitions.clj renamed to src/cljfx/dev/definitions.clj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@
4040
:instance (instance-of ~of)))
4141
(defmethod keyword-prop->spec-form :enum [{:keys [of]}]
4242
(enum-sym->spec-form of))
43+
(defn- desc-of [c-sym]
44+
(fn [desc]
45+
(let [type (:fx/type desc)
46+
id (*type->id* type)]
47+
(if (nil? id)
48+
true
49+
(if-let [of (-> @registry :types id :of)]
50+
(cond
51+
(symbol? of) (isa? (resolve of) (resolve c-sym))
52+
(keyword? of) (recur (get desc of))
53+
:else (throw (ex-info (str "Unknown 'instance of' definition: " of)
54+
{:of of})))
55+
true)))))
4356
(defmethod keyword-prop->spec-form :desc [{:keys [of]}]
4457
`(s/and (s/nonconforming :cljfx/desc) (desc-of '~of)))
4558
(defmethod keyword-prop->spec-form :string [_] `(s/spec string?))
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)