Puck.Content.Wrappable protocol (Puck v0.2.11)

Copy Markdown View Source

Protocol for converting content to Puck.Content.Part structs.

Built-in implementations:

  • Strings become text parts
  • Maps/structs are JSON-encoded
  • Parts pass through unchanged

Summary

Types

t()

All the types that implement this protocol.

Functions

Converts content to a list of Content.Part structs.

Types

t()

@type t() :: term()

All the types that implement this protocol.

Functions

wrap(content)

Converts content to a list of Content.Part structs.

Examples

iex> Puck.Content.Wrappable.wrap("Hello")
[%Puck.Content.Part{type: :text, text: "Hello"}]

iex> Puck.Content.Wrappable.wrap(%{result: 42})
[%Puck.Content.Part{type: :text, text: ~s({"result":42})}]