Module: Protege::Components::IconsHelper

Defined in:
app/helpers/protege/components/icons_helper.rb

Overview

Inline SVG icons — a small registry of single-path, stroked glyphs (Lucide geometry). Each renders as currentColor so it inherits the surrounding text color and theme. Add an entry to ICONS to introduce a new glyph; render one with icon(:name).

Constant Summary collapse

ICONS =

Icon key => the d attribute of its single <path>.

{
  paperclip: 'M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66' \
             'l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48'
}.freeze

Instance Method Summary collapse

Instance Method Details

#icon(name, size: 16, **attrs) ⇒ ActiveSupport::SafeBuffer

Render a named icon as an inline SVG that inherits the current text color.

Parameters:

  • name (Symbol)

    the icon key (see ICONS)

  • size (Integer) (defaults to: 16)

    the pixel width and height

  • attrs (Hash)

    extra attributes merged onto the <svg> (e.g. class:)

Returns:

  • (ActiveSupport::SafeBuffer)

    the SVG markup

Raises:

  • (ArgumentError)

    when name is not a registered icon



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/protege/components/icons_helper.rb', line 22

def icon(name, size: 16, **attrs)
  path = ICONS.fetch(name) { raise ArgumentError, "unknown icon #{name.inspect}" }

  tag.svg(
    tag.path(d: path),
    xmlns:             'http://www.w3.org/2000/svg',
    width:             size,
    height:            size,
    viewBox:           '0 0 24 24',
    fill:              'none',
    stroke:            'currentColor',
    'stroke-width':    2,
    'stroke-linecap':  'round',
    'stroke-linejoin': 'round',
    **attrs
  )
end