PhoenixTestDatastar.DOM
(PhoenixTestDatastar v0.0.2)
Copy Markdown
Applies Datastar SSE patch events to an in-memory HTML string using Floki.
Supports various patch modes:
:outer- Morph by ID or replace element matching selector:inner- Replace children of target element:append- Add children at end of target:prepend- Add children at start of target:before- Insert siblings before target:after- Insert siblings after target:replace- Replace entire element matching selector:remove- Remove elements matching selector
Summary
Functions
Applies a patch to raw HTML and returns the updated HTML string.
Types
Functions
Applies a patch to raw HTML and returns the updated HTML string.
Parameters
raw_html- The full HTML document as a stringpatch- A map with:mode,:selector, and optionally:elements
Examples
iex> html = "<div id='app'><span id='count'>0</span></div>"
iex> patch = %{mode: :outer, selector: "", elements: "<span id='count'>1</span>"}
iex> PhoenixTestDatastar.DOM.apply_patch(html, patch)
"<div id='app'><span id='count'>1</span></div>"