Phlex.SGML.State (phlex v0.3.0)

Copy Markdown View Source

Rendering state for Phlex components.

Manages the buffer, rendering flags, fragments, and cache capture contexts.

Summary

Functions

Appends content to the buffer.

Increments fragment depth unconditionally.

Begins a named fragment: updates selective-render depth and cache offsets.

Renders a block into an isolated buffer for cache storage.

Captures the output of a block.

Decrements fragment depth unconditionally.

Ends a named fragment: finalizes cache length and clears selective-render membership.

Flushes the buffer to the output buffer.

Creates a new state with default values.

Records a fragment range into the current cache context, shifting by buffer size.

Checks if the component should render.

Types

cache_entry()

@type cache_entry() :: %{map: map(), frozen_prefix_bytes: non_neg_integer()}

fragment_meta()

@type fragment_meta() :: {non_neg_integer(), non_neg_integer() | nil, list()}

t()

@type t() :: %Phlex.SGML.State{
  buffer: IO.chardata(),
  cache_stack: [cache_entry()],
  capturing: boolean(),
  content_block: function() | nil,
  fragment_depth: non_neg_integer(),
  fragment_map: map(),
  fragments: MapSet.t() | nil,
  output_buffer: IO.chardata(),
  rendering: boolean(),
  should_render: boolean(),
  user_context: map()
}

Functions

append_buffer(state, content)

Appends content to the buffer.

begin_fragment(state)

Increments fragment depth unconditionally.

begin_fragment(state, id)

Begins a named fragment: updates selective-render depth and cache offsets.

caching(state, fun)

Renders a block into an isolated buffer for cache storage.

Returns {binary, fragment_map} where fragment_map maps fragment names to {byte_offset, byte_length, nested_fragment_names}.

caching?(state)

capture(state, fun)

Captures the output of a block.

Returns the captured buffer content as a binary.

end_fragment(state)

Decrements fragment depth unconditionally.

end_fragment(state, id)

Ends a named fragment: finalizes cache length and clears selective-render membership.

flush(state)

Flushes the buffer to the output buffer.

new(opts \\ [])

Creates a new state with default values.

record_fragment(state, name, arg)

record_fragment(state, name, offset, length, nested_fragments)

Records a fragment range into the current cache context, shifting by buffer size.

should_render?(arg1)

Checks if the component should render.