-- 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: ` `, 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: ` `, usage: code_block("use html\n\nclass Card {\n name: Text\n fn render() -> Text {\n return `\n
\n

{{ self.name }}

\n
`;\n }\n}\n\n-- in a handler:\nlet c = Card { name: user_supplied };\nreturn ok_html(page(\"Hello\", c.render()));") }); return out; }