Voodoo.PathBuilder (Bonfire v1.0.1-social-alpha.28)
View SourceBuilds URL paths from route patterns without depending on deprecated Phoenix.Router.Helpers.
Instead of calling user_path(conn, :show, 1), we extract the pattern /users/:id and interpolate it with the provided arguments at runtime.
Summary
Functions
Extracts parameter names from a route path pattern.
Extracts route information and generates path builder clauses.
Interpolates a path pattern with the given arguments.
Functions
Extracts parameter names from a route path pattern.
Examples
iex> extract_params("/users/:id")
[:id]
iex> extract_params("/posts/:post_id/comments/:id")
[:post_id, :id]
iex> extract_params("/feed")
[]
Extracts route information and generates path builder clauses.
Returns a list of function clauses that can be used to build paths from route patterns and arguments.
Interpolates a path pattern with the given arguments.
Filters out module atoms (used for routing) before interpolation.
Examples
iex> interpolate_path("/users/:id", [:id], [123])
"/users/123"
iex> interpolate_path("/@:username", [:username], [Bonfire.Data.Identity.Character, "mayel"])
"/@mayel"
iex> interpolate_path("/posts/:post_id/comments/:id", [:post_id, :id], [5, 10])
"/posts/5/comments/10"
iex> interpolate_path("/feed", [], [])
"/feed"
iex> interpolate_path("/users/:id", [:id], [123, %{page: 2}])
"/users/123?page=2"