Skip to content

Commit 65cd666

Browse files
authored
Merge pull request #28 from machow/example-shiny
Example shiny
2 parents 801a181 + fbac16b commit 65cd666

File tree

19 files changed

+633
-73
lines changed

19 files changed

+633
-73
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ jobs:
7878
run: |
7979
python -m pip install -r requirements-dev.txt
8080
python -m pip install .
81+
python -m pip install shiny shinylive
8182
- uses: quarto-dev/quarto-actions/setup@v2
8283
- name: Build docs
8384
run: |

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ README.md: README.qmd
22
quarto render $<
33

44
examples/%/_site: examples/%/_quarto.yml
5-
python -m quartodoc build $<
5+
cd examples/$* \
6+
&& quarto add --no-prompt ../.. \
7+
&& quarto add --no-prompt quarto-ext/shinylive
8+
cd examples/$* && python -m quartodoc build _quarto.yml --verbose
9+
cd examples/$* && python -m quartodoc interlinks
610
quarto render $(dir $<)
711

812
docs/examples/%: examples/%/_site
913
rm -rf docs/examples/$*
1014
cp -rv $< $@
1115

12-
docs-build-examples: docs/examples/single-page docs/examples/pkgdown
16+
docs-build-examples: docs/examples/single-page docs/examples/pkgdown docs/examples/shiny
1317

1418
docs-build: docs-build-examples
1519
cd docs && quarto add --no-prompt ..

_extensions/interlinks/interlinks.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ def lookup_reference(self, ref: Ref):
4747
else:
4848
field_value = getattr(ref, field)
4949

50+
if field == "role":
51+
# for some reason, things like :func: are short for :function:.
52+
field_value = self.normalize_role(field_value)
53+
5054
crnt_items = _filter_by_field(crnt_items, field, field_value)
5155

5256
results = list(crnt_items)
@@ -65,6 +69,12 @@ def lookup_reference(self, ref: Ref):
6569

6670
return results[0]
6771

72+
def normalize_role(self, role_name):
73+
if role_name == "func":
74+
return "function"
75+
76+
return role_name
77+
6878

6979
global_inventory = Inventories()
7080

@@ -80,7 +90,12 @@ def get_path_to_root():
8090
# I have no idea how to get the documentation root,
8191
# except to get the path the extension script, which
8292
# lives in <root>/_extensions/interlinks, and work back
83-
return Path(__file__).parent.parent.parent
93+
p_root = Path(__file__).parent.parent.parent
94+
95+
if p_root.name == "_extensions":
96+
return p_root.parent
97+
98+
return p_root
8499

85100

86101
def load_inventories(interlinks: dict):
@@ -189,14 +204,8 @@ def parse_rst_style_ref(full_text):
189204
# Visitor ================================================================================
190205

191206

192-
@dispatch
193-
def visit(el, doc):
194-
return el
195-
# raise TypeError(f"Unsupported type: {type(el)}")
196-
207+
def prepare(doc: pf.Doc):
197208

198-
@dispatch
199-
def visit(el: pf.MetaList, doc):
200209
meta = doc.get_metadata()
201210

202211
try:
@@ -212,12 +221,13 @@ def visit(el: pf.MetaList, doc):
212221

213222
load_inventories(interlinks)
214223

215-
return el
224+
return doc
216225

217226

218227
@dispatch
219-
def visit(el: pf.Doc, doc):
228+
def visit(el, doc):
220229
return el
230+
# raise TypeError(f"Unsupported type: {type(el)}")
221231

222232

223233
# TODO: the syntax :ref:`target` is not trivial to implement. The pandoc AST
@@ -251,7 +261,7 @@ def visit(el: pf.Link, doc):
251261

252262

253263
def main(doc=None):
254-
return pf.run_filter(visit, doc=None)
264+
return pf.run_filter(visit, prepare=prepare, doc=None)
255265

256266

257267
if __name__ == "__main__":

docs/_quarto.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ project:
44
resources:
55
- examples/single-page
66
- examples/pkgdown
7+
- examples/shiny
8+
9+
metadata-files:
10+
- api/_sidebar.yml
711

812
filters:
913
- "interlinks"
@@ -12,11 +16,14 @@ interlinks:
1216
sources:
1317
python:
1418
url: https://docs.python.org/3/
19+
griffe:
20+
url: https://mkdocstrings.github.io/griffe/
1521

1622
quartodoc:
1723
style: pkgdown
1824
dir: api
1925
package: quartodoc
26+
sidebar: "api/_sidebar.yml"
2027
sections:
2128
- title: API Builders
2229
desc: |
@@ -83,7 +90,6 @@ website:
8390
- section: "Extra Topics"
8491
contents:
8592
- get-started/architecture.qmd
86-
- id: dummy
8793

8894

8995
format:

docs/examples/index.qmd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
| ----- | ------ | ------ |
33
| [pkgdown] | [github][pkgdown-code] | Index page with a title and short description for functions listed in each section. Each function gets its own documentation page. |
44
| [single-page] | [github][sp-code] | Index page has function documentation embedded on it. |
5+
| [shiny] | [github][shiny-code] | The shiny docs translated to quartodoc, using a custom renderer. |
56

67
: {tbl-colwidths="[20, 20, 60]"}
78

89
[pkgdown]: /examples/pkgdown/reference
910
[pkgdown-code]: https://github.com/machow/quartodoc/tree/main/examples/pkgdown
1011
[single-page]: /examples/single-page/reference
1112
[sp-code]: https://github.com/machow/quartodoc/tree/main/examples/single-page
13+
[shiny]: /examples/shiny/reference
14+
[shiny-code]: https://github.com/machow/quartodoc/tree/main/examples/shiny

docs/get-started/sidebar.qmd

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,31 @@
22
title: Sidebar navigation
33
---
44

5-
Currently, adding API reference pages to the left-hand sidebar requires manually
6-
listing each page in `_quarto.yml`. See the [quarto sidebar docs](https://quarto.org/docs/websites/website-navigation.html#side-navigation) for details.
5+
quartodoc can generate a sidebar on the lefthand side of the page, with a list of your functions.
76

8-
Generating sidebar entries is being tracked in [this quartodoc issue](https://github.com/machow/quartodoc/issues/20).
7+
In order to create a sidebar for your docs, add the following options to your `_quarto.yml`:
8+
9+
```yaml
10+
# tell quarto to read the sidebar file
11+
metadata-files:
12+
- _sidebar.yml
13+
14+
15+
# tell quartodoc to generate the sidebar file
16+
quartodoc:
17+
sidebar: "_sidebar.yml"
18+
# other options ...
19+
```
20+
21+
Note that running `python -m quartodoc build` will now produce a file called `_sidebar.yml`,
22+
with a [quarto sidebar configuration](https://quarto.org/docs/websites/website-navigation.html#side-navigation).
23+
The quarto [`metadata-files` option](https://quarto.org/docs/projects/quarto-projects.html#metadata-includes) ensures
24+
it's included with the configuration in `_quarto.yml`.
25+
26+
Here is what the sidebar for the [quartodoc reference page](/api) looks like:
27+
28+
<div class="sourceCode">
29+
<pre class="sourceCode yaml"><code class="sourceCode yaml">
30+
{{< include /api/_sidebar.yml >}}
31+
</code></pre>
32+
</div>

examples/pkgdown/reference/get_object.qmd

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
## get_object { #get_object }
22

3-
`get_object(module: str, object_name: str, parser: str = 'numpy')`
3+
`get_object(module, object_name, parser='numpy', load_aliases=True, modules_collection=None)`
44

55
Fetch a griffe object.
66

77
### Parameters
88

9-
| Name | Type | Description | Default |
10-
|---------------|--------|----------------------------|-----------|
11-
| `module` | str | A module name. | required |
12-
| `object_name` | str | A function name. | required |
13-
| `parser` | str | A docstring parser to use. | `'numpy'` |
9+
| Name | Type | Description | Default |
10+
|----------------------|---------------------------|------------------------------------------------------------------------------------|-----------|
11+
| `module` | str | A module name. | required |
12+
| `object_name` | str | A function name. | required |
13+
| `parser` | str | A docstring parser to use. | `'numpy'` |
14+
| `load_aliases` | | For aliases that were imported from other modules, should we load that module? | `True` |
15+
| `modules_collection` | None \| ModulesCollection | A griffe [](`~griffe.collections.ModulesCollection`), used to hold loaded modules. | `None` |
1416

15-
### See_Also
17+
### See Also
1618

1719
get_function: a deprecated function.
1820

examples/pkgdown/reference/preview.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## preview { #preview }
22

3-
`preview(ast: dc.Object | ds.Docstring | object, max_depth=999)`
3+
`preview(ast, max_depth=999)`
44

55
Print a friendly representation of a griffe object (e.g. function, docstring)
66

examples/shiny/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# vim
2+
.*.sw[po]
3+
4+
# quartodoc api folder
5+
reference
6+
7+
# quarto
8+
/.quarto/
9+
_site

0 commit comments

Comments
 (0)