OgEx.Card behaviour (og_ex v0.1.0)

Copy Markdown View Source

Defines a social card using HEEx, HTML, and CSS.

A card implements metadata/1 and render/1. Using this module also imports Phoenix.Component, so ~H and component attributes are available.

Summary

Callbacks

Returns Open Graph and Twitter/X metadata for the card assigns.

Returns the HEEx representation that OgEx sends to the configured renderer.

Returns the stable data used to version the generated image.

Functions

Configures a module as an OgEx card.

Types

metadata()

@type metadata() :: %{
  :title => String.t(),
  optional(:description) => String.t(),
  optional(:type) => String.t(),
  optional(:image_alt) => String.t(),
  optional(:twitter_card) => String.t()
}

Callbacks

metadata(assigns)

@callback metadata(assigns :: map()) :: metadata()

Returns Open Graph and Twitter/X metadata for the card assigns.

render(assigns)

@callback render(assigns :: map()) :: Phoenix.LiveView.Rendered.t()

Returns the HEEx representation that OgEx sends to the configured renderer.

version(assigns)

(optional)
@callback version(assigns :: map()) :: term()

Returns the stable data used to version the generated image.

This callback is optional. When omitted, OgEx versions the complete assigns map.

Functions

__using__(options)

(macro)

Configures a module as an OgEx card.

Supported options are :width, :height, and :format. Formats may be :png, :jpeg, :webp, or :svg. The macro imports Phoenix.Component, records the render dimensions, and installs the OgEx.Card behaviour.