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"), ), ), )
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"), ), ), ))
e.html(op="news")( e.head()( e.meta(name="referrer", content="origin"), e.meta(name="viewport", content="width=device-width, initial-scale=1.0"), e.link(rel="stylesheet", type_="text/css", href="news.css?9UnLxU8WHV0ou3hRwndX"), e.link(rel="shortcut icon", href="favicon.ico"), e.link(rel="alternate", type_="application/rss+xml", title="RSS", href="rss"), e.title()("Hacker News"), ), e.body()(e.center()(e.table( id_="hnmain", border="0", cellpadding="0", cellspacing="0", width="85%", bgcolor="#f6f6ef", )( e.tr()(e.td(bgcolor="#ff6600")(e.table( border="0", cellpadding="0", cellspacing="0", width="100%", style="padding:2px", )(e.tr()( e.td(style="width:18px;padding-right:4px")( e.a(href="https://news.ycombinator.com")(e.img( src="y18.gif", width="18", height="18", style="border:1px white solid;", ))), e.td(style="line-height:12pt; height:10px;")( e.span(class_="pagetop")( e.b(class_="hnname")(e.a(href="news")("Hacker News ")), e.a(href="newest")("new"), " | ", e.a(href="front")("past"), " | ", e.a(href="newcomments")("comments"), " | ", e.a(href="ask")("ask"), " | ", e.a(href="show")("show"), " | ", e.a(href="jobs")("jobs"), " | ", e.a(href="submit")("submit"), )), e.td(style="text-align:right;padding-right:4px;")(e.span( class_="pagetop")(e.a(href="login?goto=news")("login"))), )))), e.tr("title", id_="pagespace", style="height:10px"), e.tr()(e.td()(e.table( border="0", cellpadding="0", cellspacing="0", class_="itemlist", )( "{newslist}", e.tr(class_="morespace", style="height:10px"), e.tr()( e.td(colspan="2"), e.td(class_="title")(e.a( href="news?p=2", class_="morelink", rel="next", )("More")), ), ))), e.tr()(e.td()( e.img(src="s.gif", height="10", width="0"), e.table(width="100%", cellspacing="0", cellpadding="1")(e.tr()(e.td(bgcolor="#ff6600"))), e.br(), e.center()(e.a( href="https://www.startupschool.org" )(" Registration is open for Startup School 2019. Classes start July 22nd. " )), e.br(), e.center()( e.span(class_="yclinks")( e.a(href="newsguidelines.html")("Guidelines"), " | ", e.a(href="newsfaq.html")("FAQ"), " | ", e.a(href="mailto:[email protected]")("Support"), " | ", e.a(href="https://github.com/HackerNews/API")("API"), " | ", e.a(href="security.html")("Security"), " | ", e.a(href="lists")("Lists"), " | ", e.a(href="bookmarklet.html", rel="nofollow")("Bookmarklet"), " | ", e.a(href="http://www.ycombinator.com/legal/")("Legal"), " | ", e.a(href="http://www.ycombinator.com/apply/")( "Apply to YC"), " | ", e.a(href="mailto:[email protected]")("Contact"), ), e.br(), e.br(), e.form(action="//hn.algolia.com/", method="get")( "Search: ", e.input_( "value", type_="text", name="q", size="17", autocorrect="off", spellcheck="false", autocapitalize="off", autocomplete="false", ), ), ), )), ))), e.script(type_="text/javascript", src="hn.js?9UnLxU8WHV0ou3hRwndX"), ))
), e.meta(name="theme-color", content="#ffffff"), e.link(href="https://niteo.co/static_niteo_co/main.css", rel="stylesheet"), e.script(crossorigin="anonymous", src="/fanstatic/minisites/jquery-2.2.4.min.js"), )) def render_head(data: dict, title_renderer: callable = render_title) -> dict: return {"title": title_renderer(data=data)} @renders(e.body()("{contents}")) def render_body(data) -> None: raise NotImplementedError("You are trying to render a base layout.") @renders(e.html(lang="en", prefix="og: http://ogp.me/ns#")("{head}", "{body}")) def render_html( data: dict, title_renderer: callable = render_title, head_renderer: callable = render_head, body_renderer: callable = render_body, ) -> dict: return { "head": head_renderer(data=data, title_renderer=render_title), "body": body_renderer(data=data), } @renders("{doctype}{html}") def render_document( data: dict,
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): return {"doctitle": doctitle} @renders(e.body()("{content}")) def render_body(data): raise NotImplementedError("You are trying to render a layout.") @renders("{doctype}", e.html()(e.head()("{title}"), "{body}")) def render_document(data, title_renderer=render_title, body_renderer=render_body) -> dict: return { "doctype": doctype, "title": title_renderer(doctitle=data["data"]), "body": body_renderer(data=data), } def render(data): return render_document(data=data)