Generate native python functions from HTML templates
Project description
Tempered (Beta)
Generate native python functions from HTML templates
- Scoped CSS
- Type checked
- Intelisense
- Compiled
pip install tempered
Example
<!-- templates/image.html -->
{!param src: str!}
{!param alt: str = ""!}
<img src="{{src}}" alt="{{alt}}">
<style>
img {
width: 100px;
height: 100px;
}
</style>
import tempered
tempered.add_template_folder("./templates")
components = tempered.build()
print(components.image(
src="/example.png",
alt="Example Post",
with_styles=True,
))
<!-- Generated -->
<style>img.tempered-1ad5be0d {width: 100px;height: 100px;}</style>
<img class='tempered-1ad5be0d' src="/example.png" alt="Example Post">
Compiled
Since tempered is runtime compiled and loaded, it provides increase speed compared to jinja. From initial benchmarks, it's roughly 10x faster than jinja2.
Additionally, it allows IDEs to provide intelisense to components
# __components.py
# This file is dynamicly generated when you build the templates
from tempered import _internals as __internals
IMAGE_STYLE = "<style>img.tempered-1ad5be0d {width: 100px;height: 100px;}</style>"
def image(*, src: str, alt: str = "", with_styles: bool = True) -> str:
__html = ""
if with_styles:
__html += IMAGE_STYLE
__html += "<img class='tempered-1ad5be0d' src=\""
__html += __internals.escape(src)
__html += "\" alt=\""
__html += __internals.escape(alt)
__html += "\">"
return __html
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tempered-0.3.2.tar.gz
(20.7 kB
view hashes)
Built Distribution
Close
Hashes for tempered-0.3.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 576ad09c2be98f9b08f82d911d5c6156a84c3f26a15ff0bddf1f1922d1f0dec7 |
|
MD5 | c8ca6c50cb403c69cbc2e2f09faf4ba8 |
|
BLAKE2b-256 | b868d0d4594db5577ad76e156e24cef380e969c7435e5e2f9cc6c5507c52451a |