morca ยท API

orca.html

Writing HTML: every value escaped, markup only where it's said to be.

var h = Html()
h.raw("<td>")
h.text(step.error)        # `<script>` comes out as text
h.raw("</td>")
h.link("/runs/7", "run 7")

orca ui writes its pages through this rather than a template engine: a page is tables of records, and writing it in Mojo keeps each value's type until the moment it's escaped.

Structs

Html

struct Html

A page being written.

Implements Movable, Writable

Fields
out: String

__init__

def __init__(out self)

raw

def raw[*Ts: Writable](mut self, *parts: *Ts.values)

Markup, written as it is. Only ever literals of this module's callers, never a value from the database or a request.

text

def text[*Ts: Writable](mut self, *values: *Ts.values)

Values, each written and then escaped.

code

def code(mut self, href: StringSpan, label: StringSpan, commit: StringSpan)

A link to source code on its host, set apart from links inside orca: an icon, label (where, as file.mojo:26) in monospace, and โ†—; it opens in a new tab, and its title names the commit.

code_named

def code_named(mut self, href: StringSpan, name: StringSpan, at: StringSpan, commit: StringSpan)

code's link labelled with the function's name; where it is (at, as file.mojo:26) goes in the title, after the commit.

cell

def cell[*Ts: Writable](mut self, *values: *Ts.values)

One <td> holding the values, escaped.

mono

def mono[*Ts: Writable](mut self, *values: *Ts.values)

A <td> in the monospace font: an id, a partition, a time.

num

def num[*Ts: Writable](mut self, *values: *Ts.values)

A <td> of a count, right-aligned in tabular figures.

chip

def chip(mut self, href: StringSpan, label: StringSpan)

A link to a run, as a small chip of its number.

status

def status(mut self, s: StringSpan)

A status as a badge, its class named after it (a space in the status is a hyphen in the class), with what it means on hover or keyboard focus (orca.ui.terms).

help

def help(mut self, id: String, key: String, text: StringSpan[ImmStaticOrigin], docs: StringSpan[ImmStaticOrigin] = StringSpan(""))

A "?" after a fact's or a column's name that shows text, then a link to the docs (docs: a section of the docs page, or a URL) if there is one. CSS shows it on hover and keyboard focus, so it needs no script; to a screen reader the text is the button's description. id is unique in the page.

term

def term(mut self, kind: StringSpan, value: StringSpan)

value, one of a fixed set (kind in orca.ui.terms): dotted underlined, with what it means on hover, keyboard focus or a tap; plain text if the set doesn't know it.

finish

def finish(deinit self) -> String

The page written.

write_to

def write_to(self, mut writer: T)

Functions

escape

def escape(s: StringSpan) -> String

s with &, <, >, " and ' as character references, safe in text and in a quoted attribute.

url_encode

def url_encode(s: StringSpan) -> String

s as one path segment or query value: unreserved bytes as they are, every other byte as %XX.

url_decode

def url_decode(s: StringSpan) -> String

%XX and + in a query value decoded; a malformed escape is kept as it is.

query_param

def query_param(url: String, name: StringSpan) -> String

A query parameter's value, decoded, or empty.

query_values

def query_values(url: String, name: StringSpan) -> List[String]

Each value of a query parameter given once or more, decoded, in order.