"""Small pieces the new view pages share: a page heading with a breadcrumb, a table, a ranked row.""" from . import words from .markup import Markup, esc def head(h1, lede_html, crumbs, *, kicker=""): """The page-head block. crumbs: [(text, href)] leading to this page; lede_html is HTML.""" items = "".join(f'
  • {esc(t)}
  • ' for t, h in crumbs) kick = f'

    {esc(kicker)}

    ' if kicker else "" return f"""
    {kick}

    {esc(h1)}

    {lede_html}

    """ def table(headers, rows, *, caption="", numeric=(), row_heads=False): """A table in the site's table wrapper. headers: column titles; rows: lists of HTML cells (Markup, or text that is escaped); numeric: column numbers set at the end of the cell; row_heads: the first cell of each row is a row heading.""" def cell(i, value, head=False): text = value if isinstance(value, Markup) else esc(value) cls = ' class="num"' if i in numeric else "" if head: return f'{text}' return f"{text}" cap = f'{esc(caption)}' if caption else "" num = ' class="num"' head = "".join(f'{esc(h)}' for i, h in enumerate(headers)) body = "".join( "" + "".join(cell(i, v, head=row_heads and i == 0) for i, v in enumerate(row)) + "" for row in rows) return Markup(f'
    {cap}{head}{body}
    ') def trail_link(rec): from . import common return Markup(f'{common.name(rec)}') def ft_per_mile(m_per_km): """A climb rate as feet per mile and metres per kilometre, in the same unit pair as lengths.""" ft_mi = m_per_km * words.M_PER_FT ** -1 * words.KM_PER_MI return Markup(f'{esc(words.fmt_int(ft_mi))} ft per mile' f'{esc(words.fmt_int(m_per_km))} m per km') def append_nav(body, nav_html): """body with nav_html placed at the end of its last container (the page's closing ).""" text = str(body) i = text.rfind("") return Markup(text[:i] + nav_html + text[i:]) if i >= 0 else Markup(text + nav_html) def more_nav(path, extras): """A line of links to the other table, change and reference pages: extras is [(group, title, blurb, path, n)] as pages.py builds it for /lists/.""" links = " · ".join(f'{esc(t)}' for _, t, _, p, _ in extras if p != path) return (f'') if links else ""