Idiom.Interpolation (idiom v0.6.5)
Functionality for interpolating variables into a message.
Summary
Functions
Interpolates a message with a map of bindings.
Functions
Link to this function
interpolate(message, bindings)
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.
Examples
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."