View Source LiveUI.Router (LiveUI v0.1.0)

Macro which defines a set of routes for given Ecto.Schema module.

Summary

Functions

Helper that generates all required routes for a resource.

Functions

Link to this macro

live_ui(path, live_module, schema_module)

View Source (macro)

Helper that generates all required routes for a resource.

# router.ex
scope "/", MyAppWeb do
  scope "/admin", Admin do

    # generate all routes
    live_ui("/companies", UserLive, MyApp.Admin.User)

    # or define each one
    live("/users", UserLive.Index, :index)
    live("/users/new", UserLive.Index, :new)
    live("/users/:id", UserLive.Show, :show)
    live("/users/:id/edit", UserLive.Show, :edit)
    live("/users/:id/delete", UserLive.Show, :delete)
  end
end

UserLive.Index and UserLive.Show modules should call the macro to get basic Phoenix.LiveView implementation:

# lib/my_app_web/live/admin/user_live/index.ex
defmodule MyAppWeb.Admin.UserLive.Index do
  use LiveUI.Views.Index, for: MyApp.Admin.User
end

# lib/my_app_web/live/admin/user_live/show.ex
defmodule MyAppWeb.Admin.UserLive.Index do
  use LiveUI.Views.Show, for: MyApp.Admin.User
end

These modules will provide code to display and process data which is customized via LiveUI protocol.

live_ui/3 will also generate routes for any custom action defined via LiveUI protocol:

live("/users/custom", UserLive.Index, :custom)
live("/users/:id/custom", UserLive.Show, :custom)