Pax.Plugin behaviour (Pax v0.0.1-dev)
View SourcePax.Plugin is a behaviour for defining plugins that can be used with Pax.Interface or Pax.Admin. This is the base
behavior that all Plugins must implement. However, most plugins will use Pax.Interface.Plugin
or
use Pax.Admin.Plugin
instead of implementing this behaviour directly.
Summary
Types
The plugin specification, with or without init options
A Phoenix.LiveView socket
The plugin struct
Callbacks
A function that returns the key for the plugin's configuration. Must be unique.
A function that returns a valid Pax.Config spec for configuration keys and types accepted by the plugin.
The plugin initialization function, must return a map of initialized plugin state, which is passed to all other callback functions in the plugin.
A function that merges any additional configuration options into the plugin's opts.
Render a plugin component.
The type of plugin
Functions
Initialize the given plugin with the provided callback module and options.
Render plugins.
Types
The plugin specification, with or without init options
@type socket() :: Phoenix.LiveView.Socket.t()
A Phoenix.LiveView socket
The plugin struct
Callbacks
@callback config_key() :: atom()
A function that returns the key for the plugin's configuration. Must be unique.
@callback config_spec() :: map()
A function that returns a valid Pax.Config spec for configuration keys and types accepted by the plugin.
The plugin initialization function, must return a map of initialized plugin state, which is passed to all other callback functions in the plugin.
A function that merges any additional configuration options into the plugin's opts.
@callback render(opts :: map(), section :: atom(), assigns :: map()) :: Phoenix.LiveView.Rendered.t() | nil
Render a plugin component.
@callback type() :: :interface | :admin
The type of plugin
Functions
@spec init(callback_module :: module(), pluginspec()) :: t()
Initialize the given plugin with the provided callback module and options.
Render plugins.
You can define your own plugin sections in your interface, then create plugins that implement those areas.
<div>
{Pax.Plugin.render(:my_plugin_section, assigns)}
</div>
Then in your plugin, you can define a render function for that section.
defmodule MyPaxInterfacePlugin do
use Pax.Interface.Plugin
use Phoenix.Component
def render(_opts, :my_plugin_section, assigns) do
~H"""
<div>{@pax.plural_name}</div>
"""
end
end