- docs/examples/writeonce-serve -> docs/examples/porch (git mv, history kept); `[deps]` key and import are now `porch` / `porch/http` / `porch/router` - name history preserved on the library README, not rewritten into dated records: writeonce-framework -> writeonce-serve (08-25) -> porch (08-26). Stories, specs, plans and the audit reports keep the older name by the repo's own convention; only live docs and every path link were rewritten - left alone deliberately: `internal/serve.wo`, `pub fn serve`, `serve_conn`, `app.serve(...)` — those are functions, not the module name - web-app/wo.toml comment corrected: it claimed hyphens are not identifier characters and named a key this file never used. lexer.ml's `is_ident_cont` DOES accept `-` (an internal dash is part of the identifier, which is why binary minus needs spaces), so a hyphenated key would be legal too - site now teaches the name: package card, the two-deps chapter and the handlers-are-classes chapter say `porch`; site-accept asserted the old /packages/serve route and caught the rename, as a gate should - gates: web-app 46/0, site 21/0, deps-accept 8/0, oop-e2e 116/0, linkcheck 0 broken / 0 anchors; porch typechecks entry-less as kind=library Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
90 lines
5.4 KiB
Text
90 lines
5.4 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 porch/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: "porch",
|
|
summary: "The writeonce web framework: an HTTP/1.1 keep-alive server core, a router with :param captures, and Handler/Middleware structural interfaces. Imported as <code>use porch</code>.",
|
|
git: "https://github.com/shoneyj/porch",
|
|
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>StaticFiles</code> — serve a directory over a wildcard route. Traversal is refused, not normalised; <code>max_bytes</code> is a hard ceiling. This site's <code>/dl</code> downloads run through it.</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 porch\nuse porch/http\nuse porch/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: "view",
|
|
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/writeonce-view",
|
|
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 view\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;
|
|
}
|