Class: Fontico::Manifest
- Inherits:
-
Object
- Object
- Fontico::Manifest
- 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
-
#defaults ⇒ Object
readonly
Returns the value of attribute defaults.
-
#icons ⇒ Object
readonly
Returns the value of attribute icons.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#providers ⇒ Object
readonly
Returns the value of attribute providers.
-
#targets ⇒ Object
readonly
Returns the value of attribute targets.
Class Method Summary collapse
Instance Method Summary collapse
- #[](name) ⇒ Object
- #default_provider ⇒ Object
-
#initialize(data, path: nil) ⇒ Manifest
constructor
A new instance of Manifest.
- #local_icons ⇒ Object
- #local_path ⇒ Object
-
#remote_by_provider ⇒ Object
Vendor icons grouped by provider so the resolver can batch one HTTP request per provider instead of one per icon.
- #size ⇒ Object
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
#defaults ⇒ Object (readonly)
Returns the value of attribute defaults.
14 15 16 |
# File 'lib/fontico/manifest.rb', line 14 def defaults @defaults end |
#icons ⇒ Object (readonly)
Returns the value of attribute icons.
14 15 16 |
# File 'lib/fontico/manifest.rb', line 14 def icons @icons end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
14 15 16 |
# File 'lib/fontico/manifest.rb', line 14 def path @path end |
#providers ⇒ Object (readonly)
Returns the value of attribute providers.
14 15 16 |
# File 'lib/fontico/manifest.rb', line 14 def providers @providers end |
#targets ⇒ Object (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_provider ⇒ Object
27 |
# File 'lib/fontico/manifest.rb', line 27 def default_provider = defaults.fetch("provider", "lucide") |
#local_icons ⇒ Object
39 |
# File 'lib/fontico/manifest.rb', line 39 def local_icons = icons.select(&:local?) |
#local_path ⇒ Object
28 |
# File 'lib/fontico/manifest.rb', line 28 def local_path = providers.dig("local", "path") || LOCAL_PATH |
#remote_by_provider ⇒ Object
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 |
#size ⇒ Object
29 |
# File 'lib/fontico/manifest.rb', line 29 def size = defaults.fetch("size", 24).to_i |