View Source Routex.Path (Phoenix Routes Extension Framework v0.2.0-alpha.7)
Provides functions that work with both a binary path and a list of segments; unless explicitly stated otherwise.
Link to this section Summary
Functions
Prepends given prefix
to input
. Returns the same type as
the input type.
Joins a (nested) list of path segments into a binary path..
Joins consecutive static segments using the path separator. Splits at interpolation placeholders when provided with a path.
Converts the input
to a list of segments. It's a convenience wrapper for
Plug.Router.Utils.split/1 to also handle nil value and segment lists.
Additionally queries will always have their own segment.
Creates a match pattern for binary path, segments list and AST. The result is input type agnostic.
Link to this section Functions
Prepends given prefix
to input
. Returns the same type as
the input type.
Joins a (nested) list of path segments into a binary path..
Joins consecutive static segments using the path separator. Splits at interpolation placeholders when provided with a path.
Converts the input
to a list of segments. It's a convenience wrapper for
Plug.Router.Utils.split/1 to also handle nil value and segment lists.
Additionally queries will always have their own segment.
Examples
iex> split(nil)
[]
iex> split("/foo/bar/?baz=qux")
["foo", "bar", "?baz=qux"]
iex> split(["/foo/bar", "/baz"])
["foo", "bar", "baz"]
Creates a match pattern for binary path, segments list and AST. The result is input type agnostic.
Provides an option to bind parameters. This is disabled by default as it
may cause "unused variables" warnings and the result is less compatible.
Notice how the last example binds to product
as id
is not known.
Options
bind
: bind any parameter to a named variable. (default:false
)
Example
iex> path_binary = "/products/:id/show/edit?_action=delete"
iex> path_segments = ["products", ":id", "show", "edit?_garg=bar"]
iex> path_ast = quote do: "/products/#{product}/show/edit?search=baz"
iex> to_match_pattern(path_binary)
["products", {:arg0, [], Routex.Path}, "show", "edit"]
iex> to_match_pattern(path_segments)
["products", {:arg0, [], Routex.Path}, "show", "edit"]
iex> to_match_pattern(path_ast)
["products", {:arg0, [], Routex.Path}, "show", "edit"]