|
| 1 | +--- |
| 2 | +title: Configuring content |
| 3 | +jupyter: |
| 4 | + kernelspec: |
| 5 | + display_name: Python 3 (ipykernel) |
| 6 | + language: python |
| 7 | + name: python3 |
| 8 | +--- |
| 9 | + |
| 10 | +Individual content entries (e.g. a function to be documented) can also be customized. |
| 11 | +For example, if you are documenting a python class, you may want to include or exclude |
| 12 | +documentation on specific methods on that class. |
| 13 | + |
| 14 | +Specify content options by setting `name: <content name>`, along with any additional options. |
| 15 | + |
| 16 | +For example, below is a piece of content, MdRenderer, specified without options. |
| 17 | + |
| 18 | +```yaml |
| 19 | +contents: |
| 20 | + - MdRenderer |
| 21 | +``` |
| 22 | +
|
| 23 | +We set it to only document its render method, by setting `name: MdRenderer` followed by the |
| 24 | +`members` option. |
| 25 | + |
| 26 | +```yaml |
| 27 | +contents: |
| 28 | + - name: MdRenderer |
| 29 | + members: |
| 30 | + - render |
| 31 | +``` |
| 32 | + |
| 33 | +Behind the scenes, quartodoc represents each content entry as a [](`quartodoc.Auto`) element, since it specifies how to automatically document some object. |
| 34 | + |
| 35 | +## Looking up objects |
| 36 | + |
| 37 | +Finding python objects to document involves two pieces of configuration: |
| 38 | + |
| 39 | +* the package name. |
| 40 | +* a list of objects for content. |
| 41 | + |
| 42 | +Note that quartodoc can look up anything---whether functions, modules, classes, attributes, or methods. |
| 43 | + |
| 44 | +```yaml |
| 45 | +quartodoc: |
| 46 | + package: quartodoc |
| 47 | + sections: |
| 48 | + - title: Some section |
| 49 | + desc: "" |
| 50 | + contents: |
| 51 | + - get_object # function: quartodoc.get_object |
| 52 | + - ast.preview # submodule func: quartodoc.ast.preview |
| 53 | + - MdRenderer # class: quartodoc.MdRenderer |
| 54 | + - MdRenderer.render # method: quartodoc.MDRenderer.render |
| 55 | + - renderers # module: quartodoc.renderers |
| 56 | +``` |
| 57 | + |
| 58 | +The functions listed in `contents` are assumed to be imported from the package. |
| 59 | + |
| 60 | +## Module and class members |
| 61 | + |
| 62 | +Documentation for modules and classes can automatically include their members (e.g. class methods and attributes; everything defined inside a module). |
| 63 | + |
| 64 | +There are four styles for presenting child members: |
| 65 | + |
| 66 | +```{python} |
| 67 | +#| echo: false |
| 68 | +#| output: asis |
| 69 | +
|
| 70 | +# print out the attributes table of ChoicesChildren |
| 71 | +# this is overkill, but maybe a nice case of dogfooding |
| 72 | +from quartodoc import get_object, MdRenderer |
| 73 | +from quartodoc.builder.utils import extract_type |
| 74 | +from griffe.docstrings.dataclasses import DocstringSectionAttributes |
| 75 | +
|
| 76 | +renderer = MdRenderer() |
| 77 | +choices = get_object("quartodoc.layout.ChoicesChildren") |
| 78 | +res = extract_type(DocstringSectionAttributes, choices.docstring.parsed)[0] |
| 79 | +
|
| 80 | +print(renderer.render(res)) |
| 81 | +``` |
| 82 | + |
| 83 | +You can specify a style by setting the `children` option in the config: |
| 84 | + |
| 85 | +```yaml |
| 86 | +quartodoc: |
| 87 | + package: quartodoc |
| 88 | + sections: |
| 89 | + - title: Some section |
| 90 | + desc: "" |
| 91 | + contents: |
| 92 | +
|
| 93 | + # set the children option, so that methods get documented |
| 94 | + # on separate pages. MdRenderer's docs will include a summary |
| 95 | + # table that links to each page. |
| 96 | + - name: quartodoc.MdRenderer |
| 97 | + children: separate |
| 98 | +``` |
| 99 | + |
| 100 | +## Grouping on a page |
| 101 | + |
| 102 | +By default, content in each section gets included in the same index table, |
| 103 | +with each piece of content documented on its own page. |
| 104 | + |
| 105 | +For example, consider the config below. |
| 106 | + |
| 107 | +```yaml |
| 108 | +quartodoc: |
| 109 | + package: quartodoc |
| 110 | + sections: |
| 111 | + - title: Cool functions |
| 112 | + desc: "" |
| 113 | + contents: |
| 114 | + - get_object |
| 115 | + - name: MdRenderer |
| 116 | + members: ["render"] |
| 117 | +``` |
| 118 | + |
| 119 | +Both `get_object` and `MdRenderer` will be: |
| 120 | + |
| 121 | +* summarized and linked to in the "Cool functions" section of the index. |
| 122 | +* documented on their own, separate pages. |
| 123 | + |
| 124 | +### Page layout element |
| 125 | + |
| 126 | +Use a custom page element to group object documentation on the same page. |
| 127 | + |
| 128 | +Custom page elements are specified by including a `kind: <element name>` field. |
| 129 | + |
| 130 | +:::::: {.columns} |
| 131 | + |
| 132 | + |
| 133 | +::: {.column} |
| 134 | + |
| 135 | +**Separate** |
| 136 | + |
| 137 | +```yaml |
| 138 | +quartodoc: |
| 139 | + package: quartodoc |
| 140 | + sections: |
| 141 | + - title: Cool functions |
| 142 | + desc: "" |
| 143 | +
|
| 144 | + # normal contents setup ---- |
| 145 | + contents: |
| 146 | + - get_object |
| 147 | + - name: MdRenderer |
| 148 | + members: ["render"] |
| 149 | +``` |
| 150 | + |
| 151 | +::: |
| 152 | +::: {.column} |
| 153 | + |
| 154 | +**Grouped on same page** |
| 155 | + |
| 156 | +```yaml |
| 157 | +quartodoc: |
| 158 | + package: quartodoc |
| 159 | + sections: |
| 160 | + - title: Cool functions |
| 161 | + desc: "" |
| 162 | +
|
| 163 | + # contents with a page grouping ---- |
| 164 | + contents: |
| 165 | + - kind: page |
| 166 | + contents: |
| 167 | + - get_object |
| 168 | + - name: MdRenderer |
| 169 | + members: ["render"] |
| 170 | +``` |
| 171 | + |
| 172 | +::: |
| 173 | +:::::: |
0 commit comments