x_component v0.1.0 X.Html View Source
Contains a set of functions to build a valid and safe HTML from X templates.
Link to this section Summary
Functions
Converts attr value into HTML-safe iodata
Converts given attrs into HTML-safe iodata
Merges given attrs and returns a list with key-value tuples
Converts given value into HTML-safe iodata
Link to this section Functions
Converts attr value into HTML-safe iodata:
iex> X.Html.attr_value_to_iodata("<test>")
[[[] | "<"], "test" | ">"]
"style"
and "class"
attr values are joined with a delimiter:
iex> X.Html.attr_value_to_iodata([{"color", "#fff"}, {"font", "small"}], "style")
[["color", ": ", "#fff"], "; ", ["font", ": ", "small"]]
Converts given attrs into HTML-safe iodata:
iex> X.Html.attrs_to_iodata(%{"demo" => true, "env" => "<test>"})
[["demo", '="', "true", '"'], 32, "env", '="', [[[] | "<"], "test" | ">"], '"']
Merges given attrs and returns a list with key-value tuples:
iex> X.Html.merge_attrs(%{demo: true, env: "test"}, [demo: false])
[{"env", "test"}, {"demo", false}]
It doesn't override "style"
and "class"
attributes from base_attrs
but adds merged values into the list:
iex> X.Html.merge_attrs(
...> %{style: [{"color", "#fff"}, {"size", 1}]},
...> [style: [{"color", "#aaa"}, {"font", "test"}]]
...> )
[{"style", [{"size", 1}, {"color", "#aaa"}, {"font", "test"}]}]
Converts given value into HTML-safe iodata:
iex> X.Html.to_safe_iodata("<test>")
[[[] | "<"], "test" | ">"]