Idiom.Interpolation (idiom v0.6.8)

Functionality for interpolating variables into a message.



Interpolates a message with a map of bindings.


Link to this function

interpolate(message, bindings)

@spec interpolate(String.t(), map()) :: String.t()

Interpolates a message with a map of bindings.

The message can include variables wrapped in {{}}. For example, in the string Hello, {{name}}!, {{name}} is a variable. If a variable exists in the message , but not in the bindings, it is converted to a string in-place.

The binding can be any value that implements the String.Chars protocol.


iex> Idiom.Interpolation.interpolate("Hello, {{name}}!", %{name: "John"})
"Hello, John!"

iex> Idiom.Interpolation.interpolate("Hello, {{name}}! It is {{day_of_week}}.", %{name: "John", day_of_week: "Monday"})
"Hello, John! It is Monday."

iex> Idiom.Interpolation.interpolate("Hello, {{name}}! It is {{day_of_week}}.", %{name: "John"})
"Hello, John! It is day_of_week."