| 1 | # manifest/ — the declarative path |
| 2 | |
| 3 | Manifest-driven and code-driven are equal, optional paths: declare the |
| 4 | resources that are pure CRUD, hand-write the ones that aren't, per |
| 5 | resource, in one app. One TOML file here declares a whole screen set — |
| 6 | List → Show → Edit/New plus the confirm-page delete flow — generated |
| 7 | as 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 | |
| 19 | The vocabulary covers one flat table per resource, three field kinds, |
| 20 | no relations. Add `scope = "user"` and every generated query is |
| 21 | owner-filtered by the session subject — someone else's row answers |
| 22 | 404 — for resources a user owns; mount those routes behind |
| 23 | `sessions.Require`. Add `store = "mergeable"` and the resource lives as |
| 24 | event-log streams (tombstone deletes, derive-on-read) instead of a |
| 25 | sqlc table — it needs no sqlc tool. Relations or a custom flow: |
| 26 | hand-write it. |
| 27 | |
| 28 | Adding the first manifest to this app: |
| 29 | |
| 30 | 1. `go get -tool github.com/sqlc-dev/sqlc/cmd/sqlc` (once — the |
| 31 | generated store is sqlc input). |
| 32 | 2. `rastrillo generate` writes gen/ — committed, never hand-edited. |
| 33 | 3. 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 | |
| 45 | 4. Append the generated migrations to the schema step, and add |
| 46 | `rastrillo generate --check` to the Makefile's ci target. |
| 47 | |
| 48 | Drop to a .go manifest in this directory (package manifest, a |
| 49 | `var X = rastrillo.Resource{...}`) the moment you need a function |
| 50 | value — a custom Column.Render, say. To take any single generated |
| 51 | screen over by hand, write your own action file at the same computed |
| 52 | path under actions/ — the generator skips that one from then on. |
| 53 | |