ElementorexCms.Sources (ElementorexCms v0.2.0)

Copy Markdown View Source

The sources of dynamic content a document can use (see ElementorexCms.Source), like ElementorexCms.Registry is for blocks.

default/0 reads the config:

config :elementorex_cms,
  sources: [
    # an Ecto schema: every field, read from the schema
    MyApp.Catalog.Product,
    # a module (use ElementorexCms.Source.Ecto or the behaviour)
    MyAppWeb.Sources.Posts,
    # the Ecto adapter with options
    {ElementorexCms.Source.Ecto, schema: MyApp.Events.Event, path: "/events/:id"}
  ]

Pass the same sources to the editor and to ElementorexCms.Components.document/1 (sources={...}) to use others than the configured ones.

Summary

Functions

The configured sources (config :elementorex_cms, sources: [...]).

Whether there are no sources.

The source with key, or nil.

The source a record comes from: the one whose Ecto schema is the record's struct (see ElementorexCms.Source.Ecto), or nil.

The sources in the order they were given.

Builds the sources from a list of source modules, Ecto schemas or {adapter, opts} tuples (see ElementorexCms.Source.new/1). nil gives default/0; a later source with the same key replaces an earlier one.

Types

t()

@type t() :: %ElementorexCms.Sources{
  order: [String.t()],
  sources: %{required(String.t()) => ElementorexCms.Source.t()}
}

Functions

default()

@spec default() :: t()

The configured sources (config :elementorex_cms, sources: [...]).

empty?(sources)

@spec empty?(t() | nil) :: boolean()

Whether there are no sources.

fetch(sources, key)

@spec fetch(t() | nil, term()) :: ElementorexCms.Source.t() | nil

The source with key, or nil.

for_record(sources, arg2)

@spec for_record(t() | nil, term()) :: ElementorexCms.Source.t() | nil

The source a record comes from: the one whose Ecto schema is the record's struct (see ElementorexCms.Source.Ecto), or nil.

list(sources)

@spec list(t() | nil) :: [ElementorexCms.Source.t()]

The sources in the order they were given.

new(sources)

@spec new(t() | [term()] | nil) :: t()

Builds the sources from a list of source modules, Ecto schemas or {adapter, opts} tuples (see ElementorexCms.Source.new/1). nil gives default/0; a later source with the same key replaces an earlier one.