Motus

A template language for Jaiweb

HTML that knows your types.

Motus is HTML plus a few elements — output, let, if, for, match, components, regions, routes — compiled against the Jai types your app already has. A misspelled member is a build error, not a blank on the page.

  • Compiled with your program
  • Native, WebAssembly, the edge
  • Escaped by default
views/examples/hello.mot
<!-- A template is HTML that reads a view: here a Shop (samples.jai). Every name below is checked against
     that type when the template compiles. -->
<article class="shop">
  <h1><output store.name></h1>
  <p class="muted"><output store.tagline></p>
  <ul>
    <for p in where(products, "status", "ACTIVE")>
      <li>
        <b><output p.name></b> · <Price cents=p.price currency=store.currency />
        <if p.stock == 0><Badge tone="bad">Sold out</Badge></if>
      </li>
    </for>
  </ul>
  <p><output cart> <output plural(cart, "item", "items")> in your cart</p>
</article>

Rendered · sample shop200
81 instructions · 137 run · 419 bytes outOpen in playground →
The HTML it rendered
<article class="shop">
  <h1>Ana &amp; Co</h1>
  <p class="muted">&lt;b&gt;Shoes&lt;/b&gt; made by hand in Porto</p>
  <ul>
    <li><b>Tênis Azul</b> · <span class="price">€89,00</span></li>
    <li><b>Bota &lt;Couro&gt;</b> · <span class="price">€219,00</span></li>
    <li><b>Sandália Rio</b> · <span class="price">€54,00</span><span data-m-270290e3 class="badge bad">Sold out</span></li>
  </ul>
  <p>2 items in your cart</p>
</article>

In one screen

What Motus is

01

Compiled against your types

A template reads a Jai struct. Every name, member, prop, function and call is checked when the app builds: a typo stops the build with its line, its column and the members that do exist.

See it →
02

Native, WebAssembly, the edge

A compiled template is plain data: a small program that reads the view in place. The same VM runs it in the server, in a WebAssembly build of the app, and in a Cloudflare worker.

See it →
03

Components, three levels of style

Typed props, defaults, children, <@slot> fills. Styles at the root, scoped to a component (nesting with &, props as var(name)), or on one element.

See it →
04

Regions that stream and update live

A region is replaced alone on navigation, its <loading> shown at once. A first render streams the frame, then each region; a live one renders again when the rows it read change.

See it →
05

Routes, typed calls, actions

An entry's <routes> are its pages, their params typed. Its data comes from controller procedures called as expressions; its forms call @Actions, whose notes check the inputs.

See it →
07

State, without a script of yours

bind= ties a control to the URL's state, <state> keeps the page's, on:click= writes either, a typed form holds a Jai value. The compiler draws in the browser what it can, asks origin for the parts only origin can draw, alone.

See it →
06

Edge caching by read set

An edge page is made in two places: origin's part once, the request's part at the edge. Each part is cached by what it read and purged when that changes, so a write drops only what it touched.

See it →

Mistakes are build errors

The compiler reads your types, so a typo never ships.

These three templates are compiled right now, against the playground's Shop. Under each is what the compiler answered: the message a build stops with, line and column first.

In an app the templates compile with the program (motus_program, an entry's motus_mount), so a template that no longer fits its type is caught before anything runs.

<h1><output store.nmae></h1>

1:13: Shop_Store has no member 'nmae' (it has: name, tagline, currency, accent)

<if cart><b>Your cart</b></if>

1:5: a condition is a bool; this is an int: compare it (cart gt 0, cart neq 0)

<for p in products><output p.price | uppercase></for>

1:36: a function is called, f(x), not piped: x | f

Small programs

A template is a program you can ship anywhere.

Static HTML merges into single literals, constants fold, a branch on a constant keeps only the branch taken. What is left is a few instructions, serialized as plain data for a worker or a WebAssembly unit to run.

12examples in the tour
1,027instructions in all
28components, the kit's too
73.8 KBserialized, all of them

Where next

Read it, run it, use it.