Skip to content

Commit a75926a

Browse files
committed
feat: documenting classes on module pages
1 parent 7c50929 commit a75926a

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

quartodoc/renderers/md_renderer.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,13 @@ def render(self, el: Union[layout.DocClass, layout.DocModule]):
251251

252252
extra_parts = []
253253
meth_docs = []
254+
class_docs = []
255+
254256
if el.members:
255257
sub_header = "#" * (self.crnt_header_level + 1)
256258
raw_attrs = [x for x in el.members if x.obj.is_attribute]
257259
raw_meths = [x for x in el.members if x.obj.is_function]
260+
raw_classes = [x for x in el.members if x.obj.is_class]
258261

259262

260263
header = "| Name | Description |\n| --- | --- |"
@@ -267,30 +270,40 @@ def render(self, el: Union[layout.DocClass, layout.DocModule]):
267270
if (
268271
raw_attrs
269272
and not _has_attr_section(el.obj.docstring)
270-
and not isinstance(el, layout.DocClass)
273+
# TODO: what should backwards compat be?
274+
# and not isinstance(el, layout.DocClass)
271275
):
272276

273277
_attrs_table = "\n".join(map(self.summarize, raw_attrs))
274278
attrs = f"{sub_header} Attributes\n\n{header}\n{_attrs_table}"
275279
extra_parts.append(attrs)
280+
281+
# classes summary table ----
282+
if raw_classes:
283+
_summary_table = "\n".join(map(self.summarize, raw_classes))
284+
section_name = "Classes"
285+
objs = f"{sub_header} {section_name}\n\n{header}\n{_summary_table}"
286+
extra_parts.append(objs)
287+
288+
class_docs = [self.render(x) for x in raw_classes if isinstance(x, layout.Doc)]
276289

277290
# method summary table ----
278291
if raw_meths:
279-
_meths_table = "\n".join(map(self.summarize, raw_meths))
292+
_summary_table = "\n".join(map(self.summarize, raw_meths))
280293
section_name = (
281294
"Methods" if isinstance(el, layout.DocClass)
282295
else "Functions"
283296
)
284-
meths = f"{sub_header} {section_name}\n\n{header}\n{_meths_table}"
285-
extra_parts.append(meths)
297+
objs = f"{sub_header} {section_name}\n\n{header}\n{_summary_table}"
298+
extra_parts.append(objs)
286299

287300
# TODO use context manager, or context variable?
288301
n_incr = 1 if el.flat else 2
289302
with self._increment_header(n_incr):
290303
meth_docs = [self.render(x) for x in raw_meths if isinstance(x, layout.Doc)]
291304

292305
body = self.render(el.obj)
293-
return "\n\n".join([title, body, *extra_parts, *meth_docs])
306+
return "\n\n".join([title, body, *extra_parts, *meth_docs, *class_docs])
294307

295308
@dispatch
296309
def render(self, el: layout.DocFunction):

0 commit comments

Comments
 (0)