Class: Unmagic::Icon::Library

Inherits:
Object
  • Object
show all
Defined in:
lib/unmagic/icon/library.rb,
lib/unmagic/icon/library/source.rb,
lib/unmagic/icon/library/registry.rb,
lib/unmagic/icon/library/source/silk.rb,
lib/unmagic/icon/library/source/lucide.rb,
lib/unmagic/icon/library/source/tabler.rb,
lib/unmagic/icon/library/source/feather.rb,
lib/unmagic/icon/library/source/devicons.rb,
lib/unmagic/icon/library/source/heroicons.rb,
lib/unmagic/icon/library/source/simple_icons.rb,
lib/unmagic/icon/library/source/material_file_icons.rb

Defined Under Namespace

Classes: Registry, Source

Constant Summary collapse

MANIFEST_FILENAME =

The optional per-set manifest. Asset-kind-agnostic: it carries metadata, a ‘default`, a global `aliases` map, and optional per-entry declarations (`entries`, each with its own `aliases`). Icons auto-discover from disk, so for an icon library only `default` + `aliases` are typically present.

"manifest.json"
ASSET_GLOB =

The lone asset-kind-specific bit: which files in the directory are assets. SVG today; a future raster pack would scan png/gif here.

"*.svg"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, path:) ⇒ Library

Returns a new instance of Library.



20
21
22
23
# File 'lib/unmagic/icon/library.rb', line 20

def initialize(name:, path:)
  @name = name
  @path = path
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



18
19
20
# File 'lib/unmagic/icon/library.rb', line 18

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



18
19
20
# File 'lib/unmagic/icon/library.rb', line 18

def path
  @path
end

Instance Method Details

#aliasesObject



37
38
39
# File 'lib/unmagic/icon/library.rb', line 37

def aliases
  alias_index
end

#find(query) ⇒ Object

Resolve a query to an icon. Order: exact icon file, then the alias index (exact alias, then longest matching glob/pattern), then the manifest’s default. Raises when nothing matches and no default is declared.



28
29
30
31
# File 'lib/unmagic/icon/library.rb', line 28

def find(query)
  resolve(query.to_s) or
    raise Unmagic::Icon::IconNotFoundError.new("Can't find #{query} in #{path}")
end

#iconsObject



33
34
35
# File 'lib/unmagic/icon/library.rb', line 33

def icons
  icons_by_key.values
end