LedgerUI.Icons (LedgerUI v0.2.0)

Copy Markdown View Source

The icons an app vendored with mix ledger_ui.icons, loaded for <.icon>.

# config/config.exs
config :ledger_ui, :icons_path, "priv/hugeicons"
# or, to resolve it inside a release:
config :ledger_ui, :icons_path, {:my_app, "priv/hugeicons"}

The folder is read once, on first use, and kept in :persistent_term as a map of name => iodata parts, so a lookup costs one Application.get_env/3, one :persistent_term read and one map access, with no file access. When a name is missing the folder's signature (modification time and file count) is compared with the loaded one and the folder is read again if it changed, so icons added by mix ledger_ui.icons get/sync show up in a running dev server without a restart (a missing name in a stable folder costs one File.stat/1, and <.icon> logs it anyway).

Each file is converted again on load (LedgerUI.Icons.Hugeicons.convert/1), so only shapes survive. Without :icons_path nothing is loaded and every lookup misses.

Summary

Functions

The render parts of a vendored icon (see LedgerUI.Components.Icon), or nil.

The names of the vendored icons currently loaded.

The configured folder as an absolute path, or nil.

Forgets the loaded icons; the next lookup reads the folder again.

Functions

fetch(name)

@spec fetch(String.t()) :: tuple() | nil

The render parts of a vendored icon (see LedgerUI.Components.Icon), or nil.

names()

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

The names of the vendored icons currently loaded.

path()

@spec path() :: Path.t() | nil

The configured folder as an absolute path, or nil.

reload()

@spec reload() :: :ok

Forgets the loaded icons; the next lookup reads the folder again.