PhxAdmin v0.9.1 PhxAdmin.Utils
A collection of utility functions.
Summary
Functions
URL helper for routes related to associations
URL helper to build assistant admin paths
URL helper to build admin paths for CRUD
Add a an or a in front of a word
Convert a field name to its human readable form
Generate html for a link
Returns a list of items from list1 that are not in list2
Return the plural of a term
Return the plural of a term based on a passed count
Converts camel case items to human readable form
Functions
URL helper for routes related to associations
Examples:
iex> PhxAdmin.Utils.admin_association_path(%TestExAdmin.Product{id: 1}, :tags)
"/admin/products/1/tags"
iex> PhxAdmin.Utils.admin_association_path(%TestExAdmin.Product{id: 1}, :tags, :update_positions)
"/admin/products/1/tags/update_positions"
URL helper to build assistant admin paths
Examples:
iex> PhxAdmin.Utils.admin_path
"/admin"
iex> PhxAdmin.Utils.admin_path(:page, [:dashboard])
"/admin/page/dashboard"
iex> PhxAdmin.Utils.admin_path(:select_theme, [1])
"/admin/select_theme/1"
URL helper to build admin paths for CRUD
Examples:
iex> PhxAdmin.Utils.admin_resource_path(TestExAdmin.Product)
"/admin/products"
iex> PhxAdmin.Utils.admin_resource_path(%TestExAdmin.Product{})
"/admin/products/new"
iex> PhxAdmin.Utils.admin_resource_path(%TestExAdmin.Product{id: 1})
"/admin/products/1"
iex> PhxAdmin.Utils.admin_resource_path(%TestExAdmin.Product{id: 1}, :edit)
"/admin/products/1/edit"
iex> PhxAdmin.Utils.admin_resource_path(%TestExAdmin.Product{id: 1}, :update)
"/admin/products/1"
iex> PhxAdmin.Utils.admin_resource_path(%TestExAdmin.Product{id: 1}, :destroy)
"/admin/products/1"
iex> PhxAdmin.Utils.admin_resource_path(TestExAdmin.Product, :create)
"/admin/products"
iex> PhxAdmin.Utils.admin_resource_path(TestExAdmin.Product, :batch_action)
"/admin/products/batch_action"
iex> PhxAdmin.Utils.admin_resource_path(TestExAdmin.Product, :csv)
"/admin/products/csv"
iex> PhxAdmin.Utils.admin_resource_path(%Plug.Conn{assigns: %{resource: %TestExAdmin.Product{}}}, :index, [[scope: "active"]])
"/admin/products?scope=active"
Add a an or a in front of a word.
Examples
iex> PhxAdmin.Utils.articlize("hat")
"a hat"
iex> PhxAdmin.Utils.articlize("apple")
"an apple"
Convert a field name to its human readable form.
Converts items like field names to a form suitable for display labels and menu items. By default, converts _ to space and capitalizes each word.
The conversion can be customized by passing a from regex and to regex as the 2nd and 3rd arguments.
Examples:
iex> PhxAdmin.Utils.humanize :first_name
"First Name"
iex> PhxAdmin.Utils.humanize "last-name", ~r/[-]/
"Last Name"
Generate html for a link
Syntax
iex> PhxAdmin.Utils.link_to("click me", "/something", class: "link btn", style: "some styling")
{:safe, "<a href='/something' class='link btn' style='some styling' >click me</a>"}
Return the plural of a term based on a passed count.
If count is equal to 1, return the singular. Otherwise, return the plural.