Class: HeroicIcons::Icons

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

Instance Method Summary collapse

Instance Method Details

#icon(name, **options) ⇒ Object

Updated method signature to accept name and a hash for additional options



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/heroic_icons/heroic_icons.rb', line 9

def icon(name, **options)
  # append or replace?  hmmm.
  options[:class] = if options[:override_class].present?
    options.delete(:override_class)
  elsif options[:class].present?
    "#{HeroicIcons.configuration.default_classes} #{options[:class]}"
  else
    HeroicIcons.configuration.default_classes
  end
  file_path = determine_file_path(name, options)

  begin
    file_data = File.read(file_path)
  rescue
    raise HeroicIcons::IconNotFound, "Icon not found: #{name}"
  end

  # Modify SVG with additional attributes if any
  file_data = modify_svg(file_data, name, options) unless options.empty?

  file_data.html_safe
end