Skip to content

Commit 53cd180

Browse files
committed
Add generated API docs to documentation.
1 parent 7f29a74 commit 53cd180

File tree

6 files changed

+509
-398
lines changed

6 files changed

+509
-398
lines changed

django_unicorn/views/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -519,12 +519,12 @@ def message(request: HttpRequest, component_name: Optional[str] = None) -> JsonR
519519
Returns:
520520
`JsonRequest` with the following structure in the body:
521521
{
522-
"id": component_id,
523-
"dom": html, // re-rendered version of the component after actions in the payload are completed
524-
"data": {}, // updated data after actions in the payload are completed
525-
"errors": {}, // form validation errors
526-
"return": {}, // optional return value from an executed action
527-
"parent": {}, // optional representation of the parent component
522+
"id": component_id,
523+
"dom": html, # re-rendered version of the component after actions in the payload are completed
524+
"data": {}, # updated data after actions in the payload are completed
525+
"errors": {}, # form validation errors
526+
"return": {}, # optional return value from an executed action
527+
"parent": {} # optional representation of the parent component
528528
}
529529
"""
530530

django_unicorn/views/action_parsers/call_method.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from django_unicorn.utils import cast_value, get_method_arguments, get_type_hints
1313
from django_unicorn.views.action_parsers.utils import set_property_value
1414
from django_unicorn.views.objects import ComponentRequest, Return
15-
from django_unicorn.views.utils import set_property_from_data
1615

1716
try:
1817
from typing import get_origin
@@ -24,6 +23,9 @@ def get_origin(type_hint):
2423

2524

2625
def handle(component_request: ComponentRequest, component: UnicornView, payload: Dict):
26+
# Import here to prevent cyclic import
27+
from django_unicorn.views.utils import set_property_from_data
28+
2729
call_method_name = payload.get("name", "")
2830
if not call_method_name:
2931
raise AssertionError("Missing 'name' key for callMethod")

docs/source/conf.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# -- Project information -----------------------------------------------------
1717

1818
project = "Unicorn"
19-
copyright = "2021, Adam Hill" # noqa: A001
19+
copyright = "2023, Adam Hill" # noqa: A001
2020
author = "Adam Hill"
2121

2222
pyproject = toml.load("../../pyproject.toml")
@@ -32,14 +32,14 @@
3232
extensions = [
3333
"sphinx.ext.duration",
3434
"sphinx.ext.doctest",
35-
"sphinx.ext.autodoc",
3635
"sphinx.ext.autosummary",
3736
"sphinx.ext.intersphinx",
3837
"myst_parser",
3938
"sphinx_copybutton",
4039
"sphinx.ext.napoleon",
4140
"sphinx.ext.autosectionlabel",
4241
"rst2pdf.pdfbuilder",
42+
"autoapi.extension",
4343
]
4444

4545
intersphinx_mapping = {
@@ -79,3 +79,31 @@
7979
pdf_documents = [
8080
("index", "unicorn-latest", "Unicorn", "Adam Hill"),
8181
]
82+
83+
autoapi_dirs = [
84+
"../../django_unicorn",
85+
]
86+
autoapi_root = "api"
87+
autoapi_add_toctree_entry = False
88+
autoapi_generate_api_docs = True
89+
# autoapi_keep_files = True # useful for debugging generated errors
90+
autoapi_options = [
91+
"members",
92+
"undoc-members",
93+
"show-inheritance",
94+
]
95+
autoapi_type = "python"
96+
autodoc_typehints = "signature"
97+
98+
99+
def skip_member(app, what, name, obj, skip, options): # noqa: ARG001
100+
if what == "data" and name.endswith(".logger"):
101+
skip = True
102+
elif "startunicorn" in name:
103+
skip = True
104+
105+
return skip
106+
107+
108+
def setup(sphinx):
109+
sphinx.connect("autoapi-skip-member", skip_member)

docs/source/index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ Code repo <https://github.com/adamghill/django-unicorn>
7272
Sponsor <https://github.com/sponsors/adamghill>
7373
```
7474

75+
```{toctree}
76+
:caption: API
77+
:maxdepth: 3
78+
:hidden:
79+
80+
api/django_unicorn/index
81+
```
82+
7583
Want to add some component-based magic to your front-end, but don't need the overhead of a complete JavaScript front-end framework? `Unicorn` revolutionizes the way your users interact with your Django app! With `Unicorn`, you can create stunningly spiffy pages without ever leaving Python or your beloved Django codebase.
7684

7785
`Unicorn` is a reactive component framework that enhances your Django views by seamlessly making AJAX calls in the background and dynamically updates the HTML DOM. It's like magic, but better! `Unicorn` is leading the charge in bringing a component-based developer experience to Django. Join the `Unicorn` community today and unlock the power of reactivity!

0 commit comments

Comments
 (0)