Skip to content

Commit 8bd77ad

Browse files
committed
fix(docs): API reference generation logic
1 parent 5c8109c commit 8bd77ad

File tree

1 file changed

+82
-49
lines changed

1 file changed

+82
-49
lines changed

docs/generators/apiref.fsx

Lines changed: 82 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -88,50 +88,46 @@ let generateType ctx (page: ApiPageInfo<ApiDocEntity>) =
8888
b [] [!! "Assembly: "]
8989
!! t.Assembly.Name
9090
br []
91+
if not (String.IsNullOrWhiteSpace t.Category) then
92+
b [] [!! "Category: "]
93+
!!t.Category
94+
br []
95+
if not (t.Attributes.IsEmpty) then
96+
b [] [!! "Attributes: "]
97+
for a in t.Attributes do
98+
code [] [!! (a.Name)]
99+
br []
91100
br []
92101

93-
if not (t.AllMembers : ApiDocMember list).IsEmpty then
94-
b [] [!! "All Members"]
95-
table [] [
96-
tr [] [
97-
th [ Width "35%" ] [!!"Name"]
98-
th [ Width "65%"] [!!"Description"]
99-
]
100-
yield! t.AllMembers |> List.map formatMember
102+
table [] [
103+
tr [] [
104+
th [ Width "35%" ] [!!"Name"]
105+
th [ Width "65%"] [!!"Description"]
101106
]
102-
br []
107+
if not (t.Constructors : ApiDocMember list).IsEmpty then tr [] [ td [ColSpan 2. ] [ b [] [!! "Constructors"]]]
108+
yield! t.Constructors |> List.map formatMember
103109

104-
if not (t.Constructors : ApiDocMember list).IsEmpty then
105-
b [] [!! "Constructors"]
106-
table [] [
107-
tr [] [
108-
th [ Width "35%" ] [!!"Name"]
109-
th [ Width "65%"] [!!"Description"]
110-
]
111-
yield! t.Constructors |> List.map formatMember
112-
]
113-
br []
110+
if not (t.InstanceMembers : ApiDocMember list).IsEmpty then tr [] [ td [ColSpan 2. ] [ b [] [!! "Instance Members"]]]
111+
yield! t.InstanceMembers |> List.map formatMember
114112

115-
if not (t.InstanceMembers : ApiDocMember list).IsEmpty then
116-
b [] [!! "Instance Members"]
117-
table [] [
118-
tr [] [
119-
th [ Width "35%" ] [!!"Name"]
120-
th [ Width "65%"] [!!"Description"]
121-
]
122-
yield! t.InstanceMembers |> List.map formatMember
123-
]
124-
br []
113+
// Record Fields from AllMembers
114+
let recordFields = t.AllMembers |> List.filter (fun m -> m.Kind = ApiDocMemberKind.RecordField)
115+
if not recordFields.IsEmpty then tr [] [ td [ColSpan 2. ] [ b [] [!! "Record Fields"]]]
116+
yield! recordFields |> List.map formatMember
125117

126-
if not (t.StaticMembers : ApiDocMember list).IsEmpty then
127-
b [] [!! "Static Members"]
128-
table [] [
129-
tr [] [
130-
th [ Width "35%" ] [!!"Name"]
131-
th [ Width "65%"] [!!"Description"]
132-
]
133-
yield! t.StaticMembers |> List.map formatMember
134-
]
118+
if not (t.StaticMembers : ApiDocMember list).IsEmpty then tr [] [ td [ColSpan 2. ] [ b [] [!! "Static Members"]]]
119+
yield! t.StaticMembers |> List.map formatMember
120+
121+
// Static Parameters from AllMembers
122+
let staticParams = t.AllMembers |> List.filter (fun m -> m.Kind = ApiDocMemberKind.StaticParameter)
123+
if not staticParams.IsEmpty then tr [] [ td [ColSpan 2. ] [ b [] [!! "Static Parameters"]]]
124+
yield! staticParams |> List.map formatMember
125+
126+
// Union Cases from AllMembers
127+
let unionCases = t.AllMembers |> List.filter (fun m -> m.Kind = ApiDocMemberKind.UnionCase)
128+
if not unionCases.IsEmpty then tr [] [ td [ColSpan 2. ] [ b [] [!! "Union Cases"]]]
129+
yield! unionCases |> List.map formatMember
130+
]
135131
]
136132
t.UrlBaseName, Layout.layout ctx [body] t.Name
137133

@@ -147,16 +143,39 @@ let generateModule ctx (page: ApiPageInfo<ApiDocEntity>) =
147143
b [] [!! "Parent Module: "]
148144
a [Href ($"../%s{page.ParentUrlName}.html")] [!! page.ParentName]
149145
br []
146+
if not (String.IsNullOrWhiteSpace m.Category) then
147+
b [] [!! "Category: "]
148+
!!m.Category
149+
br []
150150
br []
151151

152-
if not (m.NestedEntities).IsEmpty then
153-
b [] [!! "Nested Modules"]
152+
// Split NestedEntities into types and modules
153+
let nestedTypes = m.NestedEntities |> List.filter (fun e -> e.IsTypeDefinition)
154+
let nestedModules = m.NestedEntities |> List.filter (fun e -> not e.IsTypeDefinition)
155+
156+
if not nestedTypes.IsEmpty then
157+
b [] [!! "Declared Types"]
158+
table [] [
159+
tr [] [
160+
th [ Width "35%" ] [!!"Type"]
161+
th [ Width "65%"] [!!"Description"]
162+
]
163+
for t in nestedTypes do
164+
tr [] [
165+
td [] [a [Href ($"%s{t.UrlBaseName}.html")] [!! t.Name ]]
166+
td [] [!! (getComment t.Comment)]
167+
]
168+
]
169+
br []
170+
171+
if not nestedModules.IsEmpty then
172+
b [] [!! "Declared Modules"]
154173
table [] [
155174
tr [] [
156175
th [ Width "35%" ] [!!"Module"]
157176
th [ Width "65%"] [!!"Description"]
158177
]
159-
for t in m.NestedEntities do
178+
for t in nestedModules do
160179
tr [] [
161180
td [] [a [Href ($"%s{t.UrlBaseName}.html")] [!! t.Name ]]
162181
td [] [!! (getComment t.Comment)]
@@ -187,29 +206,43 @@ let generateModule ctx (page: ApiPageInfo<ApiDocEntity>) =
187206
]
188207
m.UrlBaseName, Layout.layout ctx [body] m.Name
189208

190-
let generateNamespace ctx (n: ApiDocNamespace) =
209+
let generateNamespace ctx (ns: ApiDocNamespace) (allTypes: ApiPageInfo<ApiDocEntity> list) =
210+
let namespaceTypes = allTypes |> List.filter (fun t -> t.NamespaceName = ns.Name && t.ParentName = ns.Name)
211+
191212
let body =
192213
div [Class "api-page"] [
193-
h2 [] [!!n.Name]
214+
h2 [] [!!ns.Name]
194215

195-
// Instead of n.Types, get types from the AssemblyEntities that were precomputed
196-
let types = [] // We'll populate this differently since Types is not available directly
216+
if not namespaceTypes.IsEmpty then
217+
b [] [!! "Declared Types"]
218+
table [] [
219+
tr [] [
220+
th [ Width "35%" ] [!!"Type"]
221+
th [ Width "65%"] [!!"Description"]
222+
]
223+
for t in namespaceTypes do
224+
tr [] [
225+
td [] [a [Href ($"%s{t.Info.UrlBaseName}.html")] [!! t.Info.Name ]]
226+
td [] [!! (getComment t.Info.Comment)]
227+
]
228+
]
229+
br []
197230

198-
if not (n.Entities).IsEmpty then
231+
if not (ns.Entities).IsEmpty then
199232
b [] [!! "Declared Modules"]
200233
table [] [
201234
tr [] [
202235
th [ Width "35%" ] [!!"Module"]
203236
th [ Width "65%"] [!!"Description"]
204237
]
205-
for t in n.Entities do
238+
for t in ns.Entities do
206239
tr [] [
207240
td [] [a [Href ($"%s{t.UrlBaseName}.html")] [!! t.Name ]]
208241
td [] [!! (getComment t.Comment)]
209242
]
210243
]
211244
]
212-
n.Name, Layout.layout ctx [body] (n.Name)
245+
ns.Name, Layout.layout ctx [body] (ns.Name)
213246

214247

215248
let generate' (ctx : SiteContents) =
@@ -223,7 +256,7 @@ let generate' (ctx : SiteContents) =
223256
let name = n.GeneratorOutput.Collection.CollectionName
224257
let namespaces =
225258
n.GeneratorOutput.Collection.Namespaces
226-
|> List.map (generateNamespace ctx)
259+
|> List.map (fun ns -> generateNamespace ctx ns n.Types)
227260

228261
let modules =
229262
n.Modules

0 commit comments

Comments
 (0)