Ussd.Menu (Ussd v0.2.0)

Copy Markdown View Source

A fluent builder for the text a Ussd.State renders back to the caller.

Build one with build/0 and grow it with the pipe operator:

Ussd.Menu.build()
|> Ussd.Menu.text("Welcome")
|> Ussd.Menu.line("Select an option")
|> Ussd.Menu.listing(["Airtime", "Data Bundle"])

Implements String.Chars, so a menu can be interpolated or passed anywhere a string is expected.

Summary

Functions

Appends another menu's content, or the menu built by a (menu -> menu) function.

Starts an empty menu.

Appends :io_lib.format/2-formatted text, e.g. format(menu, "Balance: ~s", ["GHS 10"]).

Appends text followed by a newline.

Appends times blank lines (default 1).

Appends a numbered listing of items.

Prepends another menu's content, or the menu built by a (menu -> menu) function.

Appends raw text with no trailing newline.

Appends key translated via the configured Gettext backend (see trans/4).

Like trans/4, but followed by a newline - the translated counterpart to line/2.

Types

t()

@type t() :: %Ussd.Menu{content: String.t()}

Functions

append(menu, fun)

@spec append(t(), t() | (t() -> t())) :: t()

Appends another menu's content, or the menu built by a (menu -> menu) function.

build()

@spec build() :: t()

Starts an empty menu.

format(menu, format, args \\ [])

@spec format(t(), String.t() | charlist(), [term()]) :: t()

Appends :io_lib.format/2-formatted text, e.g. format(menu, "Balance: ~s", ["GHS 10"]).

line(menu, text)

@spec line(t(), String.t()) :: t()

Appends text followed by a newline.

line_break(menu, times \\ 1)

@spec line_break(t(), pos_integer()) :: t()

Appends times blank lines (default 1).

listing(menu, items, opts \\ [])

@spec listing(t(), [String.Chars.t()], keyword()) :: t()

Appends a numbered listing of items.

Options:

  • :numbering - (index :: non_neg_integer() -> String.Chars.t()), defaults to &(&1 + 1)
  • :spacer - separates the number from the item, defaults to "."
  • :divider - separates items, defaults to "\n"
  • :page / :per_page - slice items before rendering, like Laravel's paginated listings

prepend(menu, fun)

@spec prepend(t(), t() | (t() -> t())) :: t()

Prepends another menu's content, or the menu built by a (menu -> menu) function.

text(menu, text)

@spec text(t(), String.t()) :: t()

Appends raw text with no trailing newline.

trans(menu, key, bindings \\ %{}, locale \\ nil)

@spec trans(t(), String.t(), map(), String.t() | nil) :: t()

Appends key translated via the configured Gettext backend (see trans/4).

trans_line(menu, key, bindings \\ %{}, locale \\ nil)

@spec trans_line(t(), String.t(), map(), String.t() | nil) :: t()

Like trans/4, but followed by a newline - the translated counterpart to line/2.