Aurora. Uix. RouteHelper
(Aurora UIX v0.1.4-rc.7)
Copy Markdown
Provides macros for generating standard LiveView routes for resource-based CRUD operations.
Summary
Functions
Generates standard LiveView routes for resource CRUD operations.
Functions
Generates standard LiveView routes for resource CRUD operations.
Creates a set of LiveView routes following a consistent pattern for managing resources. Routes are bound to action names (:index, :new, :edit, :show, :show_edit) for LiveView event handling.
The macro expands to up to five live routes with the following pattern:
GET /path→.Indexmodule with:indexactionGET /path/new→.Indexmodule with:newactionGET /path/:id/edit→.Indexmodule with:editactionGET /path/:id/show→.Indexmodule with:showactionGET /path/:id/show-edit→.Indexmodule with:show_editaction
Parameters
path(binary()) - Base URL path segment (e.g.,"/users","/products").module(module()) - Base LiveView module name. Must have.Indexand.Showsubmodules.opts(Keyword.t()) - Options::only(list(atom())) - Generate only the specified actions. Valid actions::index,:new,:edit,:show,:show_edit.:except(list(atom())) - Exclude the specified actions from generation.
Returns
Macro.t() - Quoted expression expanding to live/3 route definitions.
Examples
Generate all routes (default):
import Aurora.Uix.RouteHelper
auix_live_resources("/users", MyApp.UserLive)
# Expands to:
live "/users", MyApp.UserLive.Index, :index
live "/users/new", MyApp.UserLive.Index, :new
live "/users/:id/edit", MyApp.UserLive.Index, :edit
live "/users/:id/show", MyApp.UserLive.Index, :show
live "/users/:id/show-edit", MyApp.UserLive.Index, :show_editGenerate only index and show routes:
auix_live_resources("/users", MyApp.UserLive, only: [:index, :show])
# Expands to:
live "/users", MyApp.UserLive.Index, :index
live "/users/:id/show", MyApp.UserLive.Index, :showGenerate all routes except new and edit (read-only mode):
auix_live_resources("/users", MyApp.UserLive, except: [:new, :edit])
# Expands to:
live "/users", MyApp.UserLive.Index, :index
live "/users/:id/show", MyApp.UserLive.Index, :show
live "/users/:id/show-edit", MyApp.UserLive.Index, :show_edit