View Source Backpex.Router (Backpex v0.8.1)

Provides LiveView routing for Backpex resources.

Summary

Functions

Checks whether the to path is the same as the current path

Finds the cookie path by the given socket.

Filters actions based on only and except parameters.

Finds the raw path by the given socket and module and puts the path params into the raw path.

Defines "RESTful" routes for a Backpex resource.

Checks whether item is member of list and returns default value if list is nil or empty.

Replace path params with actual params

Functions

Link to this function

active?(current_path, to_path)

View Source

Checks whether the to path is the same as the current path

Examples

iex> Backpex.Router.active?(URI.new!("https://example.com/admin/events"), "/admin/events")
true
iex> Backpex.Router.active?(URI.new!("https://example.com/admin/events"), "/admin/users")
false
Link to this macro

backpex_routes()

View Source (macro)
Link to this function

filter_actions(actions, only, except)

View Source

Filters actions based on only and except parameters.

Examples

iex> Backpex.Router.filter_actions([:index, :edit, :show], [:index], nil)
[:index]
iex> Backpex.Router.filter_actions([:index, :edit, :show], nil, [:index])
[:edit, :show]
iex> Backpex.Router.filter_actions([:index, :edit, :show], nil, nil)
[:index, :edit, :show]
iex> Backpex.Router.filter_actions([:index, :edit, :show], [], [])
[:index, :edit, :show]
Link to this function

get_path(socket, module, params, action, params_or_item \\ %{})

View Source

Finds the raw path by the given socket and module and puts the path params into the raw path.

Link to this function

get_path(socket, module, params, action, id_or_instance, query_params)

View Source
Link to this function

has_resource_actions?(module, live_resource)

View Source
Link to this macro

live_resources(path, live_resource, options \\ [])

View Source (macro)

Defines "RESTful" routes for a Backpex resource.

Options

  • :only - List of actions to generate routes for, for example: [:index, :show].
  • :except - List of actions to exclude generated routes from, for example: [:edit].

Example

defmodule MyAppWeb.Router
  import Backpex.Router

  scope "/admin", MyAppWeb do
    pipe_through :browser

    live_session :default, on_mount: Backpex.InitAssigns do
      live_resources("/users", UserLive, only: [:index])
    end
  end
end
Link to this function

member?(list, item, default)

View Source

Checks whether item is member of list and returns default value if list is nil or empty.

Examples

iex> Backpex.Router.member?([:index], :index, true)
true
iex> Backpex.Router.member?([:edit], :index, true)
false
iex> Backpex.Router.member?([], :index, true)
true
iex> Backpex.Router.member?(nil, :index, true)
true
Link to this function

put_route_params(route, params)

View Source

Replace path params with actual params

Examples

iex> Backpex.Router.put_route_params("/:param1/events/:param2/show", %{"param1" => "123", "param2" => "xyz", "test" => "abcdef"})
"/123/events/xyz/show"
iex> Backpex.Router.put_route_params("/:param1/events/:id/edit", %{"param1" => "123", "id" => "xyz"})
"/123/events/xyz/edit"
iex> Backpex.Router.put_route_params("/:param1/events/:id/edit", %{"param1" => "123", "id" => "hällö / world"})
"/123/events/h%C3%A4ll%C3%B6+%2F+world/edit"
iex> Backpex.Router.put_route_params("/events", %{"param1" => "123", "param2" => "xyz"})
"/events"
iex> Backpex.Router.put_route_params("/events", %{})
"/events"