mix ledger_ui.icons (LedgerUI v0.2.0)

Copy Markdown View Source

Vendors the Hugeicons Stroke Rounded icons the app uses into a folder (priv/hugeicons by default) that <.icon> reads. No extra dependency: it downloads from the free set in GitHub (hugeicons/hugeicons, MIT) with :httpc and verified TLS.

mix ledger_ui.icons get search-01 tick-02    # also accepts huge-search-01
mix ledger_ui.icons sync                     # every icon name the sources use
mix ledger_ui.icons sync --prune             # ...and removes vendored icons nobody uses
mix ledger_ui.icons search invoice           # lists upstream names containing the term
mix ledger_ui.icons update                   # re-downloads everything at the newest ref
mix ledger_ui.icons update --ref v1.2.0      # ...or at a given commit, tag or branch

Point the app at the folder, once:

config :ledger_ui, :icons_path, "priv/hugeicons"
# in a release: {:my_app, "priv/hugeicons"}

sync scans lib, assets/js and priv/templates for <.icon name="..."> and huge-* names. Names the built-in dictionary already has (download, chevron-down, ... see LedgerUI.Components.Icon.names/0) need no file and are skipped; a name that does not exist upstream is reported, not fatal.

Each SVG is converted to the kit's stroke format (see LedgerUI.Icons.Hugeicons: stroke colour, width and caps come from the .lu-i CSS rule) before it is written, so files are small and follow currentColor.

Options

  • --dir - the folder (default: :icons_path of the config, else priv/hugeicons)
  • --ref - the commit, tag or branch of hugeicons/hugeicons to download from. Defaults to the ref of the folder's .hugeicons.json, else to a commit pinned in this task. For update it defaults to main, the newest upstream
  • --prune - only for sync: removes the SVGs no source references

The folder also gets .hugeicons.json (the ref and the names) and Hugeicons' LICENSE.md (MIT). Every file is written to a temporary name and renamed, so a failed download leaves no partial file; a network failure ends the task with a non-zero exit.

Summary

Functions

"huge-Search-01", "search-01.svg" and "search-01" all become "search-01".

The names to remove: vendored, but not in wanted.

The folders sync scans.

Up to 5 upstream names close to name: containing it, or with a high string similarity.

Functions

normalize!(raw)

@spec normalize!(String.t()) :: String.t()

"huge-Search-01", "search-01.svg" and "search-01" all become "search-01".

prunable(vendored, wanted)

@spec prunable([String.t()], [String.t()]) :: [String.t()]

The names to remove: vendored, but not in wanted.

roots()

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

The folders sync scans.

suggestions(name, upstream)

@spec suggestions(String.t(), [String.t()]) :: [String.t()]

Up to 5 upstream names close to name: containing it, or with a high string similarity.