Pote.Theme.Runtime (Pote v3.0.0)

Copy Markdown View Source

Runtime theme operations for host modules using Pote.Theme.

All functions in this module receive the host module as their first argument and call host_module.config_app/0, host_module.storage_dir/0, and host_module.defaults/0 at runtime. This allows the host module to override storage_dir/0 freely without any macro recompilation.

Summary

Functions

Activates a theme by name. Writes through to :theme_active.

Returns the active theme as a Pote.Theme.Theme struct.

Looks up a single colour key in the active theme.

Returns the colour map for the active theme.

Installs a theme to disk. Accepts a Pote.Theme.Theme struct.

Installs a built-in template theme by name.

Lists all themes available in storage_dir.

Registers the resolver with Pote so Pote.parse("theme:<key>") and atom lookups consult this theme system. Idempotent.

Returns the list of built-in template theme names.

Functions

activate(host_module, name)

@spec activate(module(), String.t()) :: :ok

Activates a theme by name. Writes through to :theme_active.

active(host_module)

@spec active(module()) :: Pote.Theme.Theme.t()

Returns the active theme as a Pote.Theme.Theme struct.

Reads :theme_active from the application's config, loads the JSON file, and returns the parsed theme. Falls back to the built-in default theme when no theme is selected or the active file is unreadable.

color(host_module, key)

@spec color(module(), String.t()) :: {:ok, Pote.Theme.Theme.rgb()} | :not_found

Looks up a single colour key in the active theme.

Returns {:ok, {r, g, b}} on hit, :not_found on miss.

colors(host_module)

@spec colors(module()) :: %{optional(String.t()) => Pote.Theme.Theme.rgb()}

Returns the colour map for the active theme.

install!(host_module, theme)

@spec install!(module(), Pote.Theme.Theme.t()) :: :ok | {:error, term()}

Installs a theme to disk. Accepts a Pote.Theme.Theme struct.

install_template(host_module, name)

@spec install_template(module(), String.t()) :: :ok | {:error, term()}

Installs a built-in template theme by name.

Returns :ok if the template was installed, {:error, :not_found} if the template does not exist.

list(host_module)

@spec list(module()) :: [String.t()]

Lists all themes available in storage_dir.

register_with_pote(host_module)

@spec register_with_pote(module()) :: :ok

Registers the resolver with Pote so Pote.parse("theme:<key>") and atom lookups consult this theme system. Idempotent.

templates()

@spec templates() :: [String.t()]

Returns the list of built-in template theme names.