Class: PhlexIcons::Icon

Inherits:
Phlex::SVG
  • Object
show all
Defined in:
lib/phlex-icons/icon.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, **options) ⇒ Phlex::SVG

Factory method to create an icon component instance. Parses the name string, finds the corresponding class, and initializes it with options.

Parameters:

  • name (String)

    Icon identifier (e.g., “hero/house:solid”, “lucide/arrow-right”).

  • options (Hash)

    HTML attributes and options for the icon component.

Raises:

  • (ArgumentError)

    If the name format is invalid or default pack is missing.

  • (NameError)

    If the corresponding icon class cannot be found.



16
17
18
19
20
# File 'lib/phlex-icons/icon.rb', line 16

def initialize(name, **options)
  @name = name
  @options = options&.transform_keys(&:to_sym) || {}
  super()
end

Instance Method Details

#view_templateObject



22
23
24
25
26
27
28
29
# File 'lib/phlex-icons/icon.rb', line 22

def view_template
  parser = PhlexIcons::NameParser.new(@name)

  # Prioritize variant from the name string over options hash
  @options[:variant] = parser.variant_name if parser.variant_name

  render parser.klass.new(**@options)
end