ExBoxPacker.Preview (ExBoxPacker v0.2.0)

Copy Markdown View Source

Opt-in capture hook for the ExBoxPacker.PackerPreview dev visualiser.

Enable in dev config and add the collector to your supervision tree:

# config/dev.exs
config :ex_box_packer, ExBoxPacker, preview: [enabled: true]

# application.ex (dev only)
children = [ExBoxPacker.Preview.Collector | rest]

Then, after packing, capture the result:

{:ok, result} = ExBoxPacker.Packer.pack(boxes, items)
ExBoxPacker.Preview.capture(result, label: "order #123")

When disabled (default) or the collector isn't running, capture/2 is a cheap no-op.

Summary

Functions

Capture a packing for the preview (no-op unless enabled and the collector is running).

Whether preview capture is enabled (config :ex_box_packer, ExBoxPacker, preview: [enabled: true]; default false).

Convenience: Packer.pack/3 then capture/2. Returns the pack/3 result.

Functions

capture(result, opts \\ [])

@spec capture(
  ExBoxPacker.Result.PackedBoxList.t(),
  keyword()
) :: :ok

Capture a packing for the preview (no-op unless enabled and the collector is running).

enabled?()

@spec enabled?() :: boolean()

Whether preview capture is enabled (config :ex_box_packer, ExBoxPacker, preview: [enabled: true]; default false).

pack(boxes, items, opts \\ [])

Convenience: Packer.pack/3 then capture/2. Returns the pack/3 result.