Livex.RenderedManipulator (livex v0.1.2)
A utility library for manipulating Phoenix.LiveView.Rendered structs.
Summary
Functions
Formats an attribute for inclusion in an HTML tag.
Manipulates a Phoenix.LiveView.Rendered struct by either injecting attributes or wrapping content.
Conditionally adds an ID attribute to an HTML element.
Functions
Formats an attribute for inclusion in an HTML tag.
Parameters
name
- The attribute namevalue
- The attribute valueprefix
- Optional prefix for the attribute nametype
- Optional type for the attribute name
Returns
- A formatted attribute string
Manipulates a Phoenix.LiveView.Rendered struct by either injecting attributes or wrapping content.
Options
:inject
- Injects attributes into the first static chunk:wrap
- Wraps the content with a new tag that has the specified attributes
Parameters
mode
- Either:inject
or:wrap
rendered
- The Phoenix.LiveView.Rendered struct to manipulateattributes
- List of attribute strings to addoptions
- Additional options depending on the mode:- For
:inject
mode:hook_name
- Optional hook name to add
- For
:wrap
mode:tag
- The HTML tag to wrap content withhook_name
- Optional hook name to addid
- Optional ID to add to the wrapping tag
- For
Conditionally adds an ID attribute to an HTML element.
Returns an ID attribute string if the ID is provided, otherwise returns an empty string.
Examples
iex> maybe_add_dom_id("my-element")
" id=\"my-element\""
iex> maybe_add_dom_id(nil)
""