PyHTML is HTML in python objects
Project description
py-HTML
Building Static HTML and CSS in Python
Introduction
PyHTML is a library that compiles HTML syntax based on how py-HTML elements are combined. The compiled HTML is still static not JS interactions or Virtual DOM thingy. It simply provides components that make it easier to build the HTML template faster.
Although there are Jinja and Mako in this space, I don't intend to make this library a substitute for such a package.
This is just an experiment.
Quick Bootstrap Example
from py_html.el.base import render_component
import py_html.el as el
from starlette.responses import HTMLResponse
from ellar.common import ModuleRouter
from ellar.app import AppFactory
from ellar_cli.main import create_ellar_cli
router = ModuleRouter("/example")
@router.get("/", response=HTMLResponse)
def template():
content = el.html(
el.head(
el.title("Example HTML"),
lambda ctx: el.link(href=ctx.get("bootstrap_css", ""))
),
el.body(class_name="container py-4", *(
el.header(
class_name="pb-3 mb-4 border-bottom",
*(
el.a(href="/", class_name="d-flex align-items-center text-dark text-decoration-none"),
el.span("Jumbotron example", class_name="fs-4")
)
),
el.div(class_name="p-5 mb-4 bg-light rounded-3", *(
el.div(class_name="container-fluid py-5", *(
el.h1("Custom jumbotron", class_name="display-5 fw-bold"),
el.p("""
Using a series of utilities, you can create this jumbotron, just like the one in previous versions of Bootstrap.
Check out the examples below for how you can remix and restyle it to your liking.
""", class_name="col-md-8 fs-4"
),
el.button("Example button", class_name="btn btn-primary btn-lg", type="button")
)),
)),
el.footer("© 2024", class_name="pt-3 mt-4 text-muted border-top")
))
)
return render_component(content, {
"bootstrap_css": "https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css",
})
def app_bootstrap():
application = AppFactory.create_app(routers=[router])
return application
cli = create_ellar_cli("readme:app_bootstrap")
if __name__ == "__main__":
cli()
Start up command
python readme.py runserver --reload
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
py_htmlbuilder-0.1.0.tar.gz
(24.7 kB
view details)
Built Distribution
File details
Details for the file py_htmlbuilder-0.1.0.tar.gz
.
File metadata
- Download URL: py_htmlbuilder-0.1.0.tar.gz
- Upload date:
- Size: 24.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62d40062d4118760ee94d8533579891664ac1e49d63a42440e3bd508a0f72001 |
|
MD5 | 71b49b89e259bde7bc221795b08a78fa |
|
BLAKE2b-256 | 31e9aab79fe3304539f44484be6e35a56cbeb85536f1637673494fc4a4ad7b37 |
File details
Details for the file py_htmlbuilder-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: py_htmlbuilder-0.1.0-py3-none-any.whl
- Upload date:
- Size: 34.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22300f0eeeb58e6d83810b0f840bfe051756adcf3fea190eef9fc5a7f2711ef9 |
|
MD5 | 591a8b2e0f34c9b4501068a68d0a7f48 |
|
BLAKE2b-256 | 1f61b2fc803624722025909cb86894e54108bbe6e2ece534a35f468d0e30b258 |