Exemplo n.º 1
0
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"),
            ),
        ),
    )
Exemplo n.º 2
0
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"),
                ),
            ),
        ))
Exemplo n.º 3
0
def badge(href: str, src: str, alt: str):
    return e.span()(e.a(href=href)(e.img(src=src, alt=alt)))
Exemplo n.º 4
0
def plugin(title: str, href: str, description: str):
    return e.ul()(e.li()(e.a(href=href)(e.b()(title)),
                         e.span()(f": {description}")))
Exemplo n.º 5
0
      ">>> from htmldoom import functions as fn\n"
      ">>> \n"
      '>>> tuple(fn.foreach(["good", "bad", "evil"])(\n'
      "...     lambda x: fn.switch({\n"
      '...         x == "good": lambda: e.span(style="color: green")(f"this is {x}"),\n'
      '...         x == "bad": lambda: e.span(style="color: yellow")(f"this is {x}"),\n'
      '...         x == "evil": lambda: e.span(style="color: red")(f"this is {x}"),\n'
      "...         fn.Case.DEFAULT: lambda: fn.Error.throw(ValueError(x)),\n"
      "...     })\n"
      "... ))\n"
      """(b'<span style="color: green">this is good</span>',\n"""
      """ b'<span style="color: yellow">this is bad</span>',\n"""
      """ b'<span style="color: red">this is evil</span>')\n"""),
 ),
 e.p()(e.a(
     href="https://github.com/sayanarijit/htmldoom/tree/master/examples")(
         e.b()("Find more examples here"))),
 e.p()(
     e.h2()("Q/A"),
     e.h3()("What is the goal here?"),
     e.p()("The primary goal is to make writing dynamic HTML pages "
           "cleaner, easier, safer and intuitive in Python."),
     e.h3()("What about performance?"),
     e.p()(
         "Although performance is not the primary goal here, it's been given a very high priority.",
         " htmldoom uses pure functions with hashable input parameters as elements.",
         " Hence, it makes effective use of caching internally. It also offers a friendly",
         " mechanism to pre-render the static parts of the page using the ",
         e.code()("@renders"),
         " decorator and reuse it. ",
         e.br(),
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
from htmldoom import base as b
from htmldoom import elements as e
from htmldoom import render as _render
from htmldoom import renders

from .layout import render_document


@renders(
    e.tr(class_="spacer", style="height:5px"),
    e.tr(class_="athing", id_="{id}")(
        e.td(align="right", valign="top",
             class_="title")(e.span(class_="rank")("{rank}.")),
        e.td(valign="top", class_="votelinks")(e.center()(
            e.a(id_="up_{id}",
                href="vote?id={id}&how=up&goto=news")(e.div(class_="votearrow",
                                                            title="upvote")))),
        e.td(class_="title")(
            e.a(href="{href}", class_="storylink")("{title}"),
            e.span(class_="sitebit comhead")(
                " (",
                e.a(href="from?site={from_url}")(
                    e.span(class_="sitestr")("{from_name}")),
                ")",
            ),
        ),
    ),
    e.tr()(
        e.td(colspan="2"),
        e.td(class_="subtext")(
            e.span(class_="score", id_="score_{id}")("{score} points"),
Exemplo n.º 8
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"),
                 " | ",
Exemplo n.º 9
0
from htmldoom import base as b
from htmldoom import elements as e
from htmldoom import render as _render
from htmldoom import renders
from htmldoom_pages.layout import render_document

contents = _render(
    e.nav(class_="navbar navbar-light sticky-top navbar-expand-lg")(
        e.div(class_="container")(
            e.a(href="/", class_="navbar-brand")(e.img(
                src="https://niteo.co/static_niteo_co/images/logo.svg",
                width="120",
                height="30",
                alt="Niteo",
            )),
            e.button(
                class_="navbar-toggler",
                type_="button",
                data_toggle="collapse",
                data_target="#navbarResponsive",
                aria_controls="navbarSupportedContent",
                aria_expanded="false",
                aria_label="Toggle navigation",
            )(e.span(class_="navbar-toggler-icon")),
            e.div(class_="collapse navbar-collapse", id_="navbarResponsive")(
                e.ul(class_="navbar-nav ml-auto")(
                    e.li(class_="nav-item")(e.a(class_="nav-link",
                                                href="/projects")("Projects")),
                    e.li()(e.a(class_="nav-link", href="/about")("About")),
                    e.li(class_="nav-item")(e.a(class_="nav-link",
                                                href="/team")("Team")),
Exemplo n.º 10
0
         '>>> tuple(fn.foreach(["good", "bad", "evil"])(\n'
         "...     lambda x: fn.switch({\n"
         '...         x == "good": lambda: e.span(style="color: green")(f"this is {x}"),\n'
         '...         x == "bad": lambda: e.span(style="color: yellow")(f"this is {x}"),\n'
         '...         x == "evil": lambda: e.span(style="color: red")(f"this is {x}"),\n'
         "...         fn.Case.DEFAULT: lambda: fn.Error.throw(ValueError(x)),\n"
         "...     })\n"
         "... ))\n"
         """(b'<span style="color: green">this is good</span>',\n"""
         """ b'<span style="color: yellow">this is bad</span>',\n"""
         """ b'<span style="color: red">this is evil</span>')\n"""
     ),
 ),
 e.p()(
     e.a(href="https://github.com/sayanarijit/htmldoom/tree/master/examples")(
         e.b()("Find more examples here")
     )
 ),
 e.p()(
     e.h2()("Q/A"),
     e.h3()("What is the goal here?"),
     e.p()(
         "The primary goal is to make writing dynamic HTML pages "
         "cleaner, easier, safer and intuitive in Python."
     ),
     e.h3()("What about performance?"),
     e.p()(
         "Although performance is not the primary goal here, it should not be a roadblock.",
         " htmldoom is copying the syntax and some of the rendering properties of ",
         e.a(href="https://elm-lang.org")("elm"),
         ", an existing fast and purely functional programming language",