Module: Glyphs

Extended by:
Phlex::Kit
Defined in:
lib/glyphs.rb,
lib/glyphs/icon.rb,
lib/glyphs/rubocop.rb,
lib/glyphs/version.rb,
lib/glyphs/box_icon.rb,
lib/glyphs/flag_icon.rb,
lib/glyphs/hero_icon.rb,
lib/glyphs/huge_icon.rb,
lib/glyphs/radix_icon.rb,
lib/glyphs/linear_icon.rb,
lib/glyphs/lucide_icon.rb,
lib/glyphs/tabler_icon.rb,
lib/glyphs/feather_icon.rb,
lib/glyphs/weather_icon.rb,
lib/glyphs/animated_icon.rb,
lib/glyphs/configuration.rb,
lib/glyphs/phosphor_icon.rb,
lib/glyphs/sidekick_icon.rb

Overview

Phlex icon components for every rails_icons library, exposed as a Phlex::Kit:

include Glyphs
LucideIcon(:house, class: "size-4")

Defined Under Namespace

Modules: RuboCop Classes: AnimatedIcon, BoxIcon, Configuration, FeatherIcon, FlagIcon, HeroIcon, HugeIcon, Icon, LinearIcon, LucideIcon, PhosphorIcon, RadixIcon, SidekickIcon, TablerIcon, WeatherIcon

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.configurationObject



37
38
39
# File 'lib/glyphs.rb', line 37

def configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



32
33
34
35
# File 'lib/glyphs.rb', line 32

def configure
  yield(configuration) if block_given?
  configuration
end

.register_library(library, component:) ⇒ Object

Defines a Glyphs::Icon subclass for a custom icon library and exposes it as a kit method. The library's SVG location itself is configured through the icons/rails_icons custom-library configuration.

Glyphs.register_library(:brand, component: :BrandIcon)
# => BrandIcon(:logo, class: "size-4")


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/glyphs.rb', line 51

def register_library(library, component:)
  library = library.to_sym
  name = component.to_sym

  if const_defined?(name, false)
    existing = const_get(name, false)
    return existing if existing < Icon && library == existing::LIBRARY

    raise ArgumentError, "Glyphs::#{name} is already defined and does not render the #{library} library"
  end

  klass = Class.new(Icon)
  klass.const_set(:LIBRARY, library)
  const_set(name, klass)
end

.reset_cache!Object



78
79
80
# File 'lib/glyphs.rb', line 78

def reset_cache!
  @svg_cache_mutex.synchronize { @svg_cache = {} }
end

.reset_configuration!Object



41
42
43
# File 'lib/glyphs.rb', line 41

def reset_configuration!
  @configuration = Configuration.new
end

.svg_for(name:, library:, variant:, attributes:) ⇒ Object

Returns the SVG markup for an icon, applying the configured missing-icon policy (raise / instrument / fallback) and an optional per-process cache.



69
70
71
72
73
74
75
76
# File 'lib/glyphs.rb', line 69

def svg_for(name:, library:, variant:, attributes:)
  return render_svg(name:, library:, variant:, attributes:) unless configuration.cache_svgs

  key = [library, variant, name, attributes]
  @svg_cache_mutex.synchronize do
    @svg_cache[key] ||= render_svg(name:, library:, variant:, attributes:)
  end
end