ExAdmin v0.8.3-build.2 ExAdmin.Utils

A collection of utility functions.

Summary

Functions

URL helper for routes related to associations

URL helper to build assistant admin paths

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

admin_association_path(resource, assoc_name, method \\ nil, args \\ [])

URL helper for routes related to associations

Examples:

iex> ExAdmin.Utils.admin_association_path(%TestExAdmin.Product{id: 1}, :tags)
"/admin/products/1/tags"

iex> ExAdmin.Utils.admin_association_path(%TestExAdmin.Product{id: 1}, :tags, :update_positions)
"/admin/products/1/tags/update_positions"
admin_path()

URL helper to build assistant admin paths

Examples:

iex> ExAdmin.Utils.admin_path
"/admin"

iex> ExAdmin.Utils.admin_path(:page, [:dashboard])
"/admin/page/dashboard"

iex> ExAdmin.Utils.admin_path(:select_theme, [1])
"/admin/select_theme/1"
admin_path(method, args \\ [])
admin_resource_path(resource_or_model, method \\ nil, args \\ [])

URL helper to build admin paths for CRUD

Examples:

iex> ExAdmin.Utils.admin_resource_path(TestExAdmin.Product)
"/admin/products"

iex> ExAdmin.Utils.admin_resource_path(%TestExAdmin.Product{})
"/admin/products/new"

iex> ExAdmin.Utils.admin_resource_path(%TestExAdmin.Product{id: 1})
"/admin/products/1"

iex> ExAdmin.Utils.admin_resource_path(%TestExAdmin.Product{id: 1}, :edit)
"/admin/products/1/edit"

iex> ExAdmin.Utils.admin_resource_path(%TestExAdmin.Product{id: 1}, :update)
"/admin/products/1"

iex> ExAdmin.Utils.admin_resource_path(%TestExAdmin.Product{id: 1}, :destroy)
"/admin/products/1"

iex> ExAdmin.Utils.admin_resource_path(TestExAdmin.Product, :create)
"/admin/products"

iex> ExAdmin.Utils.admin_resource_path(TestExAdmin.Product, :batch_action)
"/admin/products/batch_action"

iex> ExAdmin.Utils.admin_resource_path(TestExAdmin.Product, :csv)
"/admin/products/csv"

iex> ExAdmin.Utils.admin_resource_path(%Plug.Conn{assigns: %{resource: %TestExAdmin.Product{}}}, :index, [[scope: "active"]])
"/admin/products?scope=active"
articlize(string)

Add a an or a in front of a word.

Examples

iex> ExAdmin.Utils.articlize("hat")
"a hat"

iex> ExAdmin.Utils.articlize("apple")
"an apple"
displayable_name_singular(conn)
extract_controller_name(name)
humanize(item, from \\ ~r"[_ ]", to \\ " ")

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> ExAdmin.Utils.humanize :first_name
"First Name"

iex> ExAdmin.Utils.humanize "last-name", ~r/[-]/
"Last Name"
not_in(list1, list2)

Returns a list of items from list1 that are not in list2

parameterize(atom)
pluralize(atom)

Return the plural of a term.

Returns a string give an atom or a string.

pluralize(atom, count)

Return the plural of a term based on a passed count.

If count is equal to 1, return the singular. Otherwise, return the plural.

titleize(atom)

Converts camel case items to human readable form.

Examples

iex> ExAdmin.Utils.titleize "MyModel"
"My Model"