Class: Glyphs::IconReference
- Inherits:
-
Object
- Object
- Glyphs::IconReference
- Defined in:
- lib/glyphs/icon_reference.rb
Overview
A single (library, variant, name) icon reference discovered in source, with the shared library/variant resolution tables the scanner and the RuboCop cops both rely on.
library is an icons-gem library symbol (:lucide), variant is a string
or nil (variant-less libraries), and name is dasherized ("circle-check").
The library/variant tables are sourced from the icons gem wherever
possible (default_variant_for) so they never drift from what actually
resolves at render time.
Constant Summary collapse
- LIBRARY_TO_COMPONENT =
Subclassed (not the block form) so the constants below are namespaced under IconReference — constants defined inside a
Data.define do…endblock leak to the enclosing scope instead of nesting under the class.Maps every Glyphs library component to its icons-gem library symbol. This is the canonical map;
RuboCop::Cop::Glyphs::LibraryCallHelpersreads it so the cops and the pruner agree on the full set of libraries. { lucide: "LucideIcon", phosphor: "PhosphorIcon", heroicons: "HeroIcon", tabler: "TablerIcon", feather: "FeatherIcon", boxicons: "BoxIcon", flags: "FlagIcon", hugeicons: "HugeIcon", linear: "LinearIcon", radix: "RadixIcon", sidekickicons: "SidekickIcon", weather: "WeatherIcon", animated: "AnimatedIcon" }.freeze
- LEGACY_HELPERS =
Legacy icon helpers (
_lucide(:house)) the scanner also recognizes. { "_lucide" => :lucide, "_phosphor" => :phosphor, "_hero" => :heroicons, "_heroicon" => :heroicons, "_tabler" => :tabler }.freeze
- ICONIFY_PATTERN =
Raw
iconify lucide--houseclass strings. /\biconify\s+(lucide|phosphor|heroicons)--([a-z0-9-]+)/
Class Method Summary collapse
-
.component_to_library ⇒ Object
Component name (
"LucideIcon") => library symbol (:lucide). -
.default_variant_for(library) ⇒ Object
The library's default variant, as configured in the icons gem.
- .legacy_helpers ⇒ Object
-
.library_for(method_name) ⇒ Object
Resolves a called method name (component or legacy helper) to a library symbol, or nil when the method isn't an icon call.
-
.normalize_variant(variant) ⇒ Object
Mirrors the icons gem's variant→path handling so a scanned reference points at the same file that renders: an empty string (a documented rails_icons override) and
"."(the variant-less convention) both mean "no variant subdirectory" and normalize to nil.
Class Method Details
.component_to_library ⇒ Object
Component name ("LucideIcon") => library symbol (:lucide).
52 53 54 |
# File 'lib/glyphs/icon_reference.rb', line 52 def component_to_library @component_to_library ||= LIBRARY_TO_COMPONENT.to_h { |library, component| [component, library] }.freeze end |
.default_variant_for(library) ⇒ Object
The library's default variant, as configured in the icons gem. Returns a
string ("outline"), or nil for variant-less libraries.
69 70 71 72 73 74 |
# File 'lib/glyphs/icon_reference.rb', line 69 def default_variant_for(library) = Icons.config.libraries[library.to_sym] normalize_variant(&.default_variant) rescue StandardError nil end |
.legacy_helpers ⇒ Object
56 57 58 |
# File 'lib/glyphs/icon_reference.rb', line 56 def legacy_helpers LEGACY_HELPERS end |
.library_for(method_name) ⇒ Object
Resolves a called method name (component or legacy helper) to a library symbol, or nil when the method isn't an icon call.
62 63 64 65 |
# File 'lib/glyphs/icon_reference.rb', line 62 def library_for(method_name) name = method_name.to_s component_to_library[name] || LEGACY_HELPERS[name] end |
.normalize_variant(variant) ⇒ Object
Mirrors the icons gem's variant→path handling so a scanned reference
points at the same file that renders: an empty string (a documented
rails_icons override) and "." (the variant-less convention) both mean
"no variant subdirectory" and normalize to nil. See the icons gem's
Icons::Icon::Configurable#set_variant and Icons::Icon::FilePath#parts.
81 82 83 84 85 86 87 88 |
# File 'lib/glyphs/icon_reference.rb', line 81 def normalize_variant(variant) return if variant.nil? string = variant.to_s return if string.empty? || string == "." string end |