Phoenix.Naming

Conveniences for inflecting and working with names in Phoenix.

Source

Summary

base_concat(mod, submodule \\ nil)

Finds the Base Namespace of the module with optional concat

camelize(value)

Converts String to camel case

resource_name(alias, suffix \\ "")

Extracts the resource name from an alias

underscore(value)

Converts String to underscore case

unsuffix(value, suffix)

Removes the given suffix from the name if it exists

Functions

base_concat(mod, submodule \\ nil)

Finds the Base Namespace of the module with optional concat.

Examples

iex> Phoenix.Naming.base_concat(MyApp.MyChannel)
MyApp

iex> Phoenix.Naming.base_concat(MyApp.Admin.MyChannel, PubSub)
MyApp.PubSub

iex> Phoenix.Naming.base_concat(MyApp.Admin.MyChannel, "PubSub")
MyApp.PubSub
Source
camelize(value)

Specs:

Converts String to camel case.

Examples

iex> Phoenix.Naming.camelize("my_app")
"MyApp"

iex> Phoenix.Naming.camelize(:my_app)
"MyApp"

In general, camelize can be thought of as the reverse of underscore, however, in some cases formatting may be lost:

Phoenix.Naming.underscore "SAPExample"  #=> "sap_example"
Phoenix.Naming.camelize   "sap_example" #=> "SapExample"
Source
resource_name(alias, suffix \\ "")

Specs:

Extracts the resource name from an alias.

Examples

iex> Phoenix.Naming.resource_name(MyApp.User)
"user"

iex> Phoenix.Naming.resource_name(MyApp.UserView, "View")
"user"
Source
underscore(value)

Specs:

Converts String to underscore case.

Examples

iex> Phoenix.Naming.underscore("MyApp")
"my_app"

iex> Phoenix.Naming.underscore(:MyApp)
"my_app"

iex> Phoenix.Naming.underscore("my-app")
"my_app"

In general, underscore can be thought of as the reverse of camelize, however, in some cases formatting may be lost:

Phoenix.Naming.underscore "SAPExample"  #=> "sap_example"
Phoenix.Naming.camelize   "sap_example" #=> "SapExample"
Source
unsuffix(value, suffix)

Specs:

Removes the given suffix from the name if it exists.

Examples

iex> Phoenix.Naming.unsuffix("MyApp.User", "View")
"MyApp.User"

iex> Phoenix.Naming.unsuffix("MyApp.UserView", "View")
"MyApp.User"
Source