Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a page decorator and Jinja.page + run sync routes in threadpool #15

Merged
merged 3 commits into from
Feb 20, 2024

Conversation

volfpeter
Copy link
Owner

@volfpeter volfpeter commented Feb 19, 2024

Changes

  • Added a page() decorator for unconditionally rendering HTML (useful when a route needs to serve HTML for non-HTMX requests).
  • Added a Jinja.page() decorator, the Jinja2 implementation of the generic page() decorator.
  • Sync routes are now executed in a threadpool to avoid blocking the asyncio event loop.
  • Added Jinja.hx() as the primary decorator for HTMX-serving routes for overall consistency in the library. At the same time, Jinja.__call__() and Jinja.template() are now deprecated and will be removed in the future.
  • JinjaContext.unpack_result() can now handle None as well by converting it into an empty Jinja rendering context.
  • Typing improvements.
  • Renamed HTMXRenderer to HTMLRenderer. HTMXRenderer is still importable as a deprecated alias of HTMLRenderer.
  • Updated the existing Jinja example to showcase the updated Jinja class.
  • Added a fully-working (although rather basic) custom rendering example.
  • Updated the documentation.

Internals

A lot of internal code has been moved. If, for some reason you imported something directly from a module instead of the package, you will unfortunately need to update your imports. New package layout:

  • fasthx.core_decorators: the hx() and page() decorators can now be found here.
  • Jinja-related code has been moved from fasthx.main to fasthx.jinja.
  • get_hx_request() and DependsHXRequest are now in fasthx.dependencies.
  • All utility types have been moved from fasthx.main to fasthx.typing.
  • The internal _append_to_signature() method was moved from fasthx.main to fasthx.utils and renamed to append_to_signature. This method is still for internal use only.

Notes

Tentatively bumped version to 0.2402.2, although putting so many (and important) changes in a patch release is not that user-friendly. I'm considering moving to semver and 1.0 at this point, or alternatively to 0.2403.0.

…in a threadpool + typing improvements + internal refactoring + updated and new examples + doc updates, refs #13 #14
@volfpeter
Copy link
Owner Author

Leaving the PR here for a day or two, to leave some time for questions or comments.

@volfpeter volfpeter merged commit f5496a3 into main Feb 20, 2024
2 checks passed
@volfpeter volfpeter deleted the page-methods-and-threadpool-runner branch February 20, 2024 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant