Lab42.Html v0.1.4 Lab42.Html.Tool View Source

Link to this section Summary

Functions

By default we will number a list starting with 1 and increment by the same value

Wrap result depending on options, by default we will wrap for usage in Phoenix templates.

Link to this section Functions

Link to this function

numbered(list, options \\ [])

View Source

By default we will number a list starting with 1 and increment by the same value

  iex(0)> numbered(~w[a b c])
  [{1, "a"}, {2, "b"}, {3, "c"}]

However one or both of these default values can be changed

  iex(1)> numbered(~w[alpha beta gamma]a, start: 40)
  [{40, :alpha}, {41, :beta}, {42, :gamma}]

  iex(2)> numbered(~w[three one minus_one], start: 3, increment: -2)
  [{3, "three"}, {1, "one"}, {-1, "minus_one"}]
Link to this function

result(messages, value, options \\ [])

View Source

Wrap result depending on options, by default we will wrap for usage in Phoenix templates.

  iex(3)> result([], "42")
  {:safe, "42"}

It also transforms bindata into a string if necessary

  iex(4)> result([], ["4", ["2"]])
  {:safe, "42"}

In the case of an error that transformation still works

  iex(5)> result([{:error, "typo", nil}], ["42"])
  {:error, "42", [{:error, "typo", nil}]}

And last, but not least, the success tag can be changed

  iex(6)> result([], ~w{hello world}, success_tag: :ok)
  {:ok, "helloworld"}