You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -239,7 +239,7 @@ from app.models import Message
239
239
page.messages = Message.find_all()
240
240
---
241
241
{% use_layout %}
242
-
<{MercureStream topic="messages" id="messages"}>
242
+
<{MercureStream topic="messages"}>
243
243
{% for msg in messages %}
244
244
<{ChatMessage message=msg }/>
245
245
{% endfor %}
@@ -285,6 +285,8 @@ Modify the component `ChatMessage` to display the author:
285
285
286
286
Finally, add `page.login_required()` at the top of your page frontmatter to require authentication to access it.
287
287
288
+
Upon accessing your site, you will be asked to connect using an email address. No confirmation will be asked on first connection. On further connections, you will be asked for a code to complete the connection. Go to <http://localhost:8025> to access [Mailpit](https://github.com/axllent/mailpit) and read the emails.
289
+
288
290
## Deploying to production
289
291
290
292
Signup for an account on Fly.io or any VPS provider (eg: Digital Ocean) then run the following command from a VS Code terminal (while connected to the dev container):
@@ -86,114 +86,6 @@ Example using the previous *app/components/Dropdown.html*:
86
86
</div>
87
87
```
88
88
89
-
## Backend logic and interactions with HTMX
90
-
91
-
Components can define their own custom backend logic. Similar to pages, files should use the *jpy* extension and provide a frontmatter with the python code.
92
-
93
-
Functions named after HTTP methods will be registered as routes. For example, if a *get* function exists, Hyperflask will make the component accessible through GET requests.
94
-
These functions can return a dict with component props to render the component or any other valid Flask response value.
95
-
96
-
Use HTMX to call your component logic and retrieve only the necessery HTML.
Unlike pages, all python imports are mandatory in components
173
-
174
-
!!! tip
175
-
The `request` object in Hyperflask uses [htmx-Flask](https://github.com/sponsfreixes/htmx-flask) subclass that [provides easy access to htmx headers](https://github.com/sponsfreixes/htmx-flask?tab=readme-ov-file#usage).
176
-
177
-
### HTMX utilities
178
-
179
-
Perform an htmx redirection using `htmx_redirect()`:
180
-
181
-
```py
182
-
from hyperflask import htmx_redirect
183
-
defpost():
184
-
# ...
185
-
return htmx_redirect("/")
186
-
```
187
-
188
-
Perform an Out-Of-Band (oob) swap using `htmx_oob()`:
189
-
190
-
```py
191
-
from hyperflask import htmx_oob
192
-
defpost():
193
-
# ...
194
-
return htmx_oob(current_app.components.Sidebar()) # replaces the sidebar element with a new version of itself
195
-
```
196
-
197
89
## Styling and scripting
198
90
199
91
Scripts and styles can be embedded in components and bundled automatically.
@@ -231,7 +123,7 @@ In a template: `<{custom_dropdown}/>`
231
123
232
124
### React components
233
125
234
-
Define react components as usual in a jsx file named after the component. Call them in your template like any other component. Each component call will create an independant react tree.
126
+
Define react components as usual in a jsx file named after the component. You must export your component as default. Call them in your template like any other component. Each component call will create an independant react tree.
235
127
236
128
!!! important
237
129
React is not bundled with Hyperflask. You will need to install it using npm.
@@ -241,7 +133,7 @@ Properties provided to the component will be serialized to JSON. You cannot prov
241
133
Example, *app/components/Dropdown.jsx*:
242
134
243
135
```js
244
-
functionDropdown(props) {
136
+
exportdefaultfunctionDropdown(props) {
245
137
return<div></div>;
246
138
}
247
139
```
@@ -252,4 +144,21 @@ In a template: `<{Dropdown}/>`
252
144
253
145
Hyperflask includes a rich library of UI components powered by [DaisyUI](https://daisyui.com).
254
146
255
-
Check out the [Components library](/components)
147
+
Check out the [Components library](/components)
148
+
149
+
## Components with custom logic
150
+
151
+
For backend components, you can execute business logic before rendering the template.
152
+
Use a jinjapy file instead of html file (.jpy extension) and implement the render function.
153
+
154
+
The render function will be provided the props as arguments.
Flask [provides a mechanism](https://flask.palletsprojects.com/en/stable/patterns/flashing/) for showing one time messages to the user.
4
+
5
+
Use `flash()` or `page.flash()` as described by Flask documentation.
6
+
7
+
Hyperflask will automatically print the messages as [alert messages in a toast](https://daisyui.com/components/toast/). This will also work when flashing messages during ajax requests.
0 commit comments