View Source Routex.Extension.AlternativeGetters (Phoenix Routes Extension Framework v0.3.0-alpha.4)

Creates helper functions to get a list of alternative slugs and their Routex attributes by providing the function a binary url.

Configuration

# file /lib/example_web/routex_backend.ex
defmodule ExampleWeb.RoutexBackend do
  use Routex.Backend,
  extensions: [
    Routex.Extension.Alternatives,
+   Routex.Extension.AlternativeGetters,
    Routex.Extension.AttrGetters
],

Routex.Attrs

Requires

  • none

Sets

  • none

Helpers

  • alternatives(url :: String.t()) :: struct()

Example

iex> ExampleWeb.Router.RoutexHelpers.alternatives("/products/12?foo=baz")
[ %Routex.Extension.AlternativeGetters{
  slug: "products/12/?foo=baz",
  match?: true,
  attrs: %{
    __branch__: [0, 12, 0],
    __origin__: "/products/:id",
    [...attributes set by other extensions...]
  }},
  %Routex.Extension.AlternativeGetters{
  slug: "/europe/products/12/?foo=baz",
  match?: true,
  attrs: %{
    __branch__: [0, 12, 1],
    __origin__: "/products/:id",
    [...attributes set by other extensions...]
  }},
 %Routex.Extension.AlternativeGetters{
  slug: "/asia/products/12/?foo=baz",
  match?: true,
  attrs: %{
    __branch__: [0, 12, 1],
    __origin__: "/products/:id",
    [...attributes set by other extensions...]
  }},
]