Module: LucideRails::IconProvider

Defined in:
lib/lucide-rails/icon_provider.rb

Class Method Summary collapse

Class Method Details

.icon(named) ⇒ Object



7
8
9
# File 'lib/lucide-rails/icon_provider.rb', line 7

def icon(named)
  send("provide_from_#{LucideRails.provider}", named)
end

.memoryObject



25
26
27
28
29
30
31
# File 'lib/lucide-rails/icon_provider.rb', line 25

def memory
  return @memory if @memory

  file_path = LucideRails::GEM_ROOT.join("icons/stripped.bin.gz")
  data = ActiveSupport::Gzip.decompress(File.read(file_path))
  @memory = data.split("\x00").to_h { |x| x.split(",", 2) }
end

.provide_from_filesystem(named) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
14
15
16
# File 'lib/lucide-rails/icon_provider.rb', line 11

def provide_from_filesystem(named)
  file = LucideRails::GEM_ROOT.join("icons", "stripped", "#{named}.svg")
  raise ArgumentError, "Unknown icon #{named}" unless file.exist?

  File.read(file)
end

.provide_from_memory(named) ⇒ Object

Raises:

  • (ArgumentError)


18
19
20
21
22
23
# File 'lib/lucide-rails/icon_provider.rb', line 18

def provide_from_memory(named)
  named = named.to_s
  raise ArgumentError, "Unknown icon #{named}" unless memory.key? named

  memory[named]
end