Livex.RenderedManipulator (livex v0.2.0)

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

attribute_snippets(attributes, assigns)

format_attribute(name, value, prefix \\ nil, type \\ nil)

Formats an attribute for inclusion in an HTML tag.

Parameters

  • name - The attribute name
  • value - The attribute value
  • prefix - Optional prefix for the attribute name
  • type - Optional type for the attribute name

Returns

  • A formatted attribute string

manipulate_rendered(mode, rendered, attributes, assigns, options \\ nil)

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 manipulate
  • attributes - List of attribute strings to add
  • options - 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 with
      • hook_name - Optional hook name to add
      • id - Optional ID to add to the wrapping tag

maybe_add_dom_id(id)

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)
""

maybe_prepend_route(arg1, attributes)

wrap_in_div(rendered, module, assigns)