Class: DocsUI::Icon

Inherits:
Phlex::HTML
  • Object
show all
Defined in:
app/components/docs_ui/icon.rb

Overview

Renders a synced lucide icon as inline SVG via rails_icons. Thin Phlex wrapper.

render DocsUI::Icon.new("search", class: "size-4")

A missing icon name falls back to a question-mark glyph outside development, rather than raising, so a typo never takes down a docs page in production.

Constant Summary collapse

MISSING_ICON =
"circle-question-mark"

Instance Method Summary collapse

Constructor Details

#initialize(name, **attributes) ⇒ Icon

Returns a new instance of Icon.



13
14
15
16
# File 'app/components/docs_ui/icon.rb', line 13

def initialize(name, **attributes)
  @name = name
  @attributes = attributes
end

Instance Method Details

#view_templateObject



18
19
20
21
22
23
24
25
26
27
28
# File 'app/components/docs_ui/icon.rb', line 18

def view_template
  # rails_icons is a Railtie gem; outside a Rails host (isolated Phlex tests)
  # it isn't loaded, and in a not-yet-fully-set-up app its default library may
  # be unconfigured. Either way, render nothing rather than take down the page
  # — icons are chrome, not content. In development we still raise so a real
  # misconfiguration is visible.
  return unless defined?(::Icons::Icon) && rails_icons_library

  svg = svg_for(@name, **@attributes)
  raw(safe(svg)) if svg
end