-- packages/controller.wo — GET /packages and /packages/:name. -- -- The catalogue is static data, not rows, so it lives here on the DATA -- side of the feature rather than in the view: the components are handed -- values exactly as they would be if this were a table one day. use serve/http use view use layout typedef PackageInfo = { name: Text, summary: Text, git: Text, rev: Text, what: Text, usage: Text } pub class ShowPackages { fn handle(req: Req) -> Resp { let cards: multi Component = []; for p in catalogue() { push(cards, PackageCard { name: p.name, summary: p.summary }); } let page = PackagesPage { cards: cards }; let shell = reading_shell("writeonce — packages", page.render()); return ok_html(shell.render()); } } pub class ShowPackage { fn handle(req: Req) -> Resp { let name = req.params["name"]; if name == nil { return html_error(404, "No such package", "The address names no package."); } for p in catalogue() { if p.name == name { let page = PackagePage { name: p.name, summary: p.summary, git: p.git, rev: p.rev, what: p.what, usage: p.usage }; let shell = reading_shell("writeonce — ${p.name}", page.render()); return ok_html(shell.render()); } } return html_error(404, "No such package", "Nothing is published under that name."); } } -- The two libraries this site runs on. Both are `kind = "library"` -- projects: no `fn main`, imported through `[deps]`. fn catalogue() -> multi PackageInfo { let out: multi PackageInfo = []; push(out, PackageInfo { name: "serve", summary: "The web framework: an HTTP/1.1 keep-alive server core, a router with :param captures, and Handler/Middleware structural interfaces.", git: "https://github.com/shoneyj/writeonce-serve", rev: "v0.1.0", what: `
App — the route table and the middleware chains; app.get/post/delete_, use_mw, use_after, mount, serve.StaticFiles — serve a directory over a wildcard route. Traversal is refused, not normalised; max_bytes is a hard ceiling. This site's /dl downloads run through it.Handler, Middleware, After — structural interfaces. A handler is a CLASS; its fields are the closure this language does not have.Req/Resp plus builders: ok_text, ok_html, ok_json, created_json, not_found, bad_request, unauthorized, conflict, redirect.bearer_token, basic_credentials, constant-time ct_eq. Which routes are gated stays your policy.form_values, multipart_parts, content negotiation, ETags, security headers, CORS, WebSocket frames.esc() — escapes & < > ". A {{ }} hole in a raw text literal compiles to a call to it, so display data is escaped by construction. (Written with entities here: inside a raw literal, a real {{ would BE a hole.)Component — a class with fields and fn render() -> Text, satisfied structurally. multi Component holds children directly; render_all renders them in order.Layout — content projection: title, head, nav, content and footer as pre-rendered slots.el, link, card, nav_bar, code_block, form_post, text_input, text_area, submit_btn, btn_link.tw_css() + page() — one hand-written utility sheet, inlined, so a page is one self-contained response. No CDN, no build step, no JS.