Class: Glyphs::Icon

Inherits:
Phlex::HTML
  • Object
show all
Defined in:
lib/glyphs/icon.rb

Overview

Base icon component. Prefer the library-specific subclasses (LucideIcon, HeroIcon, ...); the generic form requires an explicit library:

Icon(:house, library: :lucide)

Constant Summary collapse

LIBRARY =
nil

Instance Method Summary collapse

Constructor Details

#initialize(name, variant: nil, library: self.class::LIBRARY, **attributes) ⇒ Icon

Returns a new instance of Icon.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/glyphs/icon.rb', line 11

def initialize(name, variant: nil, library: self.class::LIBRARY, **attributes)
  if library.nil?
    raise ArgumentError,
      "library is required — use a library component (LucideIcon, HeroIcon, ...) or pass library:"
  end

  @name = name.to_s.tr("_", "-")
  @library = library.to_sym
  @variant = variant&.to_sym
  @attributes = attributes

  super()
end

Instance Method Details

#view_templateObject



25
26
27
# File 'lib/glyphs/icon.rb', line 25

def view_template
  raw safe(svg_markup)
end