diff --git a/README.md b/README.md index fe1f444..495d271 100644 --- a/README.md +++ b/README.md @@ -10,31 +10,37 @@ Say something: ```elixir iex> TwiML.say("Hello") |> TwiML.to_xml() -~s( +""" + Hello -) +\ +""" ``` Say 2 things, one after the other: ```elixir iex> TwiML.say("Hello") |> TwiML.say("world") |> TwiML.to_xml() -~s( +""" + Hello world -) +\ +""" ``` Say something in another voice: ```elixir iex> TwiML.say("Hello", voice: "woman") |> TwiML.to_xml() -~s( +""" + Hello -) +\ +""" ``` Leaving the content empty for a TwiML verb, will create a TwiML element that has @@ -42,10 +48,12 @@ no body: ```elixir iex> TwiML.hangup() |> TwiML.to_xml() -~s( +""" + -) +\ +""" ``` You can embed TwiML tags into other tags using the `into_*` function: @@ -54,12 +62,14 @@ You can embed TwiML tags into other tags using the `into_*` function: iex> TwiML.say("Lets say this inside the gather") ...> |> TwiML.into_gather(language: "en-US", input: "speech") ...> |> TwiML.to_xml() -~s( +""" + Lets say this inside the gather -) +\ +""" ``` If you have multiple TwiML tags you want to embed, that works too: @@ -69,13 +79,15 @@ iex> TwiML.say("Hi") ...> |> TwiML.say("We cool?") ...> |> TwiML.into_gather(language: "en-US", input: "speech", hints: "yes, no") ...> |> TwiML.to_xml() -~s( +""" + Hi We cool? -) +\ +""" ``` It is also possible to just include a few of the preceding tags into the body of @@ -87,13 +99,15 @@ iex> TwiML.say("Calling Yodel") ...> |> TwiML.number("+1 415-483-0400") ...> |> TwiML.into_dial(1) ...> |> TwiML.to_xml() -~s( +""" + Calling Yodel +1 415-483-0400 -) +\ +""" ``` The `into_*` functions can take the number of preceding tags, attributes or both @@ -106,7 +120,8 @@ iex> TwiML.identity("venkman") ...> |> TwiML.into_client(1, method: "GET") ...> |> TwiML.into_dial(caller: "+1 415-483-0400") ...> |> TwiML.to_xml() -~s( +""" + @@ -116,7 +131,8 @@ iex> TwiML.identity("venkman") stantz -) +\ +""" ``` Multiple calls to `into_*` functions allow building complex nested TwiML @@ -129,7 +145,8 @@ iex> TwiML.identity("venkman") ...> |> TwiML.into_client(3) ...> |> TwiML.into_dial(1) ...> |> TwiML.to_xml() -~s( +""" + @@ -138,7 +155,8 @@ iex> TwiML.identity("venkman") -) +\ +""" ``` Attributes can be provided both as `snake_case` or `camelCase`, but the latter is preferred as the code looks more Elixir-like. @@ -146,10 +164,12 @@ Attributes can be provided both as `snake_case` or `camelCase`, but the latter i ```elixir iex> TwiML.dial("+1 415-483-0400", recordingStatusCallback: "https://example.org", recording_status_callback_method: "POST") ...> |> TwiML.to_xml() -~s( +""" + +1 415-483-0400 -) +\ +""" ``` Safe binary strings, **IO Data** or **CDATA** are supported as well. Make sure @@ -157,37 +177,69 @@ to only mark actually safe data as safe! ```elixir iex> TwiML.say({:safe, "Hello World"}) |> TwiML.to_xml() -"\n\n Hello World\n" +""" + + + Hello World +\ +""" iex> TwiML.say({:iodata, [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]}) |> TwiML.to_xml() -~s(\n\n hello world\n) +""" + + + hello world +\ +""" iex> TwiML.say({:cdata, "\\"}) |> TwiML.to_xml() -~s(\n\n \\]]>\n) +""" + + + \\]]> +\ +""" ``` This also works with attributes: ```elixir iex> TwiML.say({:safe, "Hello World"}, voice: "Polly.Joanna") |> TwiML.to_xml() -"\n\n Hello World\n" +""" + + + Hello World +\ +""" iex> TwiML.say({:iodata, [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]}, voice: "Polly.Joanna") |> TwiML.to_xml() -"\n\n hello world\n" +""" + + + hello world +\ +""" iex> TwiML.say({:cdata, "\\"}, voice: "Polly.Joanna") |> TwiML.to_xml() -"\n\n \\]]>\n" +""" + + + \\]]> +\ +""" ``` Comments can help with debugging (yes, they are somewhat ugly, until `xml_builder` properly supports them): ```elixir iex> TwiML.comment("Blocked because of insufficient funds") |> TwiML.reject() |> TwiML.to_xml() -~s( +""" + Blocked because of insufficient funds -) +\ +""" ``` And can also be chained: @@ -197,12 +249,14 @@ iex> TwiML.say("Sorry, calls are currently unavailable") ...> |> TwiML.comment("Blocked because of insufficient funds") ...> |> TwiML.reject() ...> |> TwiML.to_xml() -~s( +""" + Sorry, calls are currently unavailable Blocked because of insufficient funds -) +\ +""" ``` Empty attributes are not included in the generated TwiML: @@ -210,10 +264,12 @@ Empty attributes are not included in the generated TwiML: ```elixir iex> TwiML.say("Hello", voice: "", loop: nil) ...> |> TwiML.to_xml() -~s( +""" + Hello -) +\ +""" ``` diff --git a/mix.exs b/mix.exs index 27d78d5..0075788 100644 --- a/mix.exs +++ b/mix.exs @@ -14,6 +14,10 @@ defmodule Twiml.MixProject do deps: deps(), description: description(), package: package(), + preferred_cli_env: [ + docs: :docs, + "hex.publish": :docs + ], # Docs name: "TwiML", @@ -26,7 +30,7 @@ defmodule Twiml.MixProject do defp deps do [ {:xml_builder, "~> 2.2"}, - {:ex_doc, "~> 0.24", only: :dev, runtime: false} + {:ex_doc, "~> 0.24", only: :docs} ] end