Caravela.Gen.RestController (Caravela v0.13.3)

Copy Markdown View Source

Generates Phoenix controllers that render Svelte components via caravela_svelte's Inertia-style transport (:rest render mode).

One controller per entity. Actions: index, show, new, edit, create, update, delete. Each action calls CaravelaSvelte.Caravela.put_field_access/2 before rendering so the Svelte component receives the entity's field_access prop under the same key regardless of render mode.

Unlike Caravela.Gen.Controller (which emits pure JSON APIs), controllers produced here assume the consumer app has caravela_svelte installed and mounted in its router.

The generator only emits files for entities declared with frontend: :rest in the Caravela.Domain DSL. When an entity also declares realtime: true, the generated controller calls CaravelaSvelte.Caravela.broadcast_patch/3 after each state-changing action — create, update, delete.

Returns a list of {path, source} tuples. Files preserve content below the # --- CUSTOM --- marker on regeneration.

Summary

Functions

Render a controller for every :rest entity in the domain.

Render a single :rest controller.

Functions

render_all(domain, opts \\ [])

@spec render_all(
  Caravela.Schema.Domain.t(),
  keyword()
) :: [{String.t(), String.t()}]

Render a controller for every :rest entity in the domain.

render_entity(domain, entity, opts \\ [])

Render a single :rest controller.