writeonce/docs/examples/shop/orders/view.wo
shoney.arickathil bbf5fb66d3 feat(shop): 37 target = in-class raw template literals (developer form)
- separate view.html files dropped; every render() now carries its
  '-- 37 target:' literal above the hand-lowered body — the pair is
  the DX referendum in one file
- story 37 re-pointed: raw multi-line literal + {{ }} auto-escaped
  typed holes + {!! !!} raw slots; structural control stays if/for;
  w:if/w:for and .html files demoted to later; forks revised
- rebuild verified on untouched toolchain

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

72 lines
2.2 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- orders/view.wo — the confirmation page and the orders table. The
-- comment above each render() is the STORY-37 TARGET (raw template
-- literal, {{ }} auto-escaped); the body is today's hand-lowering.
use html
pub class OrderOk {
name: Text
qty: Int
total: Float
-- 37 target:
-- return `
-- <div class="card">
-- <h1>Order placed</h1>
-- <p>{{ self.qty }} × {{ self.name }} — total € {{ self.total }}</p>
-- <p><a href="/orders">See all orders</a> · <a href="/">Keep shopping</a></p>
-- </div>`;
fn render() -> Text {
let head = el("h1", "", "Order placed");
let what = el("p", "", "${self.qty} × ${esc(self.name)} — total € ${self.total}");
let links = el("p", "", link("/orders", "", "See all orders") .. " · " .. link("/", "", "Keep shopping"));
return el("div", "card", head .. what .. links);
}
}
pub class OrderRow {
name: Text
qty: Int
total: Float
status: Text
-- 37 target:
-- return `
-- <tr>
-- <td>{{ self.name }}</td>
-- <td>{{ self.qty }}</td>
-- <td>€ {{ self.total }}</td>
-- <td>{{ self.status }}</td>
-- </tr>`;
fn render() -> Text {
let cells = el("td", "", esc(self.name));
cells = cells .. el("td", "", "${self.qty}");
cells = cells .. el("td", "", "€ ${self.total}");
cells = cells .. el("td", "", esc(self.status));
return el("tr", "", cells);
}
}
pub class OrdersPage {
rows: Text
-- 37 target:
-- if self.rows == "" {
-- return `<h1>Orders</h1>
-- <p>No orders yet — <a href="/">go buy something</a>.</p>`;
-- }
-- return `
-- <h1>Orders</h1>
-- <table class="orders">
-- <tr><th>Product</th><th>Qty</th><th>Total</th><th>Status</th></tr>
-- {!! self.rows !!}
-- </table>`;
fn render() -> Text {
let head = el("h1", "", "Orders");
if self.rows == "" {
return head .. el("p", "", "No orders yet — " .. link("/", "", "go buy something") .. ".");
}
let thead = el("tr", "", el("th", "", "Product") .. el("th", "", "Qty") .. el("th", "", "Total") .. el("th", "", "Status"));
let table = el("table", "orders", thead .. self.rows);
return head .. table;
}
}