// 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 ` }