View Source Routex.Path (Phoenix Routes Extension Framework v0.1.0-alpha.3)

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.

Creates a match pattern for binary path, segments list and AST. The result is input type agnostic.

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.

Link to this section Functions

Link to this function

add_prefix(input, prefix)

View Source

Prepends given prefix to input. Returns the same type as the input type.

Link to this function

build_path_match(segments)

View Source

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> build_path_match(path_binary)
["products", {:arg0, [], Routex.Path}, "show", "edit"]
iex> build_path_match(path_segments)
["products", {:arg0, [], Routex.Path}, "show", "edit"]
iex> build_path_match(path_ast)
["products", {:arg0, [], Routex.Path}, "show", "edit"]
Link to this function

build_path_match(path, kind)

View Source

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.

Link to this function

recompose(orig_path, new_path, sigil_segments)

View Source

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"]