Skip to content

Commit 87dae23

Browse files
Add documentation for plugins (#188)
* Add documentation for plugins Add enhanced docstring for collect_component_assets hook and create plugin documentation add documentation for plugins * adjust imports
1 parent 408f101 commit 87dae23

File tree

4 files changed

+81
-2
lines changed

4 files changed

+81
-2
lines changed

.just/documentation.just

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ serve PORT="8000": cog
2828
[no-cd]
2929
[private]
3030
cog:
31-
uv run --with cogapp cog -r CONTRIBUTING.md docs/development/just.md
31+
uv run --with cogapp cog -r CONTRIBUTING.md docs/development/just.md docs/plugins.md

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Variables <vars>
1717
slots
1818
Assets <assets>
1919
Organization <organization>
20+
Plugins <plugins>
2021
configuration
2122
```
2223

docs/plugins.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Plugins
2+
3+
django-bird uses a plugin system based on [pluggy](https://pluggy.readthedocs.io/) to allow extending its functionality.
4+
5+
## Available Hooks
6+
7+
<!-- [[[cog
8+
from django.conf import settings
9+
10+
settings.configure(INSTALLED_APPS=["django_bird"])
11+
12+
import cog
13+
import inspect
14+
from django_bird.plugins import hookspecs
15+
from typing import get_type_hints
16+
17+
hook_functions = [
18+
obj for name, obj in inspect.getmembers(hookspecs)
19+
if inspect.isfunction(obj) and obj.__module__ == 'django_bird.plugins.hookspecs'
20+
]
21+
22+
for func in hook_functions:
23+
hints = get_type_hints(func)
24+
25+
params = []
26+
for name, hint in hints.items():
27+
if name != 'return':
28+
params.append(f"{name}: {hint.__module__}.{hint.__name__}")
29+
30+
return_type = hints['return']
31+
32+
full_sig = f"{func.__name__}({', '.join(params)}) -> {return_type}"
33+
34+
cog.outl(f"````{{py:function}} {full_sig}")
35+
cog.outl(f":canonical: django_bird.plugins.hookspecs.{func.__name__}\n")
36+
37+
if func.__doc__:
38+
cog.outl(f"```{{autodoc2-docstring}} django_bird.plugins.hookspecs.{func.__name__}")
39+
cog.outl(":parser: myst")
40+
cog.outl("```")
41+
42+
cog.outl("````\n")
43+
# ]]] -->
44+
````{py:function} collect_component_assets(template_path: pathlib.Path) -> collections.abc.Iterable[django_bird.staticfiles.Asset]
45+
:canonical: django_bird.plugins.hookspecs.collect_component_assets
46+
47+
```{autodoc2-docstring} django_bird.plugins.hookspecs.collect_component_assets
48+
:parser: myst
49+
```
50+
````
51+
52+
<!-- [[[end]]] -->
53+
54+
## Creating a Plugin
55+
56+
To create a plugin:
57+
58+
1. Create a Python package for your plugin
59+
2. Import the `django_bird.hookimpl` marker:
60+
61+
```python
62+
from django_bird import hookimpl
63+
```
64+
65+
3. Implement one or more hooks using the `@hookimpl` decorator.
66+
4. Register your plugin in your package's entry points:
67+
68+
```toml
69+
[project.entry-points."django_bird"]
70+
my_plugin = "my_plugin.module"
71+
```
72+
73+
See the [pluggy documentation](https://pluggy.readthedocs.io/) for more details.

src/django_bird/plugins/hookspecs.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@
1212

1313
@hookspec
1414
def collect_component_assets(template_path: Path) -> Iterable[Asset]:
15-
"""Collect all assets associated with a component."""
15+
"""Collect all assets associated with a component.
16+
17+
This hook is called for each component template to gather its associated static assets.
18+
Implementations should scan for and return any CSS, JavaScript or other static files
19+
that belong to the component and return a list/set/other iterable of `Asset` objects.
20+
"""

0 commit comments

Comments
 (0)