Module: ZestuiLucideRails::IconProvider

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

Class Method Summary collapse

Class Method Details

.icon(named) ⇒ Object



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

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

.memoryObject



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

def memory
  return @memory if @memory

  file_path = ZestuiLucideRails::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/zestui-lucide-rails/icon_provider.rb', line 11

def provide_from_filesystem(named)
  file = ZestuiLucideRails::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/zestui-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