defmodule CodeNameRaven.ChannelDisplay do @moduledoc """ Behaviour for notification channel display modules. Renders a channel's own dashboard panel (e.g. delivery history). Paired with a `CodeNameRaven.Channel` module the same way `CodeNameRaven.Display` pairs with `CodeNameRaven.Monitor` — self-bundled in one module, or as a separate package-sibling module declaring `compatible_channels/0`. """ @callback display_name() :: String.t() @callback compatible_channels() :: [module()] @callback prepare_assigns(map()) :: map() @callback render(map()) :: Phoenix.LiveView.Rendered.t() defmacro __using__(_opts) do quote do @behaviour CodeNameRaven.ChannelDisplay use Phoenix.Component @impl true def display_name do __MODULE__ |> Module.split() |> List.last() |> Macro.underscore() |> String.replace("_", " ") |> String.split() |> Enum.map_join(" ", &String.capitalize/1) end @impl true def prepare_assigns(assigns), do: assigns defoverridable display_name: 0, prepare_assigns: 1 end end @doc "Returns true if the module implements the ChannelDisplay behaviour." def channel_display_module?(module) do Code.ensure_loaded?(module) and function_exported?(module, :compatible_channels, 0) and function_exported?(module, :render, 1) end end