// Compiled pug templates (ADR 0057): what used to be `pug`'s runtime // panics are compile-time diagnostics (E0601), pointing at the line of // the template at fault. import std/html.{type Html} import std/template.{pug} pub fn indented_more :: -> Html { pug` div p oops //~ ERROR E0601 pug: line 4 is indented more than the line before ` } pub fn indented_less :: -> Html { pug` div p //~ ERROR E0601 pug: line 3 is indented less than the first line ` } // The `\t` escape decodes to a tab character. pub fn tab_indent :: -> Html { pug`\tdiv` //~ ERROR E0601 pug: line 1 is indented with a tab; use spaces } pub fn text_with_children :: -> Html { pug` | text div //~^ ERROR E0601 pug: line 3 follows a text line; only elements have children ` } pub fn bad_start :: -> Html { pug`=oops` //~^ ERROR E0601 `=` cannot start an element; a line of text starts with `|` } pub fn missing_class_name :: -> Html { pug`div.` //~ ERROR E0601 pug: line 1: expected a class name } pub fn missing_id :: -> Html { pug`div#(x)` //~ ERROR E0601 pug: line 1: expected an id } pub fn bad_attr :: -> Html { pug`p(class="x" oops` //~ ERROR E0601 pug: line 1: an attribute name or `)` } pub fn bad_attr_start :: -> Html { pug`p("x")` //~ ERROR E0601 pug: line 1: an attribute name or `)` } pub fn unquoted_attr :: -> Html { pug`p(class=x)` //~^ ERROR E0601 pug: line 1: an attribute value is quoted or a single `{hole}` } pub fn unclosed_attr :: -> Html { pug`p(class="x)` //~ ERROR E0601 pug: line 1: an attribute value is not closed } // An element can't be an attribute value: a type error now (it was a // panic), as is one in a quoted value (`Element` has no `Show`). pub fn element_attr :: el: Html -> Html { pug`p(class={el})` //~^ ERROR E0602 attribute `class` must be a String, Int, Bool or Option } pub fn element_in_quoted_attr :: el: Html -> Html { pug`p(class="a {el}")` //~ ERROR E0401 does not implement `Show` } // Holes are typed by position: a `Bool` attribute is a flag (present iff // true), an `Option` is absent for `None`. pub fn bool_attrs :: on: Bool off: Bool -> Html { pug`input(required={on} autofocus={off})` } pub fn option_attr :: value: Option -> Html { pug`input(value={value})` } // Components: an uppercase tag calls the function with labelled // arguments, children included (as in a literal). fn card :: title: String children: List -> Html {

{title}

{children}
} pub fn uses_card :: title: String -> Html { pug` Card(title={title}) p body ` } pub fn component_flag :: title: String -> Html { pug` Card(title) //~ ERROR E0604 needs a value p x ` } // An element written right after a hole is text (issue #54): the rest // of the line renders literally, so W0601 warns at the element's head. pub fn element_after_leading_hole :: icon: Html word: String -> Html { pug` button(type="submit" class="act") {icon}span.label {word} //~^ WARN W0601 renders as text, not an element ` } pub fn element_after_hole_mid_line :: a: String b: String -> Html { pug` p {a} and {b}span.x //~^ WARN W0601 span.x ` } pub fn element_after_hole_in_content :: x: String -> Html { pug` p {x}span.y //~^ WARN W0601 span.y ` } pub fn selectors_after_hole :: x: String y: String -> Html { pug` div {x}div#main.wide(role="main") //~^ WARN W0601 div#main.wide(role="main") {y}li#first //~^ WARN W0601 li#first ` } pub fn attrs_after_hole :: x: String -> Html { pug` p {x}a(href="/") //~^ WARN W0601 a(href="/") ` } // Bare words, punctuation and tagless `.x`/`#x` after a hole are text, // as is anything on a `| ` line; a hole alone on its line embeds, and // the next line is an element. pub fn text_after_holes :: n: Int price: Int a: String -> Html { pug` p {n} participants {n}px wide {price}.00 each {n}#1 in line {a}. ` } pub fn tagless_selectors_after_holes :: x: String host: String file: String url: String -> Html { pug` p {x}.note {x}#main see {host}.com, {file}.pdf and {url}#section ` } pub fn explicit_text_line :: x: String -> Html { pug` p | {x}span.label ` } pub fn hole_alone_on_its_line :: icon: Html word: String -> Html { pug` button(type="submit") {icon} span.label {word} ` }