Aurora.Uix.RouteHelper (Aurora UIX v0.1.4-rc.3)

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

auix_live_resources(path, module, opts \\ [])

(macro)
@spec auix_live_resources(binary(), module(), keyword()) :: Macro.t()

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.Index module with :index action
  • GET /path/new.Index module with :new action
  • GET /path/:id/edit.Index module with :edit action
  • GET /path/:id/show.Index module with :show action
  • GET /path/:id/show-edit.Index module with :show_edit action

Parameters

  • path (binary()) - Base URL path segment (e.g., "/users", "/products").
  • module (module()) - Base LiveView module name. Must have .Index and .Show submodules.
  • 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_edit

Generate 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, :show

Generate 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