- layout/logo.wo: the mark as inline SVG — dark tile, two-stroke "W" (white then accent blue). One source: nav brand + /favicon.svg - favicon/controller.wo: GET /favicon.svg, image/svg+xml, day cache - install/: GET /install — toolchain tarball, PATH, verify, first project, build/run, adding a dep. Copy from the real install README - packages/: GET /packages + /packages/:name — catalogue with the [deps] line, what each library gives you, and a usage snippet. Index cards are child components (multi Component) - wo-html: page_head(title, head, body) and a `head` slot on Layout — a favicon link or meta tag had nowhere else to go; page() passes "" - header: Install/Tutorial/Packages/GitHub, brand shows the mark - main.wo: SITE_HOST picks the interface (loopback default), bound address printed at startup - site-accept: 11 -> 17 checks (install, packages x2, 404, favicon, inline logo) Verified on 192.168.0.165:8080 — every route, favicon bytes, and the mark rasterised at 256px and 32px. Gates: oop-accept MET, site 17/0, web-app 46/0, fibers 10/0, db-actor 8/0; shop rebuilt clean. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
89 lines
5.2 KiB
Text
89 lines
5.2 KiB
Text
-- 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 framework/http
|
|
use html
|
|
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: "framework",
|
|
summary: "A web framework written in writeonce: an HTTP/1.1 keep-alive server core, a router with :param captures, and Handler/Middleware structural interfaces.",
|
|
git: "https://github.com/shoneyj/writeonce-framework",
|
|
rev: "v0.1.0",
|
|
what: `
|
|
<ul class="list-disc pl-6 leading-relaxed">
|
|
<li class="mb-2"><code>App</code> — the route table and the middleware chains; <code>app.get</code>/<code>post</code>/<code>delete_</code>, <code>use_mw</code>, <code>use_after</code>, <code>mount</code>, <code>serve</code>.</li>
|
|
<li class="mb-2"><code>Handler</code>, <code>Middleware</code>, <code>After</code> — structural interfaces. A handler is a CLASS; its fields are the closure this language does not have.</li>
|
|
<li class="mb-2"><code>Req</code>/<code>Resp</code> plus builders: <code>ok_text</code>, <code>ok_html</code>, <code>ok_json</code>, <code>created_json</code>, <code>not_found</code>, <code>bad_request</code>, <code>unauthorized</code>, <code>conflict</code>, <code>redirect</code>.</li>
|
|
<li class="mb-2">Auth MECHANISM only — <code>bearer_token</code>, <code>basic_credentials</code>, constant-time <code>ct_eq</code>. Which routes are gated stays your policy.</li>
|
|
<li class="mb-2">Bodies: <code>form_values</code>, <code>multipart_parts</code>, content negotiation, ETags, security headers, CORS, WebSocket frames.</li>
|
|
</ul>`,
|
|
usage: code_block("use framework\nuse framework/http\nuse framework/router\n\nclass Hello {\n fn handle(req: Req) -> Resp {\n return ok_text(\"hello\");\n }\n}\n\nfn main(args: multi Text) -> Int {\n let app = App { middleware: [], routes: [] };\n app.use_mw(Mw { m: Logging {} });\n app.get(\"/\", Hello {});\n return app.serve(\"127.0.0.1\", 8080);\n}")
|
|
});
|
|
|
|
push(out, PackageInfo {
|
|
name: "html",
|
|
summary: "Server-rendered HTML as plain Text: escaping, element builders, a component layer, and a Tailwind-style utility stylesheet inlined into every page.",
|
|
git: "https://github.com/shoneyj/wo-html",
|
|
rev: "v0.1.0",
|
|
what: `
|
|
<ul class="list-disc pl-6 leading-relaxed">
|
|
<li class="mb-2"><code>esc()</code> — escapes <code>& < > "</code>. A <code>{{ }}</code> 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 <code>{{</code> would BE a hole.)</li>
|
|
<li class="mb-2"><code>Component</code> — a class with fields and <code>fn render() -> Text</code>, satisfied structurally. <code>multi Component</code> holds children directly; <code>render_all</code> renders them in order.</li>
|
|
<li class="mb-2"><code>Layout</code> — content projection: title, head, nav, content and footer as pre-rendered slots.</li>
|
|
<li class="mb-2">Builders: <code>el</code>, <code>link</code>, <code>card</code>, <code>nav_bar</code>, <code>code_block</code>, <code>form_post</code>, <code>text_input</code>, <code>text_area</code>, <code>submit_btn</code>, <code>btn_link</code>.</li>
|
|
<li class="mb-2"><code>tw_css()</code> + <code>page()</code> — one hand-written utility sheet, inlined, so a page is one self-contained response. No CDN, no build step, no JS.</li>
|
|
</ul>`,
|
|
usage: code_block("use html\n\nclass Card {\n name: Text\n fn render() -> Text {\n return `\n <div class=\"card\">\n <h3>{{ self.name }}</h3>\n </div>`;\n }\n}\n\n-- in a handler:\nlet c = Card { name: user_supplied };\nreturn ok_html(page(\"Hello\", c.render()));")
|
|
});
|
|
|
|
return out;
|
|
}
|