/// Server-rendered pages, as pug templates (ADR 0048), styled from disk /// (`static/style.css`, ADR 0049). import std/html.{type Html} import std/string import std/template.{pug} import std/test.{assert} fn page :: title: String body: Html -> Html { pug` html(lang="en") head meta(charset="utf-8") meta(name="viewport" content="width=device-width, initial-scale=1") link(rel="stylesheet" href="/static/style.css") title {title} body main.shell header.brand span.accent ~/ span louise span.dim · span.dim demo span.cursor ▌ h1 {title} {body} ` } /// The error paragraph, or nothing. fn error_note :: error: String -> Html { if error == "" { html.Fragment([]) } else { pug`p.error {error}` } } pub fn login :: error: String -> Html { page "Log in" pug` {error_note error} .card form(method="post" action="/login") input(name="name" placeholder="Name" required) input(name="password" type="password" placeholder="Password" required) button.primary(type="submit") Log in h2 New here? .card form(method="post" action="/register") input(name="name" placeholder="Name" required) input(name="password" type="password" placeholder="Password (8+ characters)" required) button.ghost(type="submit") Register ` } @test fn the_login_page_shows_an_error_only_if_there_is_one :: { assert (!string.contains (html.render (login "")) "class=\"error\"") "no error paragraph" assert ( string.contains (html.render (login "Try again.")) "
Try again.
" ) "the error" } pub fn home :: name: String -> Html { page "Home" pug` .card p Welcome, {name}! p.muted span.dim session span.accent · live p a(href="/logout") Log out ` } @test fn names_are_escaped_on_the_home_page :: { // Anyone can register any name. let page = html.render (home "") assert ( string.contains page "Welcome, <script>alert(1)</script>!
" ) "escaped" assert (!string.contains page "