Skip to main content

htmldoom rendering library plugin for Pyramid

Project description


htmldoom rendering library plugin for Pyramid



pip install pyramid_htmldoom

Plug into Pyramid

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="")
def hello_htmldoom_view(request):
    """htmldoom rendered view"""
    return {"data": "Hello htmldoom"}

if __name__ == "__main__":
    with Configurator() as config:

        config.add_route("hello_htmldoom", "/")

        app = config.make_wsgi_app()
    server = make_server("localhost", 8080, app)


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"))

def render_title(doctitle: str) -> dict:
    return {"doctitle": doctitle}

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)


from htmldoom import elements as e
from htmldoom import renders

from .layout import render_document

def render_body(data: dict) -> dict:
    return {"contents": data["data"]}

def render(data: dict) -> str:
    return render_document(data, body_renderer=render_body)


Find demo and examples here

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pyramid-htmldoom, version 0.2
Filename, size File type Python version Upload date Hashes
Filename, size pyramid_htmldoom-0.2-py3-none-any.whl (3.9 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size pyramid_htmldoom-0.2.tar.gz (3.3 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page