PhoenixVapor.Template (PhoenixVapor v0.6.1)

Copy Markdown View Source

A Vue template compiled for rendering on the server: static HTML and the dynamic slots between it, the shape of %Phoenix.LiveView.Rendered{}.

A template comes from Vize.split_template/2, compiled by PhoenixVapor's compiler. Its expressions are parsed, and every slot's :position is {line, column} in :file. Blocks inside it, such as a v-if branch, are templates too.

Summary

Functions

The blocks directly inside a slot. See map_blocks/3.

Every expression in a template, in document order. See map_exprs/3.

Identifies statics and slots, as the fingerprint of a %Phoenix.LiveView.Rendered{} does, so LiveView sends statics only when they change.

Maps the blocks directly inside a slot, threading an accumulator: a v-if's branches, a v-for's body, a component's slot content, a <slot>'s fallback, and a fragment's template. Other slots have none.

Maps every expression in a template, threading an accumulator: fun gets the expression, the slot it belongs to, and the accumulator. A component's own template, under :component, belongs to that component and is skipped.

A template from its statics and compiled slots, with their fingerprint.

Stores on every slot, in this template and the blocks inside it, the root assign keys its expressions read, its own and its blocks', as :keys. Rendering skips a slot none of whose keys changed. Call it again after replacing a template's expressions.

The expressions in one slot, including the blocks inside it.

Types

position()

@type position() :: {pos_integer(), pos_integer()}

t()

@type t() :: %PhoenixVapor.Template{
  file: Path.t() | nil,
  fingerprint: non_neg_integer() | nil,
  slots: [map()],
  statics: [String.t()]
}

Functions

blocks(slot)

@spec blocks(map()) :: [t() | map()]

The blocks directly inside a slot. See map_blocks/3.

exprs(template)

@spec exprs(t()) :: [{term(), map()}]

Every expression in a template, in document order. See map_exprs/3.

fingerprint(statics, slots)

@spec fingerprint([String.t()], [map()]) :: non_neg_integer()

Identifies statics and slots, as the fingerprint of a %Phoenix.LiveView.Rendered{} does, so LiveView sends statics only when they change.

map_blocks(slot, acc, fun)

@spec map_blocks(map(), acc, (block, acc -> {block, acc})) :: {map(), acc}
when acc: term(), block: t() | map()

Maps the blocks directly inside a slot, threading an accumulator: a v-if's branches, a v-for's body, a component's slot content, a <slot>'s fallback, and a fragment's template. Other slots have none.

map_exprs(template, acc, fun)

@spec map_exprs(block, acc, (term(), map(), acc -> {term(), acc})) :: {block, acc}
when block: t() | %{slots: [map()]}, acc: term()

Maps every expression in a template, threading an accumulator: fun gets the expression, the slot it belongs to, and the accumulator. A component's own template, under :component, belongs to that component and is skipped.

new(statics, slots, file)

@spec new([String.t()], [map()], Path.t() | nil) :: t()

A template from its statics and compiled slots, with their fingerprint.

put_keys(template)

@spec put_keys(block) :: block when block: t() | map()

Stores on every slot, in this template and the blocks inside it, the root assign keys its expressions read, its own and its blocks', as :keys. Rendering skips a slot none of whose keys changed. Call it again after replacing a template's expressions.

slot_exprs(slot)

@spec slot_exprs(map()) :: [term()]

The expressions in one slot, including the blocks inside it.