@@ -181,6 +181,53 @@ def render(self, el: layout.Section):
181
181
body = list (map (self .render , el .contents ))
182
182
183
183
return "\n \n " .join ([section_top , * body ])
184
+
185
+ @dispatch
186
+ def render (self , el : layout .Interlaced ):
187
+ # render a sequence of objects with like-sections together.
188
+ # restrict its behavior to documenting functions for now ----
189
+ for doc in el .contents :
190
+ if not isinstance (doc , (layout .DocFunction , layout .DocAttribute )):
191
+ raise NotImplementedError (
192
+ "Can only render Interlaced elements if all content elements"
193
+ " are function or attribute docs."
194
+ f" Found an element of type { type (doc )} , with name { doc .name } "
195
+ )
196
+
197
+ # render ----
198
+ # currently, we use everything from the first function, and just render
199
+ # the signatures together
200
+ first_doc = el .contents [0 ]
201
+ objs = [doc .obj for doc in el .contents ]
202
+
203
+ if first_doc .obj .docstring is None :
204
+ raise ValueError ("The first element of Interlaced must have a docstring." )
205
+
206
+
207
+ str_title = self .render_header (first_doc )
208
+ str_sig = "\n \n " .join (map (self .signature , objs ))
209
+ str_body = []
210
+
211
+ # TODO: we should also interlace parameters and examples
212
+ # parsed = map(qast.transform, [x.docstring.parsed for x in objs if x.docstring])
213
+
214
+ # TODO: this is copied from the render method for dc.Object
215
+ for section in qast .transform (first_doc .obj .docstring .parsed ):
216
+ title = section .title or section .kind .value
217
+ body = self .render (section )
218
+
219
+ if title != "text" :
220
+ header = f"{ '#' * (self .crnt_header_level + 1 )} { title .title ()} "
221
+ str_body .append ("\n \n " .join ([header , body ]))
222
+ else :
223
+ str_body .append (body )
224
+
225
+ if self .show_signature :
226
+ parts = [str_title , str_sig , * str_body ]
227
+ else :
228
+ parts = [str_title , * str_body ]
229
+
230
+ return "\n \n " .join (parts )
184
231
185
232
@dispatch
186
233
def render (self , el : layout .Doc ):
@@ -226,7 +273,8 @@ def render(self, el: Union[layout.DocClass, layout.DocModule]):
226
273
extra_parts .append (meths )
227
274
228
275
# TODO use context manager, or context variable?
229
- with self ._increment_header (2 ):
276
+ n_incr = 1 if el .flat else 2
277
+ with self ._increment_header (n_incr ):
230
278
meth_docs = [self .render (x ) for x in raw_meths if isinstance (x , layout .Doc )]
231
279
232
280
body = self .render (el .obj )
@@ -311,7 +359,7 @@ def render(self, el: dc.Parameter):
311
359
elif has_default :
312
360
res = f"{ glob } { el .name } ={ el .default } "
313
361
else :
314
- res = el .name
362
+ res = f" { glob } { el .name } "
315
363
316
364
return sanitize (res )
317
365
@@ -477,6 +525,12 @@ def summarize(self, el: layout.Page):
477
525
def summarize (self , el : layout .MemberPage ):
478
526
# TODO: model should validate these only have a single entry
479
527
return self .summarize (el .contents [0 ], el .path , shorten = True )
528
+
529
+ @dispatch
530
+ def summarize (self , el : layout .Interlaced , * args , ** kwargs ):
531
+ rows = [self .summarize (doc , * args , ** kwargs ) for doc in el .contents ]
532
+
533
+ return "\n " .join (rows )
480
534
481
535
@dispatch
482
536
def summarize (self , el : layout .Doc , path : Optional [str ] = None , shorten : bool = False ):
0 commit comments