Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support variables in verb options #13

Merged
merged 2 commits into from
Jan 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Change Log

## [v2.0.1](https://github.com/danielberkompas/ex_twiml/tree/v2.0.1) (2015-12-14)
[Full Changelog](https://github.com/danielberkompas/ex_twiml/compare/v2.0.0...v2.0.1)
## [Unreleased](https://github.com/danielberkompas/ex_twiml/tree/HEAD)

[Full Changelog](https://github.com/danielberkompas/ex_twiml/compare/v2.0.0...HEAD)

**Closed issues:**

Expand Down
28 changes: 14 additions & 14 deletions SIGNED.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - https://gpgtools.org

iQIcBAABCgAGBQJWbv0bAAoJEKU82t1CbYQMbPwP/3EApRyBem+nwJUVoFSFHZeL
IV4qdNm3o7zFuK/0YHOxVxvDCiEAL73fOc6oyu1DLRrz9OjFJf5zlU21aTzNXUPo
tn19up1k+by0Z6Da84bBjEWV8Iq4Q/QhH0a2IzKQyNb54Vr1UVHJztmrrsvLdxpD
grDKGbozjmC0WqAXwrbrTYMy7kejFIt56rJ/K09Ov2VVFFndQbTVgnKlG5D5eiLy
51llttlONCqV+otAlaIwRAR+pUMS/J3/kH7qENz45u6jm+/j4yaYfGan/l6YXR+r
MpxBkc+OZz6MnnEQowUmEaBeKR/2MRuMKOgLSUBwWnrs/ie0cbEh8+oUt69I2MeD
46PoNP6M3CJW340B6l1XF4A4e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```
Expand All @@ -37,7 +37,7 @@ size exec file contents
819 reserved_name_error.ex 84adb553bbaba0cc06294f2b0f830d9a6907ada0da029a2fc6980b0efce1b662
2303 utilities.ex 213e05588339362c187cec619b21655c8c1ebf1c573d1e3b9fa067065b313bbe
7786 ex_twiml.ex 27024f4039bcba5907c5aeaa4893023a5b609a7acffcbaf6d22d714fd9de82b6
1403 mix.exs f77046b32aa7876d16907901673ff7a2ab0bf4843dc30063b652451bb2126167
1392 mix.exs c819531658050d6b27ae93835686dc59eef11d3638fd2414e1429d4184589000
```

#### Ignore
Expand Down
18 changes: 10 additions & 8 deletions lib/ex_twiml.ex
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ defmodule ExTwiml do

# Non-nested
:say, :number, :play, :sms, :sip, :client, :conference, :queue, :enqueue,
:leave, :hangup, :reject, :pause, :record, :redirect, :body, :media
:redirect, :body, :media
]

@simple_verbs [:leave, :hangup, :reject, :pause, :record]

@doc """
Start creating a TwiML document. Returns the rendered TwiML as a string.
See the `ExTwiml` documentation to see how to call TwiML verbs from within
Expand Down Expand Up @@ -203,23 +205,23 @@ defmodule ExTwiml do
end

# {:say, [], ["Hello World", [voice: "woman"]}
defp postwalk({verb, _meta, [string, options]}) when verb in @verbs and is_list(options) do
defp postwalk({verb, _meta, [string, options]}) when verb in @verbs do
compile_simple(verb, string, options)
end

# {:pause, [], [[length: 5]]}
defp postwalk({verb, _meta, [options]}) when verb in @verbs and is_list(options) do
compile_empty(verb, options)
end

# {:say, [], ["Hello World"]}
# {:say, [], ["Hello #{var}"]} (String interpolation)
defp postwalk({verb, _meta, [string]}) when verb in @verbs do
compile_simple(verb, string)
end

# {:pause, [], [[length: 5]]}
defp postwalk({verb, _meta, [options]}) when verb in @simple_verbs do
compile_empty(verb, options)
end

# {:leave, [], Elixir}
defp postwalk({verb, _meta, _args}) when verb in @verbs do
defp postwalk({verb, _meta, _args}) when verb in @simple_verbs do
compile_empty(verb)
end

Expand Down
29 changes: 29 additions & 0 deletions test/ex_twiml_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,35 @@ defmodule ExTwimlTest do
assert_twiml markup, "<Say>123</Say>"
end

test ".twiml simple verbs can take options as a variable" do
options = [voice: "alice"]
markup = twiml do
say "I'm Alice", options
end

assert_twiml markup, "<Say voice=\"alice\">I'm Alice</Say>"
end

test ".twiml self-closing verbs can take options as a variable" do
options = [length: 31]
markup = twiml do
pause options
end

assert_twiml markup, "<Pause length=\"31\" />"
end

test ".twiml nested verbs can take options as a variable" do
options = [method: "GET"]
markup = twiml do
gather options do
say "Hi"
end
end

assert_twiml markup, "<Gather method=\"GET\"><Say>Hi</Say></Gather>"
end

test ".twiml warns of reserved variable names" do
ast = quote do
twiml do
Expand Down