ExTwiml.Utilities

A grab bag of helpful functions used to generate XML.

Summary

camelize(string)

Convert a string to headless camelCase

capitalize(atom)

Capitalize a string or atom

create_tag(type, name, options \\ [])

Generates an XML tag

xml_attributes(attrs)

Generate a list of HTML attributes from a keyword list. Keys will be converted to headless camelCase

Functions

camelize(string)

Specs:

Convert a string to headless camelCase.

Examples

...> ExTwiml.Utilities.camelize("finish_on_key")
"finishOnKey"
capitalize(atom)

Specs:

Capitalize a string or atom.

Examples

iex> ExTwiml.Utilities.capitalize(:atom)
"Atom"

iex> ExTwiml.Utilities.capitalize("string")
"String"
create_tag(type, name, options \\ [])

Specs:

Generates an XML tag.

Examples

iex> ExTwiml.Utilities.create_tag(:opening, :say, [voice: "woman"])
"<Say voice=\"woman\">"

iex> ExTwiml.Utilities.create_tag(:self_closed, :pause, [length: 5])
"<Pause length=\"5\" />"

iex> ExTwiml.Utilities.create_tag(:closing, :say)
"</Say>"
xml_attributes(attrs)

Specs:

Generate a list of HTML attributes from a keyword list. Keys will be converted to headless camelCase.

See the camelize/1 function for more details.

Examples

iex> ExTwiml.Utilities.xml_attributes([digits: 1, finish_on_key: "#"])
" digits=\"1\" finishOnKey=\"#\""