writeonce/docs/examples/shop/layout/app.wo
shoney.arickathil a4743edcc6 fix(shop): views markup-first within today's grammar
- render() bodies: one HTML line per 'h = h ..' statement, single-
  quoted attributes, ${} holes, esc() on data — el() chains gone
- discovered + recorded gap #3: no multi-line expressions or literals
  (leading/trailing .. and paren grouping all reject at NEWLINE) —
  exactly the tax story 37's raw literal deletes
- 37-target comment blocks dropped (bodies now self-explanatory; the
  README states the delta); rebuilt + full buy-flow re-smoked (178.0
  total, stock 12->10, 409, traversal 404)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-24 00:23:39 +02:00

36 lines
1.4 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 framework/http
use html
pub fn app_shell(title: Text, content: Text) -> Text {
let h = "<!doctype html><html><head>";
h = h .. "<meta charset='utf-8'>";
h = h .. "<meta name='viewport' content='width=device-width,initial-scale=1'>";
h = h .. "<title>${esc(title)}</title>";
h = h .. "<link rel='stylesheet' href='/assets/style.css'>";
h = h .. "</head><body>";
h = h .. header();
h = h .. "<main class='site-main'>${content}</main>";
h = h .. footer();
h = h .. "</body></html>";
return h;
}
-- The one transport helper every controller shares: a 200 HTML Resp.
pub fn ok_html(body: Text) -> Resp {
let h: map<Text, Text> = {};
h["content-type"] = "text/html; charset=utf-8";
return Resp { status: 200, headers: h, body: body };
}
pub fn html_error(status: Int, title: Text, msg: Text) -> Resp {
let c = "<h1>${esc(title)}</h1>";
c = c .. "<p>${esc(msg)}</p>";
c = c .. "<p><a href='/'>Back to products</a></p>";
let h: map<Text, Text> = {};
h["content-type"] = "text/html; charset=utf-8";
return Resp { status: status, headers: h, body: app_shell("shop — ${title}", c) };
}