PhoenixKitCatalogue.Export.Destination behaviour (PhoenixKitCatalogue v0.9.0)

Copy Markdown View Source

Behaviour for export destinations (e.g. PRO100, Universal).

Each destination module defines a key, a human-readable label, the list of format options it supports, and a render/2 function that produces the file content for a given format key and export context.

Adding a new destination

  1. Create a module that @behaviour PhoenixKitCatalogue.Export.Destination.
  2. Implement all four callbacks.
  3. Register it in PhoenixKitCatalogue.Export.destinations/0.

Summary

Callbacks

Supported formats as [{key, label}] pairs. key is an atom used when calling render/2; label is the display string.

Machine key for the destination (e.g. :pro100).

Human-readable label shown in the UI select.

Renders the export content.

Callbacks

formats()

@callback formats() :: [{atom(), String.t()}]

Supported formats as [{key, label}] pairs. key is an atom used when calling render/2; label is the display string.

key()

@callback key() :: atom()

Machine key for the destination (e.g. :pro100).

label()

@callback label() :: String.t()

Human-readable label shown in the UI select.

render(format_key, ctx)

@callback render(format_key :: atom(), ctx :: map()) ::
  {filename :: String.t(), iodata :: iodata(), mime :: String.t()}

Renders the export content.

format_key must be one of the atoms from formats/0. ctx is a map with keys: :items, :index, :catalogues.

Returns {filename, iodata, mime_type}.