Skip to content

Commit f3d7848

Browse files
committed
feat: support documenting member classes
1 parent 0a82948 commit f3d7848

File tree

2 files changed

+60
-9
lines changed

2 files changed

+60
-9
lines changed

quartodoc/builder/blueprint.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ def get_object_fixed(self, path, **kwargs):
126126
f" Does an object with the path {path} exist?"
127127
)
128128

129+
@staticmethod
130+
def _clean_member_path(path, new):
131+
if ":" in new:
132+
return new.replace(":", ".")
133+
134+
return new
135+
129136
@dispatch
130137
def visit(self, el):
131138
# TODO: use a context handler
@@ -205,8 +212,10 @@ def enter(self, el: Auto):
205212
pkg = self.crnt_package
206213
if pkg is None:
207214
path = el.name
215+
elif ":" in pkg or ":" in el.name:
216+
path = f"{pkg}.{el.name}"
208217
else:
209-
path = f"{pkg}.{el.name}" if ":" in el.name else f"{pkg}:{el.name}"
218+
path = f"{pkg}:{el.name}"
210219

211220
_log.info(f"Getting object for {path}")
212221

@@ -224,22 +233,27 @@ def enter(self, el: Auto):
224233
# but the actual objects on the target.
225234
# On the other hand, we've wired get_object up to make sure getting
226235
# the member of an Alias also returns an Alias.
227-
member_path = self._append_member_path(path, entry)
228-
obj_member = self.get_object_fixed(member_path, dynamic=dynamic)
236+
# member_path = self._append_member_path(path, entry)
237+
relative_path = self._clean_member_path(path, entry)
238+
239+
# create Doc element for member ----
240+
# TODO: when a member is a Class, it is currently created using
241+
# defaults, and there is no way to override those.
242+
doc = self.visit(Auto(name=relative_path, dynamic=dynamic, package=path))
229243

230244
# do no document submodules
231245
if (
232-
_is_external_alias(obj_member, obj.package)
233-
or obj_member.kind.value == "module"
246+
_is_external_alias(doc.obj, obj.package)
247+
or doc.obj.kind.value == "module"
234248
):
235249
continue
236250

237-
# create element for child ----
238-
doc = Doc.from_griffe(obj_member.name, obj_member)
251+
# obj_member = self.get_object_fixed(member_path, dynamic=dynamic)
252+
# doc = Doc.from_griffe(obj_member.name, obj_member)
239253

240254
# Case 1: make each member entry its own page
241255
if el.children == ChoicesChildren.separate:
242-
res = MemberPage(path=obj_member.path, contents=[doc])
256+
res = MemberPage(path=doc.obj.path, contents=[doc])
243257
# Case2: use just the Doc element, so it gets embedded directly
244258
# into the class being documented
245259
elif el.children in {ChoicesChildren.embedded, ChoicesChildren.flat}:
@@ -248,8 +262,9 @@ def enter(self, el: Auto):
248262
# if the page for the member is not created somewhere else, then it
249263
# won't exist in the documentation (but its summary will still be in
250264
# the table).
265+
# TODO: we shouldn't even bother blueprinting these members.
251266
elif el.children == ChoicesChildren.linked:
252-
res = Link(name=obj_member.path, obj=obj_member)
267+
res = Link(name=doc.obj.path, obj=doc.obj)
253268
else:
254269
raise ValueError(f"Unsupported value of children: {el.children}")
255270

quartodoc/tests/__snapshots__/test_renderers.ambr

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,24 @@
122122

123123
`tests.example.AClass()`
124124

125+
#### Attributes
126+
127+
| Name | Description |
128+
| --- | --- |
129+
| [a_attr](#quartodoc.tests.example.AClass.a_attr) | A class attribute |
130+
131+
#### Methods
132+
133+
| Name | Description |
134+
| --- | --- |
135+
| [a_method](#quartodoc.tests.example.AClass.a_method) | A method |
136+
137+
##### a_method { #quartodoc.tests.example.AClass.a_method }
138+
139+
`tests.example.AClass.a_method()`
140+
141+
A method
142+
125143
## Functions
126144

127145
| Name | Description |
@@ -159,6 +177,24 @@
159177

160178
`tests.example.AClass()`
161179

180+
### Attributes
181+
182+
| Name | Description |
183+
| --- | --- |
184+
| [a_attr](#quartodoc.tests.example.AClass.a_attr) | A class attribute |
185+
186+
### Methods
187+
188+
| Name | Description |
189+
| --- | --- |
190+
| [a_method](#quartodoc.tests.example.AClass.a_method) | A method |
191+
192+
#### a_method { #quartodoc.tests.example.AClass.a_method }
193+
194+
`tests.example.AClass.a_method()`
195+
196+
A method
197+
162198
## Functions
163199

164200
| Name | Description |

0 commit comments

Comments
 (0)