Helper functions and macros for Phlex components.
This module provides convenience macros and functions to make component definition easier and more idiomatic.
Summary
Functions
Macro to define a component with a simpler API.
Macro to define an SVG component with a simpler API.
Escapes HTML entities in a string.
Extracts bindings from keyword list or map.
Merges attributes intelligently, handling arrays, sets, hashes, and strings.
Functions
Macro to define a component with a simpler API.
Example
defcomponent Card do
def view_template(assigns, state) do
state
|> div([class: "card"], fn state ->
Phlex.SGML.append_text(state, assigns.title)
end)
end
endThis is equivalent to:
defmodule Card do
use Phlex.HTML
def view_template(assigns, state) do
# ...
end
end
Macro to define an SVG component with a simpler API.
Escapes HTML entities in a string.
Extracts bindings from keyword list or map.
Example
grab(foo: foo, bar: bar)
# => {foo, bar} if multiple, or single value if one
Merges attributes intelligently, handling arrays, sets, hashes, and strings.
Example
mix([class: "foo"], [class: "bar"])
# => [class: "foo bar"]
mix([class: ["a", "b"]], [class: ["c"]])
# => [class: ["a", "b", "c"]]