<moonxml/>

186 public items

The API

Generated from each package's interface file, so it cannot describe something the code does not have — or miss something it does.

four packages· every public item· generated, not typed

moonxml

The tree, the chain, and the two engines. Everything you need unless you are reading a document.

Traits

fn
pub impl Show for XPathValue

XPathValue implements Show.

type
pub(open) trait Selector {
  fn select(Self, Selection, String) -> Selection raise Refused
}

One query language plugged into the chain. Implement this to add your own, register it with Document::register, and run it with selector(name, query) — or pass it straight to custom and skip the registry entirely. struct DeepLinks {} impl Selector for DeepLinks with select(_self, ctx, _query) { ctx.css("a[href]").filter(fn(node) { node is ElementNode(e) && e.attr("href").has_prefix("https://") }) }

Errors

fn
pub fn namespace_of(String) -> String?

The URI of a {uri}local name, or None when the name carries none.

type
pub(all) suberror Refused {
  Malformed(at~ : Int32, why~ : String)
  BadQuery(at~ : Int32, why~ : String)
  UnknownSelector(name~ : String)
  Unsupported(what~ : String)
  Exceeded(at~ : Int32, limit~ : Int32, got~ : Int32)
} derive(Eq, @debug.Debug)

Why a document could not be read, or a query could not be run. One family for the whole library, so there is one thing to catch.

Types

fn
pub impl Show for Refused

Refused implements Show.

type
pub struct Document {
  root : Element
  // private fields
}

A document: the virtual root (named #document) holding the top-level nodes, the flavour it was read as, the selector registry, and — for HTML — the tally of what the parser repaired.

fn
pub fn Document::append(Self, Node) -> Unit

Add a node at the end of the document: where a comment, a processing instruction or a second document element would go. The usual use is a doctype written before the root, which is what prepend is for.

fn
pub fn Document::by_class(Self, String) -> Selection

The elements carrying the class name.

fn
pub fn Document::by_id(Self, String) -> Selection

The elements whose id attribute is id — getElementById, over the whole document.

fn
pub fn Document::by_name(Self, String) -> Selection

The elements whose name attribute is name.

fn
pub fn Document::by_tag(Self, String) -> Selection

The elements named name; * answers every element.

fn
pub fn Document::children(Self) -> Selection

The document's top-level nodes — the doctype, comments and processing instructions beside the document element, in document order.

fn
pub fn Document::clear(Self) -> Unit

Empty the document: every top-level node goes, and the document is then what a freshly created one is.

fn
pub fn Document::css(Self, String) -> Selection raise Refused

Narrow with a CSS selector over the whole document. Descendant search from the virtual root, so every element is a candidate.

fn
pub fn Document::custom(Self, &Selector) -> Selection raise Refused

Run a selector that was never registered.

fn
pub fn Document::descendants(Self) -> Selection

Every node in the document, in document order.

fn
pub fn Document::document_element(Self) -> Element?

The document element — the root's first element child, documentElement in the DOM, getroot() in lxml.

fn
pub fn Document::dump(Self) -> Bytes

A whole document as bytes, in the flavour it was read as.

fn
pub fn Document::dump_html(Self) -> Bytes

A whole document as bytes, by HTML's rules.

fn
pub fn Document::dumps(Self) -> String

A whole document, in the flavour it was read as.

fn
pub fn Document::dumps_html(Self) -> String

A whole document, HTML rules whatever it was read as.

fn
pub fn Document::events(Self) -> Array[@event.Event]

Read a finished tree back as the event stream it would have produced.

fn
pub fn Document::flavour(Self) -> Flavour

The flavour this document writes itself back in.

fn
pub fn Document::html(Self) -> String

The whole document as markup, in the flavour it was read as.

fn
pub fn Document::new(flavour? : Flavour) -> Self

A fresh document. A tree built by hand has no syntax it was read from, so it writes back with XML's exact rules; ask for flavour=Html when the tree came from HTML.

fn
pub fn Document::prepend(Self, Node) -> Unit

Add a node before everything else in the document.

fn
pub fn Document::register(Self, String, &Selector) -> Unit

Register a selector under a name. Re-registering a name replaces what was there, built-in or not — and a built-in stays reachable through its own method, which calls the engine directly and never consults the registry.

fn
pub fn Document::repairs(Self) -> Repairs

What the HTML parser repaired; a tree that was not parsed as HTML has an empty tally.

fn
pub fn Document::selector(Self, String, String) -> Selection raise Refused

Run the selector registered under name, built-in or the caller's own.

fn
pub fn Document::set_repairs(Self, Repairs) -> Unit

Record what a parser repaired; the parsers call this when they are done.

fn
pub fn Document::set_unresolved(Self, Array[String]) -> Unit

Record the external entities a reader skipped; the XML parser calls this.

fn
pub fn Document::smooth(Self) -> Unit

Fuse adjacent text nodes everywhere in the document, which is what a writer wants after editing several places.

fn
pub fn Document::text(Self) -> String

The text of the whole document, concatenated.

fn
pub fn Document::unresolved(Self) -> Array[String]

The external entities the document named but the parser did not read, in the order they were referenced, each name once. The library does no I/O, so a document whose entities live in a file beside it is read without them: XML 1.0 says a non-validating processor need not read them, but must tell the application which ones it skipped. That is this list. It is empty for a document that needed nothing from outside.

fn
pub fn Document::xpath(Self, String) -> Selection raise Refused

Narrow to the nodes an XPath 1.0 expression answers, over the whole document.

fn
pub fn Document::xpath_value(Self, String) -> XPathValue raise Refused

The typed answer of an XPath 1.0 expression, read from the whole document.

fn
pub impl @event.Sink for Document

Document implements Sink.

type
pub struct Element {
  name : String
  attrs : Array[(String, String)]
  children : Array[Node]
  mut parent : Element?
  mut closed : Bool
  // private fields
}

An element: the {uri}local name — the James Clark spelling, chosen over registered prefixes so a node reads the same whichever prefixes the document declared — its attributes in document order, its children, its parent, and how it was closed (<a/> versus <a></a>) for the writer.

fn
pub fn Element::add_class(Self, String) -> Unit

Add a class; an element that already carries it is untouched.

fn
pub fn Element::append(Self, Node) -> Unit

Append a child node, claiming its parentage.

fn
pub fn Element::attr(Self, String) -> String?

The value of an attribute, or None when the element does not carry it.

fn
pub fn Element::by_class(Self, String) -> Selection

The descendants of this element that carry the class name.

fn
pub fn Element::by_id(Self, String) -> Selection

The descendants of this element whose id attribute is id.

fn
pub fn Element::by_name(Self, String) -> Selection

The descendants of this element whose name attribute is name.

fn
pub fn Element::by_tag(Self, String) -> Selection

The descendants of this element named name; * answers every element.

fn
pub fn Element::classes(Self) -> Array[String]

The class list: the class attribute split on whitespace, empty parts dropped, as HTML says.

fn
pub fn Element::clear(Self) -> Unit

Drop every child.

fn
pub fn Element::closest(Self, String) -> Selection raise Refused

The nearest ancestor of this element, itself included, that matches a CSS selector.

fn
pub fn Element::content(Self) -> Self?

The contents of a <template>: a fragment of its own, the way the DOM keeps them, and None for every other element. What sits in a template is inert — it is not a child of the element, so a query does not reach it and text() does not read it, which is what a browser does too. set_content is how a caller that builds a template by hand gives it contents.

fn
pub fn Element::css(Self, String) -> Selection raise Refused

Narrow to the descendants of this element that match a CSS selector.

fn
pub fn Element::custom(Self, &Selector) -> Selection raise Refused

Run a selector that was never registered, over this element's descendants.

fn
pub fn Element::document(Self) -> Document?

The document an element belongs to, or None when it is detached: the registry a selector(name, ..) call consults lives on the document.

fn
pub fn Element::has_attr(Self, String) -> Bool

Whether the element carries an attribute of this name.

fn
pub fn Element::has_class(Self, String) -> Bool

Whether the element's class list names this class.

fn
pub fn Element::html(Self) -> String

The element's inner markup, written in the flavour its document was read as.

fn
pub fn Element::insert(Self, Int32, Node) -> Unit

Insert node at at; an index past either end clamps to it.

fn
pub fn Element::insert_after(Self, Node) -> Bool

Insert node after self among its siblings.

fn
pub fn Element::insert_before(Self, Node) -> Bool

Insert node before self among its siblings.

fn
pub fn Element::new(String, children? : Array[Node], attrs? : Array[(String, String)], closed? : Bool) -> Self

A fresh element. The constructor claims the parentage of the children it is given, so a tree built this way keeps its parent pointers true.

fn
pub fn Element::prepend(Self, Node) -> Unit

Insert node as the first child.

fn
pub fn Element::remove(Self) -> Bool

Detach self from the parent, answering true when there was one. bs4's extract; the collector owns the rest.

fn
pub fn Element::remove_attr(Self, String) -> Bool

Drop an attribute; true when it was there.

fn
pub fn Element::remove_class(Self, String) -> Unit

Remove one class. The attribute stays, empty if that is what is left — bs4's behaviour, so a caller is never surprised by a missing attribute.

fn
pub fn Element::replace_with(Self, Node) -> Bool

Take self's place in the parent. bs4's replace_with; false when self has no parent.

fn
pub fn Element::selector(Self, String, String) -> Selection raise Refused

Run the selector registered under name, over this element's descendants.

fn
pub fn Element::set_attr(Self, String, String) -> Unit

Set or replace an attribute, keeping its place when it is already there.

fn
pub fn Element::set_content(Self, Self) -> Unit

Give a <template> a content fragment. A caller who builds one by hand uses this; the parser does it on its own.

fn
pub fn Element::smooth(Self) -> Unit

Fuse adjacent text nodes. What a writer wants after edits, and what keeps a tree that was cut and rebuilt from carrying confetti. CDATA is left alone: it is a distinct kind so it can round-trip.

fn
pub fn Element::text(Self) -> String

The text of this element and everything under it.

fn
pub fn Element::unwrap(Self) -> Bool

Unwrap the element: its children move up to its place, the element itself is dropped. bs4's unwrap; false when the element has no parent.

fn
pub fn Element::walk(Self, (Node) -> Unit) -> Unit

Pre-order walk over the whole subtree. Iterative, so a deep tree cannot outrun the stack.

fn
pub fn Element::wrap(Self, String) -> Self?

Wrap self in a fresh element with the given name, answering the wrapper. None when self has no parent to be replaced in.

fn
pub fn Element::xpath(Self, String) -> Selection raise Refused

Narrow to the nodes an XPath 1.0 expression answers from this element.

fn
pub fn Element::xpath_value(Self, String) -> XPathValue raise Refused

The typed answer of an XPath 1.0 expression, read from this element.

type
pub(all) enum Flavour {
  Xml
  Html
} derive(Eq, @debug.Debug)

How a document was read, and therefore how it writes itself back.

fn
pub impl Show for Flavour

Flavour implements Show.

type
pub(all) enum Node {
  ElementNode(Element)
  TextNode(String)
  CDataNode(String)
  CommentNode(String)
  ProcessingInstructionNode(ProcessingInstruction)
  DoctypeNode(String)
}

One node of the tree. Mixed content survives: text, CDATA, elements, comments, processing instructions and the doctype are all nodes, in document order — none of which fits in a JSON-shaped value, which is why this is not moonjson.

fn
pub fn Node::by_class(Self, String) -> Selection

The descendants of this node that carry the class name.

fn
pub fn Node::by_id(Self, String) -> Selection

The descendants of this node whose id attribute is id.

fn
pub fn Node::by_name(Self, String) -> Selection

The descendants of this node whose name attribute is name.

fn
pub fn Node::by_tag(Self, String) -> Selection

The descendants of this node named name.

fn
pub fn Node::children(Self) -> Array[Self]

The children of a node that is an element; a node with no children answers an empty list.

fn
pub fn Node::closest(Self, String) -> Selection raise Refused

The nearest ancestor of this node, itself included, that matches a CSS selector.

fn
pub fn Node::css(Self, String) -> Selection raise Refused

Narrow to the descendants of this node that match a CSS selector; a node that is not an element answers empty.

fn
pub fn Node::custom(Self, &Selector) -> Selection raise Refused

Run a selector that was never registered, over this node's descendants.

fn
pub fn Node::is_element(Self) -> Bool

Whether the node is an element.

fn
pub fn Node::is_text(Self) -> Bool

Text, CDATA included: XPath's text() node test matches both.

fn
pub fn Node::name(Self) -> String

An element's name, or "" for a node that is not an element.

fn
pub fn Node::selector(Self, String, String) -> Selection raise Refused

Run the selector registered under name, over this node's descendants.

fn
pub fn Node::text(Self) -> String

A node's text content — the DOM's textContent: an element answers the text of its descendants, a text, CDATA, comment or processing-instruction node answers what it carries.

fn
pub fn Node::xpath(Self, String) -> Selection raise Refused

Narrow to the nodes an XPath 1.0 expression answers from this node.

fn
pub fn Node::xpath_value(Self, String) -> XPathValue raise Refused

The typed answer of an XPath 1.0 expression, read from this node.

type
pub(all) struct ProcessingInstruction {
  target : String
  data : String
}

A processing instruction: <?target data?>, with data the raw text between the target and the ?>, so an instruction round-trips exactly.

type
pub(all) struct Repairs {
  mut implied : Int32
  mut dropped : Int32
  mut reparented : Int32
  mut closed_at_eof : Int32
}

What the HTML parser repaired. WHATWG says repairs happen silently; this tally makes them answerable afterwards, for a caller who wants to ask.

fn
pub fn Repairs::any(Self) -> Bool

Whether the parser repaired anything at all.

fn
pub fn Repairs::new() -> Self

A tally with nothing in it.

fn
pub fn Repairs::total(Self) -> Int32

Every repair the parser made, added up.

type
pub struct Selection {
  items : Array[Node]
  // private fields
}

A selection: the nodes a query returned, and the document they belong to. The empty result is an empty list, never a special value, so a chain never branches — and every query method exists on Selection, on Element and on Document, so a chain never has to stop at a node. doc.xpath("//ul").css("li.external").xpath("@href") .selector("tag", "a").custom(DeepLinks::new()) .items[2].children[0].css("span").text()

fn
pub fn Selection::add_class(Self, String) -> Unit

Add a class to every selected element.

fn
pub fn Selection::append(Self, Node) -> Unit

Append a node to every selected element.

fn
pub fn Selection::at(Self, Int32) -> Node

selection[i] in the chain: the node at that position, so a chain can step down into one node and carry on. Out of range answers a detached empty element rather than panicking.

fn
pub fn Selection::attr(Self, String) -> String?

The named attribute of the first selected element that carries it.

fn
pub fn Selection::by_class(Self, String) -> Self

The elements among the descendants that carry the class name.

fn
pub fn Selection::by_id(Self, String) -> Self

The elements among the descendants whose id attribute is id.

fn
pub fn Selection::by_name(Self, String) -> Self

The elements among the descendants whose name attribute is name.

fn
pub fn Selection::by_tag(Self, String) -> Self

The elements among the descendants whose name is name; * answers them all.

fn
pub fn Selection::children(Self) -> Self

The children of every selected node.

fn
pub fn Selection::clear(Self) -> Unit

Drop the children of every selected element.

fn
pub fn Selection::closest(Self, String) -> Self raise Refused

The nearest ancestor — self included — matching a CSS selector.

fn
pub fn Selection::css(Self, String) -> Self raise Refused

Narrow with a CSS selector, Selectors Level 4's statically decidable subset. Searches the descendants of the selected nodes — the context itself is never a candidate, querySelectorAll's rule.

fn
pub fn Selection::custom(Self, &Selector) -> Self raise Refused

Run a selector that was never registered: no name, no state.

fn
pub fn Selection::descendants(Self) -> Self

Every node below the selected nodes, in document order.

fn
pub fn Selection::eq(Self, Int32) -> Self

The selected node at i; a negative index counts from the end, the way jQuery's eq does. Out of range answers empty.

fn
pub fn Selection::filter(Self, (Node) -> Bool) -> Self

Keep the selected nodes a closure accepts.

fn
pub fn Selection::first(Self) -> Self

The first selected node; empty stays empty.

fn
pub fn Selection::html(Self) -> String

The inner HTML of the first selected element, written in the flavour its document was read as; "" when the selection holds no element.

fn
pub fn Selection::last(Self) -> Self

The last selected node; empty stays empty.

fn
pub fn Selection::length(Self) -> Int32

How many nodes the selection holds.

fn
pub fn Selection::new() -> Self

An empty selection, belonging to no document.

fn
pub fn Selection::of(Array[Node]) -> Self

A selection of these nodes, in the order given, carrying the document the first of them belongs to.

fn
pub fn Selection::parent(Self) -> Self

The parent of every selected node that has one.

fn
pub fn Selection::prepend(Self, Node) -> Unit

Insert a node as the first child of every selected element.

fn
pub fn Selection::remove(Self) -> Unit

Detach every selected element from its parent.

fn
pub fn Selection::remove_attr(Self, String) -> Unit

Remove an attribute from every selected element.

fn
pub fn Selection::remove_class(Self, String) -> Unit

Remove a class from every selected element.

fn
pub fn Selection::replace_with(Self, Node) -> Unit

Put a node in the place of every selected element.

fn
pub fn Selection::selector(Self, String, String) -> Self raise Refused

Run a selector by the name it was registered under, built-in or the caller's own. An unregistered name raises.

fn
pub fn Selection::set_attr(Self, String, String) -> Unit

Set an attribute on every selected element.

fn
pub fn Selection::set_text(Self, String) -> Unit

Replace the children of every selected element with one text node.

fn
pub fn Selection::smooth(Self) -> Unit

Fuse adjacent text nodes under every selected element.

fn
pub fn Selection::text(Self) -> String

The text content of every selected node, concatenated.

fn
pub fn Selection::unwrap(Self) -> Unit

Replace every selected element with its children.

fn
pub fn Selection::wrap(Self, String) -> Unit

Wrap every selected element in a fresh element of this name.

fn
pub fn Selection::xpath(Self, String) -> Self raise Refused

Narrow the selection with an XPath 1.0 expression, evaluated with each selected node as the context node. The answer is a node-set; an expression that evaluates to a string, number or boolean answers its string value as one text node, so the chain never breaks — doc.xpath("string(//h1)").text() reads the way it should. xpath_value is the typed answer.

fn
pub fn Selection::xpath_value(Self, String) -> XPathValue raise Refused

The typed XPath 1.0 answer: nodes, a string, a number or a boolean.

type
pub struct SelectorFn {
  f : (Selection, String) -> Selection raise Refused
}

A selector that is a closure — the shape a selector with no state of its own takes. A selector that carries configuration is a struct implementing Selector directly, with a constructor of its own.

fn
pub fn SelectorFn::new((Selection, String) -> Selection raise Refused) -> Self

A selector made of a closure: the shape one with no state of its own takes.

fn
pub impl Selector for SelectorFn

SelectorFn implements Selector.

type
pub(all) enum XPathValue {
  Nodes(Selection)
  Str(String)
  Num(Double)
  Flag(Bool)
}

An XPath 1.0 result: what the expression actually answered.

Values

fn
pub fn dump(Node) -> Bytes

The XML serialization of a node, as bytes.

fn
pub fn dump_html(Node) -> Bytes

The HTML serialization of a node, as bytes.

fn
pub fn dumps(Node) -> String

The XML serialization of a node.

fn
pub fn dumps_html(Node) -> String

The HTML serialization of a node, WHATWG's rules.

fn
pub fn local_of(String) -> String

The local part of a {uri}local name.

moonxml/html

The WHATWG parser: tolerant, repairing, and never refusing.

Traits

fn
pub fn named_reference(String) -> String?

The named character references HTML defines — all 2231 spellings of them, in the table the standard keeps, generated into entities_table.mbt. A name that may be written without its semicolon is in the table twice, so named_reference("amp") and named_reference("amp;") answer the same &. An unknown name answers None, which is the tokenizer's cue to leave the text as it stands.

Values

fn
pub fn load(Bytes) -> @moonxml.Document

Read a document from bytes; UTF-8, with a leading byte-order mark skipped. A byte that is not UTF-8 reads as U+FFFD, the way a browser reads it.

fn
pub fn loads(String) -> @moonxml.Document

Read a document.

fn
pub fn loads_fragment(String, context? : String) -> @moonxml.Document

Read a fragment the way innerHTML does: the markup is read inside context, an element named as one would write it, and the fragment's nodes come back under the document's root. The name may be a foreign one — svg desc, math mi — in the spelling the standard's test corpus uses, since an SVG <title> is not an HTML one.

moonxml/xml

The XML 1.0 parser: strict, with namespaces, and with the offset of the fault.

Traits

fn
pub fn scan(String, &@event.Sink, fragment? : Bool, limit? : Int32, entity_limit? : Int32) -> Unit raise @moonxml.Refused

Stream a document's events into a sink, building nothing. limit and entity_limit are as for loads.

Values

fn
pub let entity_limit : Int32

How many characters of entity expansion one document may spend. A million is well past what a document that means something needs, and well under what one built to expand for ever would ask for.

fn
pub let limit : Int32

How deep elements may nest before a document is refused. Chrome and WebKit stop at 512 nested elements; a document deeper than that is a stack to eat, not a document.

fn
pub fn load(Bytes, limit? : Int32, entity_limit? : Int32) -> @moonxml.Document raise @moonxml.Refused

Read a document from bytes; UTF-8, with a leading byte-order mark skipped. limit and entity_limit are as for loads.

fn
pub fn loads(String, limit? : Int32, entity_limit? : Int32) -> @moonxml.Document raise @moonxml.Refused

Read a document and answer its tree. limit bounds the element nesting, entity_limit the total expansion of entities.

fn
pub fn loads_fragment(String, limit? : Int32, entity_limit? : Int32) -> @moonxml.Document raise @moonxml.Refused

Read content that has no single root — several elements, or text beside them — into a document whose root holds them. Not a well-formed document, which is the point: it is for a snippet.

moonxml/event

The streaming vocabulary — what a parser emits and what a sink receives.

Traits

type
pub(all) enum Event {
  StartTag(name~ : String, attrs~ : Array[(String, String)], self_closing~ : Bool)
  EndTag(name~ : String)
  Text(text~ : String)
  CData(text~ : String)
  Comment(text~ : String)
  ProcessingInstruction(target~ : String, data~ : String)
  Doctype(text~ : String)
}

One event of a document being read: a tag opening, a run of text, a comment. libexpat's second reading of a document, in one type. @xml.scan streams these; Document::events reads a finished tree back as the same stream. HTML has no streaming read — WHATWG's tree construction needs to see the tree it is building — so its events describe a tree that already exists.

type
pub(open) trait Sink {
  fn push(Self, Event) -> Unit
}

Where events go. The tree builder is one implementation; a caller counting tags or writing rows to a database is another, and it never builds a tree.

moonxml/htmx

htmx's attributes, read off a tree and carried out on it: the trigger, the request, the swap.

Traits

fn
pub fn Trigger::parse(String) -> Self

One trigger, from its spelling. The spelling is the event — possibly with a bracketed condition — followed by modifiers separated by spaces. An empty spelling is a click.

Types

type
pub struct Hx {
  element : @moonxml.Element
}

An element's htmx attributes — its own, or the ones it inherits. htmx's attributes travel down the tree: hx-target on a container is the target of every button inside it, until something nearer says otherwise or hx-disinherit stops the inheritance at a boundary. Reading an attribute through Hx is reading it the way htmx would.

fn
pub fn Hx::attr(Self, String) -> String?

The value of hx-<name> — attr("target") is hx-target — inherited from the nearest ancestor that declares it. None when nothing does, and when the nearest declaration is unset.

fn
pub fn Hx::boosted(Self) -> Bool

Whether the element is boosted: hx-boost="true" somewhere on the way up.

fn
pub fn Hx::confirm(Self) -> String?

The question to ask before asking: hx-confirm.

fn
pub fn Hx::element(Self) -> @moonxml.Element

The element the attributes were read off.

fn
pub fn Hx::headers(Self) -> Array[(String, String)]

The headers this element's request carries: hx-headers, a JSON object.

fn
pub fn Hx::indicator(Self) -> @moonxml.Element?

The element that says the request is in flight: hx-indicator, resolved the way a target is.

fn
pub fn Hx::of(@moonxml.Element) -> Self

The htmx attributes of element, as htmx would see them.

fn
pub fn Hx::push_url(Self) -> Bool?

Whether the address bar should follow: hx-push-url. Some(true) and Some(false) are the two things htmx lets it say, None is silence.

fn
pub fn Hx::request(Self, String) -> Request?

The request an event on this element would make, or None when it would make none: no verb, no address, or a trigger that is about something else.

fn
pub fn Hx::target(Self) -> @moonxml.Element?

Where the answer goes: hx-target, resolved. A bare selector is looked up in the document; this, closest …, find …, next … and previous … are resolved from the element that wrote them.

fn
pub fn Hx::triggers(Self) -> Array[Trigger]

What an event on this element asks: the hx-trigger it declares, or the event an element of its kind listens for when it declares none.

fn
pub fn Hx::url(Self) -> String?

Where the request goes: the value of the verb's attribute, or the href of a boosted link, or the action of a boosted form.

fn
pub fn Hx::values(Self) -> Array[(String, String)]

The values this element's request carries: what hx-include names, the element's own fields, and hx-vals over the top of them. A form contributes every control inside it that has a name and is not disabled; a field contributes itself; hx-include adds the fields of whatever its selectors answer. hx-params then keeps or drops names, the way a server would expect.

fn
pub fn Hx::verb(Self) -> String?

The verb this element asks with, in lower case — get, post, put, patch or delete — taken from the first of those it declares. A boosted link asks with get and a boosted form with post, which is what hx-boost is: an ordinary element that becomes a request.

type
pub(all) struct Request {
  verb : String
  url : String
  element : @moonxml.Element
  target : @moonxml.Element
  values : Array[(String, String)]
  headers : Array[(String, String)]
  swap : SwapSpec
  select : String?
  confirm : String?
  push_url : Bool?
  trigger : String
}

A request htmx would have made: the verb, the address, what it carries, and how the answer is put back. Nothing here is sent. A caller reads this, sends it however it likes, and hands the answer to answer.

fn
pub fn Request::address(Self) -> String

The address to send to: a get carries its values in the query, and the other verbs carry them in the body, so only a get has them added here.

fn
pub fn Request::answer(Self, String) -> @moonxml.Selection

Put an answer into the page: parse it, take the part the element asked for, send the out-of-band pieces to the places they name, and swap the rest into the target. The nodes that went in are answered, in the order they were put there.

fn
pub fn Request::headers(Self) -> Array[(String, String)]

The headers to send: what the element declared, and the four htmx adds so that a server knows what it is answering.

fn
pub fn Request::query(Self) -> String

The values as application/x-www-form-urlencoded text, without the ?.

type
pub(all) enum Swap {
  Inner
  Outer
  BeforeBegin
  AfterBegin
  BeforeEnd
  AfterEnd
  Delete
  NoSwap
}

Where an answer goes. The first six are the ones the DOM can be told to do without asking a stylesheet; Delete takes the target away, and NoSwap keeps the answer out of the page entirely — for a response that is only out-of-band content.

fn
pub fn Swap::spec(Self) -> String

The position as htmx spells it.

type
pub(all) struct SwapSpec {
  mut style : Swap
  mut delay : Int32
  mut settle : Int32
  mut transition : Bool
  mut ignore_title : Bool
}

How an answer goes there: the position, and the timing a page might want to know about.

fn
pub fn SwapSpec::new() -> Self

The default: the inside of the target, at once.

fn
pub fn SwapSpec::parse(String) -> Self

A hx-swap spelling: a position and, after it, modifiers. innerHTML, outerHTML, beforebegin, afterbegin, beforeend, afterend, delete and none are the positions; swap:100ms, settle:50ms, transition:true and ignoreTitle:true are the modifiers this reader keeps. scroll: and show: are the page's business, and are read but not carried out.

type
pub(all) struct Trigger {
  mut event : String
  mut filter : String?
  mut once : Bool
  mut changed : Bool
  mut delay : Int32
  mut throttle : Int32
  mut from : String?
  mut target : String?
  mut queue : String?
  mut consume : Bool
}

When an element asks: the event, and the conditions htmx puts on it. hx-trigger="keyup changed delay:500ms from:#search" is one trigger; hx-trigger="click, keyup[key=='Enter']" is two.

fn
pub fn Trigger::default_for(@moonxml.Element) -> Self

What an element listens for when it does not say: a form is submitted, a field changes, and everything else is clicked.

fn
pub fn Trigger::list(String) -> Array[Self]

Every trigger a spelling names, in the order it names them. click, keyup[key=='Enter'] changed delay:500ms is two triggers. A comma inside a condition does not split.

fn
pub fn Trigger::matches(Self, String) -> Bool

Whether this trigger is about event.

❦