MishkaGervaz.UIAdapters.Dynamic (MishkaGervaz v0.0.1-alpha.2)

Copy Markdown View Source

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
  ]
end

Options

  • :site — site identifier passed to the renderer (default "Global")
  • :component_renderer(assigns) -> Phoenix.LiveView.Rendered.t() called with :component_name and :site injected 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 (default MishkaGervaz.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

__using__(opts)

(macro)

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

with_config(assigns, opts \\ [])

@spec with_config(
  map(),
  keyword()
) :: map()

Adds the Dynamic adapter configuration to an assigns map.

Options

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
)