Skip to content

Commit 577b831

Browse files
committed
html primitive docs
1 parent 53c0499 commit 577b831

File tree

5 files changed

+71
-4
lines changed

5 files changed

+71
-4
lines changed

docs/examples/html/pyscript-tag.html

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{% load reactpy %}
2+
<!DOCTYPE html>
3+
<html>
4+
5+
<head>
6+
<title>ReactPy</title>
7+
{% pyscript_setup %}
8+
</head>
9+
10+
<body>
11+
{% component "example_project.my_app.components.server_side_component.py" %}
12+
</body>
13+
14+
</html>

docs/examples/python/pyscript-tag.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from reactpy import component, html
2+
from reactpy_django.html import pyscript
3+
4+
example_source_code = """
5+
import js
6+
7+
js.console.log("Hello, World!")
8+
"""
9+
10+
11+
@component
12+
def server_side_component():
13+
return html.div(
14+
pyscript(example_source_code.strip()),
15+
)

docs/mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ nav:
77
- Reference:
88
- Components: reference/components.md
99
- Hooks: reference/hooks.md
10+
- HTML: reference/html.md
1011
- URL Router: reference/router.md
1112
- Decorators: reference/decorators.md
1213
- Utilities: reference/utils.md

docs/src/reference/components.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,19 @@ This is an embeddable version of the [`#!jinja {% pyscript_component %}` templat
4444
| `#!python initial` | `#!python str | VdomDict | ComponentType` | The initial HTML that is displayed prior to the PyScript component loads. This can either be a string containing raw HTML, a `#!python reactpy.html` snippet, or a non-interactive component. | `#!python ""` |
4545
| `#!python root` | `#!python str` | The name of the root component function. | `#!python "root"` |
4646

47+
<!--pyscript-setup-required-start-->
48+
4749
??? warning "You must call `pyscript_setup` in your Django template before using this tag!"
4850

49-
This component requires the use of the [`#!jinja {% pyscript_setup %}` template tag](./template-tag.md#pyscript-setup) to work correctly.
51+
This requires using of the [`#!jinja {% pyscript_setup %}` template tag](./template-tag.md#pyscript-setup) to initialize PyScript on the client.
5052

51-
```jinja
52-
{% include "../../examples/html/pyscript-setup.html" %}
53-
```
53+
=== "my_template.html"
54+
55+
```jinja
56+
{% include "../../examples/html/pyscript-setup.html" %}
57+
```
58+
59+
<!--pyscript-setup-required-end-->
5460

5561
{% include-markdown "../reference/template-tag.md" start="<!--pyscript-js-exec-start-->" end="<!--pyscript-js-exec-end-->" %}
5662

docs/src/reference/html.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## Overview
2+
3+
<p class="intro" markdown>
4+
5+
We supply some pre-generated that HTML nodes can be used to help simplify development.
6+
7+
</p>
8+
9+
---
10+
11+
## PyScript
12+
13+
Primitive HTML tag that is leveraged by [`reactpy_django.components.pyscript_component`](./components.md#pyscript-component).
14+
15+
This can be used as an alternative to the `#!python reactpy.html.script` tag to execute JavaScript and run client-side Python code.
16+
17+
Additionally, this tag functions identically to any other tag contained within `#!python reactpy.html`, and can be used in the same way.
18+
19+
=== "components.py"
20+
21+
```python
22+
{% include "../../examples/python/pyscript-tag.py" %}
23+
```
24+
25+
=== "my_template.html"
26+
27+
```jinja
28+
{% include "../../examples/html/pyscript-tag.html" %}
29+
```
30+
31+
{% include-markdown "../reference/components.md" start="<!--pyscript-setup-required-start-->" end="<!--pyscript-setup-required-end-->" %}

0 commit comments

Comments
 (0)