Skip to content

Commit

Permalink
Allow empty attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
ream88 committed Apr 9, 2024
1 parent 9b32252 commit 5170d22
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,15 @@ iex> TwiML.say("Sorry, calls are currently unavailable")
"""
```

Empty attributes are not included in the generated TwiML:
Attributes with a value of nil are excluded from the generated TwiML:

```elixir
iex> TwiML.say("Hello", voice: "", loop: nil)
iex> TwiML.gather(input: "dtmf", finish_on_key: "", num_digits: nil)
...> |> TwiML.to_xml()
"""
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>Hello</Say>
<Gather input="dtmf" finishOnKey=""/>
</Response>\
"""
```
Expand Down
11 changes: 5 additions & 6 deletions lib/twiml.ex
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,14 @@ defmodule TwiML do
end

defp build_verb(verb, attrs, children) do
verb = verb |> Atom.to_string() |> String.capitalize()
verb =
verb
|> Atom.to_string()
|> String.capitalize()

attrs =
attrs
|> Enum.reject(fn
{_, nil} -> true
{_, ""} -> true
_ -> false
end)
|> Enum.reject(&is_nil(elem(&1, 1)))
|> Enum.map(fn {k, v} -> {camelize(k, :lower), v} end)

{verb, attrs, children}
Expand Down

0 comments on commit 5170d22

Please sign in to comment.