oficina / calendar Public

Clone
git clone https://amadan.net/oficina/calendar

Plain git — no account needed to clone.

Download

Download this file

1# manifest/ — the declarative path
2
3Manifest-driven and code-driven are equal, optional paths: declare the
4resources that are pure CRUD, hand-write the ones that aren't, per
5resource, in one app. One TOML file here declares a whole screen set —
6List → Show → Edit/New plus the confirm-page delete flow — generated
7as real committed code under gen/ by `rastrillo generate`:
8
9 name = "ticket_types"
10 route = "/admin/ticket_types"
11
12 [list]
13 columns = [{ field = "Name", kind = "text" }, { field = "Price", kind = "money" }]
14 search = true
15
16 [form]
17 basics = [{ name = "Name", required = true }, { name = "Price", kind = "money" }]
18
19The vocabulary covers one flat table per resource, three field kinds,
20no relations. Add `scope = "user"` and every generated query is
21owner-filtered by the session subject — someone else's row answers
22404 — for resources a user owns; mount those routes behind
23`sessions.Require`. Add `store = "mergeable"` and the resource lives as
24event-log streams (tombstone deletes, derive-on-read) instead of a
25sqlc table — it needs no sqlc tool. Relations or a custom flow:
26hand-write it.
27
28Adding the first manifest to this app:
29
301. `go get -tool github.com/sqlc-dev/sqlc/cmd/sqlc` (once — the
31 generated store is sqlc input).
322. `rastrillo generate` writes gen/ — committed, never hand-edited.
333. Mount the generated router beside the chi router in
34 internal/calendar/app.go, and wire its Ctx (the generated actions
35 render through Ctx.Render — examples/blog's internal/blog/genrender.go
36 in the rastrillo repo is the adapter to copy):
37
38 gmux := gen.Router(func(*http.Request) *rastrillo.Ctx {
39 writer, _ := d.G.DB()
40 return &rastrillo.Ctx{DB: writer, Logger: logger,
41 Actor: rastrillo.Actor{Human: true}, Render: render}
42 })
43 mux.Handle("/admin/", gmux)
44
454. Append the generated migrations to the schema step, and add
46 `rastrillo generate --check` to the Makefile's ci target.
47
48Drop to a .go manifest in this directory (package manifest, a
49`var X = rastrillo.Resource{...}`) the moment you need a function
50value — a custom Column.Render, say. To take any single generated
51screen over by hand, write your own action file at the same computed
52path under actions/ — the generator skips that one from then on.
53