Module: Glyphs

Extended by:
Phlex::Kit
Defined in:
lib/glyphs.rb,
lib/glyphs/icon.rb,
lib/glyphs/railtie.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/icon_pruner.rb,
lib/glyphs/linear_icon.rb,
lib/glyphs/lucide_icon.rb,
lib/glyphs/tabler_icon.rb,
lib/glyphs/feather_icon.rb,
lib/glyphs/prune_report.rb,
lib/glyphs/prune_runner.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,
lib/glyphs/icon_reference.rb,
lib/glyphs/source_scanner.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, IconPruner, IconReference, LinearIcon, LucideIcon, PhosphorIcon, PruneReport, PruneRunner, RadixIcon, Railtie, SidekickIcon, SourceScanner, TablerIcon, WeatherIcon

Constant Summary collapse

VERSION =
"0.2.2"

Class Method Summary collapse

Class Method Details

.configurationObject



44
45
46
# File 'lib/glyphs.rb', line 44

def configuration
  @configuration ||= Configuration.new
end

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

Yields:



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

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")


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/glyphs.rb', line 58

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



85
86
87
# File 'lib/glyphs.rb', line 85

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

.reset_configuration!Object



48
49
50
# File 'lib/glyphs.rb', line 48

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.



76
77
78
79
80
81
82
83
# File 'lib/glyphs.rb', line 76

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