Dynamic UI adapter for database-driven components.
Loads components from a database (or any user-supplied source) and renders
them at runtime. When the configured component is not available, falls
back to another MishkaGervaz.Behaviours.UIAdapter implementation
(Tailwind by default).
Configuration
Set this adapter on the DSL with the renderer and resolver:
presentation do
ui_adapter :dynamic
ui_adapter_opts [
site: "Global",
component_renderer: &MishkaCmsCore.Runtime.LiveViewHelpers.component/1,
module_resolver: &MishkaCmsCore.Runtime.Compilers.Helpers.module_name/3,
fallback: MishkaGervaz.UIAdapters.Tailwind
]
endOptions
:site— site identifier passed to the renderer (default"Global"):component_renderer—(assigns) -> Phoenix.LiveView.Rendered.t()called with:component_nameand:siteinjected into the assigns:module_resolver—(component_name, site, kind) -> module()used to test whether the dynamic component is actually loaded:fallback— adapter to delegate to when the dynamic component is unavailable or the renderer is not configured (defaultMishkaGervaz.UIAdapters.Tailwind)
Every callback declared on MishkaGervaz.Behaviours.UIAdapter is wired
identically: try the dynamic renderer, fall back if unavailable. The list
is taken from MishkaGervaz.Behaviours.UIAdapter.component_functions/0,
so adding a new behaviour callback automatically lights up here.
Summary
Functions
Use this module to create a Dynamic adapter with pre-configured options.
Adds the Dynamic adapter configuration to an assigns map.
Functions
Use this module to create a Dynamic adapter with pre-configured options.
Options
Same as the module-level options — :site, :fallback,
:component_renderer, :module_resolver.
Example
defmodule MyApp.GervazUIAdapter do
use MishkaGervaz.UIAdapters.Dynamic,
site: "Global",
component_renderer: &MyApp.LiveViewHelpers.component/1,
module_resolver: &MyApp.Compilers.Helpers.module_name/3,
fallback: MishkaGervaz.UIAdapters.Tailwind
end
Adds the Dynamic adapter configuration to an assigns map.
Options
:site(default"Global"):fallback(defaultMishkaGervaz.UIAdapters.Tailwind):component_renderer(optional):module_resolver(optional)
Example
assigns = MishkaGervaz.UIAdapters.Dynamic.with_config(assigns,
site: "MyApp",
component_renderer: &MyApp.Runtime.component/1,
module_resolver: &MyApp.Runtime.module_name/3,
fallback: MyApp.UIAdapters.Custom
)