Skip to content

Commit 56cc031

Browse files
authored
docs: Create a how-to guide section. (#167)
Move async, django and starlette docs there. They are mostly how-to guides and is a starting point for improving the documentation structure.
1 parent e8cf7d7 commit 56cc031

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

docs/async.md renamed to docs/how-to/async.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
htpy fully supports rendering HTML asynchronously. Combined with a async framework such as [Starlette/FastAPI](starlette.md), the entire web request can be processed async and the HTML page can be sent to the client incrementally as soon as it is ready.
44

5-
# Async components
5+
# Writing async components
66

7-
In addition to regular, [synchronous components](common-patterns.md), components can be defined as an `async def` coroutine. When rendering, htpy will `await` all async components:
7+
Components can be defined as an `async def` function. When rendering, htpy will `await` all async components:
88

99
```py
1010
from htpy import li

docs/django.md renamed to docs/how-to/django.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
# Usage With Django
1+
# Django
22

3-
htpy is not tied to any specific web framework. Nonetheless, htpy works great
4-
when combined with Django. This page contains information and useful techniques
5-
on how to combine htpy and Django.
3+
htpy works great with Django. This page contains information how you integrate htpy with Django.
64

7-
## Returning a htpy Response
5+
## Returning a htpy response from a Django view
86

97
htpy elements can be passed directly to `HttpResponse`:
108

@@ -16,7 +14,7 @@ def my_view(request):
1614
return HttpResponse(html[body[div["Hi Django!"]]])
1715
```
1816

19-
## Using htpy as Part of an Existing Django Template
17+
## Using htpy as part of an existing Django template
2018

2119
htpy elements are marked as "safe" and can be injected directly into Django
2220
templates. This can be useful if you want to start using htpy gradually in an
@@ -45,7 +43,7 @@ def index(request):
4543
})
4644
```
4745

48-
## Render a Django Form
46+
## Render a form
4947

5048
CSRF token, form widgets and errors can be directly used within htpy elements:
5149

@@ -108,9 +106,9 @@ def my_form_success_page() -> Renderable:
108106
)
109107
```
110108

111-
## Implement Custom Form Widgets With htpy
109+
## Implement custom form widgets
112110

113-
You can implement a custom form widget directly with htpy like this:
111+
You can implement a custom form widget directly with htpy.
114112

115113
```py title="widgets.py"
116114
from django.forms import widgets
@@ -128,10 +126,10 @@ class ShoelaceInput(widgets.Widget):
128126
return str(sl_input(attrs, name=name, value=value))
129127
```
130128

131-
## The htpy Template Backend
129+
## Using htpy components directly from a template
132130

133-
htpy includes a custom template backend. It makes it possible to use htpy
134-
instead of Django templates in places where a template name is required. This
131+
htpy includes a custom template backend that makes it possible to use htpy
132+
instead of Django templates in places where a template name is required. This
135133
can be used with generic views or third party applications built to be used with
136134
Django templates.
137135

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
# Usage with Starlette/FastAPI
1+
# Starlette/FastAPI
22

3-
htpy can be used with Starlette to generate HTML. Since FastAPI is built upon Starlette, htpy can also be used with FastAPI.
4-
5-
htpy supports full async rendering of all components. See [async rendering](async.md) for more information.
3+
htpy works great in combination with Starlette and FastAPI. htpy supports full async rendering of all components. See [async rendering](async.md) for more information.
64

5+
## Returning htpy content from a handler
76
To return HTML contents, use the `HtpyResponse` class:
87

98
```py

mkdocs.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ theme:
44
name: material
55
features:
66
- content.code.copy
7-
- toc.integrate
87
palette:
98
- media: "(prefers-color-scheme)"
109
toggle:
@@ -25,11 +24,12 @@ theme:
2524
nav:
2625
- README.md
2726
- usage.md
27+
- How-to guides:
28+
- how-to/django.md
29+
- how-to/async.md
30+
- how-to/starlette.md
2831
- common-patterns.md
2932
- static-typing.md
30-
- django.md
31-
- async.md
32-
- starlette.md
3333
- streaming.md
3434
- html2htpy.md
3535
- faq.md
@@ -55,4 +55,7 @@ markdown_extensions:
5555
plugins:
5656
- redirects:
5757
redirect_maps:
58-
'changelog.md': 'https://github.com/pelme/htpy/releases'
58+
"changelog.md": "https://github.com/pelme/htpy/releases"
59+
async.md: how-to/async.md
60+
django.md: how-to/django.md
61+
starlette.md: how-to/starlette.md

0 commit comments

Comments
 (0)