htmldoom rendering library plugin for Pyramid
Project description
pyramid_htmldoom
htmldoom rendering library plugin for Pyramid
Usage
Install
pip install pyramid_htmldoom
Plug into Pyramid
app.py
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
from pyramid.view import view_config
@view_config(route_name="hello_htmldoom", renderer="templates.hello.py")
def hello_htmldoom_view(request):
"""htmldoom rendered view"""
return {"data": "Hello htmldoom"}
if __name__ == "__main__":
with Configurator() as config:
config.scan()
config.include("pyramid_htmldoom")
config.add_route("hello_htmldoom", "/")
app = config.make_wsgi_app()
server = make_server("localhost", 8080, app)
server.serve_forever()
templates/hello.py
from htmldoom import base as b
from htmldoom import elements as e
from htmldoom import render as _render
from htmldoom import renders
doctype = _render(b.doctype("html"))
@renders(e.title()("{doctitle}"))
def render_title(doctitle: str) -> dict:
return {"doctitle": doctitle}
@renders(e.body()("{content}"))
def render_body(data: dict) -> None:
raise NotImplementedError("You are trying to render a layout.")
@renders("{doctype}", e.html()(e.head()("{title}"), "{body}"))
def render_document(
data: dict,
title_renderer: callable = render_title,
body_renderer: callable = render_body,
) -> dict:
return {
"doctype": doctype,
"title": title_renderer(doctitle=data["data"]),
"body": body_renderer(data=data),
}
def render(data: dict) -> str:
return render_document(data=data)
templates/layout.py
from htmldoom import elements as e
from htmldoom import renders
from .layout import render_document
@renders(
e.body()(
e.h3()("{contents}"),
e.a(href="/")("Home"),
e.br(),
e.a(href="/jinja2")("jinja2"),
)
)
def render_body(data: dict) -> dict:
return {"contents": data["data"]}
def render(data: dict) -> str:
return render_document(data, body_renderer=render_body)
Examples
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyramid_htmldoom-0.2.tar.gz
(3.3 kB
view details)
Built Distribution
File details
Details for the file pyramid_htmldoom-0.2.tar.gz
.
File metadata
- Download URL: pyramid_htmldoom-0.2.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 655b903cd18a9f55f3aadc9a96a0aa70662b831a7c061576edc4abea883c76aa |
|
MD5 | 22e02f99a0e50523530983e41d1bcf0a |
|
BLAKE2b-256 | 052477c64fd9abac38139f2978a62f60a2f2a1cfec3723b5b6f029615240bdee |
Provenance
File details
Details for the file pyramid_htmldoom-0.2-py3-none-any.whl
.
File metadata
- Download URL: pyramid_htmldoom-0.2-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d58a84a5a8ee76f68f8abff01ec53b29b625aa239b49c0fcd0be438f907678d |
|
MD5 | 369f21c594f48977830a8aa7c6af4b0e |
|
BLAKE2b-256 | 05f1314959f47cf0a461e73c54133e6b9f1bd72bbc3294b26a81a9188abd7e5b |