Class: Fontico::Manifest

Inherits:
Object
  • Object
show all
Defined in:
lib/fontico/manifest.rb

Overview

Parses icons.yml. Nested groups flatten to dotted names, so nav: { menu: lucide/menu } is addressable as icon("nav.menu").

Defined Under Namespace

Classes: Error

Constant Summary collapse

LOCAL_PATH =

Where local/ SVGs live when the manifest doesn't say otherwise.

"app/assets/icons"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, path: nil) ⇒ Manifest

Returns a new instance of Manifest.



18
19
20
21
22
23
24
25
# File 'lib/fontico/manifest.rb', line 18

def initialize(data, path: nil)
  @path      = path
  @defaults  = data["defaults"]  || {}
  @providers = data["providers"] || {}
  @targets   = data["targets"]   || ["sprite"]
  @icons     = flatten(data["icons"] || {}).freeze
  validate!
end

Instance Attribute Details

#defaultsObject (readonly)

Returns the value of attribute defaults.



14
15
16
# File 'lib/fontico/manifest.rb', line 14

def defaults
  @defaults
end

#iconsObject (readonly)

Returns the value of attribute icons.



14
15
16
# File 'lib/fontico/manifest.rb', line 14

def icons
  @icons
end

#pathObject (readonly)

Returns the value of attribute path.



14
15
16
# File 'lib/fontico/manifest.rb', line 14

def path
  @path
end

#providersObject (readonly)

Returns the value of attribute providers.



14
15
16
# File 'lib/fontico/manifest.rb', line 14

def providers
  @providers
end

#targetsObject (readonly)

Returns the value of attribute targets.



14
15
16
# File 'lib/fontico/manifest.rb', line 14

def targets
  @targets
end

Class Method Details

.load(path) ⇒ Object



16
# File 'lib/fontico/manifest.rb', line 16

def self.load(path) = new(YAML.safe_load_file(path), path: path)

Instance Method Details

#[](name) ⇒ Object



31
# File 'lib/fontico/manifest.rb', line 31

def [](name) = icons.find { _1.name == name }

#default_providerObject



27
# File 'lib/fontico/manifest.rb', line 27

def default_provider = defaults.fetch("provider", "lucide")

#local_iconsObject



39
# File 'lib/fontico/manifest.rb', line 39

def local_icons = icons.select(&:local?)

#local_pathObject



28
# File 'lib/fontico/manifest.rb', line 28

def local_path       = providers.dig("local", "path") || LOCAL_PATH

#remote_by_providerObject

Vendor icons grouped by provider so the resolver can batch one HTTP request per provider instead of one per icon.



35
36
37
# File 'lib/fontico/manifest.rb', line 35

def remote_by_provider
  icons.reject(&:local?).group_by(&:provider).transform_values { _1.map(&:slug).uniq.sort }
end

#sizeObject



29
# File 'lib/fontico/manifest.rb', line 29

def size             = defaults.fetch("size", 24).to_i