writeonce/docs/examples/shop/layout/app.wo
shoney.arickathil ffd791d05b refactor(porch): name the web framework porch, fix the wo.toml identifier claim
- 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>
2026-08-26 19:36:34 +02:00

50 lines
1.7 KiB
Text

-- layout/app.wo — the app shell (app.html's analog): one full document
-- wrapping every page with the shared header and footer. Styles are NOT
-- inlined — pages link /assets/style.css (served by static_files), so
-- markup and styling stay separate files.
use porch/http
use view
-- The app shell as a COMPONENT (writeonce-view's `Component`: fields in, Text
-- out), the same shape as writeonce-view's own `Layout` — two slots instead of
-- four, and its own document rather than `page()`'s, because this
-- template deliberately LINKS a stylesheet instead of inlining one.
-- That is the whole reason it is not just `Layout`: markup and styling
-- stay separate files here.
pub class AppShell {
title: Text
content: Text
fn render() -> Text {
return `
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>{{ self.title }}</title>
<link rel="stylesheet" href="/assets/style.css">
</head>
<body>
${header()}
<main class="site-main">${self.content}</main>
${footer()}
</body>
</html>`;
}
}
-- `ok_html` is the FRAMEWORK's (http/types.wo, beside ok_text/ok_json):
-- a status line and a content-type is transport, not rendering, and both
-- HTML samples had hand-rolled the identical four lines.
pub fn html_error(status: Int, title: Text, msg: Text) -> Resp {
let content = `
<h1>{{ title }}</h1>
<p>{{ msg }}</p>
<p><a href="/">Back to products</a></p>`;
let shell = AppShell { title: "shop — ${title}", content: content };
let h: map<Text, Text> = {};
h["content-type"] = "text/html; charset=utf-8";
return Resp { status: status, headers: h, body: shell.render() };
}