def home(): """Index page - without renderer""" return render( doctype("html"), e.html()( e.head()(e.title()("htmldoom rendering framework demo")), e.body()( e.h1()("Home page"), e.a(href="/jinja2")("Jinja2"), e.br(), e.a(href="/htmldoom")("htmldoom"), e.br(), e.a(href="/flask-profiler/")("Rendering performance"), ), ), )
def home(request): """Index page - without renderer""" return Response( render( doctype("html"), e.html()( e.head()(e.title()("Pyramid template engine demo")), e.body()( e.h1()("Home page"), e.a(href="/jinja2")("Jinja2"), e.br(), e.a(href="/htmldoom")("htmldoom"), ), ), ))
'>>> render_paras({"x": "awesome paragraph"})\n' "<p>awesome paragraph</p><p>another awesome paragraph</p>\n"), e.h3()("Syntax 2"), e.pre()(">>> from htmldoom import renders, elements as e\n" ">>> \n" ">>> render_paras = renders(\n" '... e.p()("{x}"),\n' '... e.p()("another {x}"),\n' '... )(lambda data: {"x": data["x"]})\n' ">>> \n" '>>> render_paras({"x": "awesome paragraph"})\n' "<p>awesome paragraph</p><p>another awesome paragraph</p>\n"), e.p()( e.b()("NOTE: "), "This mechanism pre-renders the template when the file loads and reuse it.", e.br(), e.pre() ("renders( ...pre-rendered template... )( ...dynamic rendering logic... )" ), e.br(), "The more elements you pre-render as template, the faster it gets.", e.br(), "If you properly use this mechanism and refactor your dynamic pages into smaller" " components, it might surpass the performance of traditional template rendering engines.", ), e.p()( e.b()("WARNING: "), "It performs a ", e.code()('"{rendered_elements}".format(**returned_data)'), ". So each `{` or `}` in the pre-rendered template needs to be", " escaped with `{{` or `}}`.",
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): return {"contents": data["data"]} def render(data): return render_document(data, body_renderer=render_body)