Class: PhlexForms::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/phlex_forms/configuration.rb

Overview

Central configuration for phlex-forms. Set via PhlexForms.configure.

PhlexForms.configure do |c|
c.icon_renderer = ->(name, **opts) { MyIcons::Icon.new(name, **opts) }
end

The icon renderer is a callable ->(name, **opts) { renderable } returning something a Phlex component can emit: a Phlex component instance OR a raw SVG String.

The DEFAULT is a bundled inline SVG so phlex-forms is self-contained and renders identically with no host configuration. To use the glyphs gem (which resolves a full icon set from the host app's rails_icons asset tree), opt in:

PhlexForms.configure do |c|
c.icon_renderer = PhlexForms::Configuration.glyphs_renderer
end

glyphs is intentionally NOT the default: rails_icons reads SVGs from the host app's asset paths, which a minimal host (or the gem's own test suite) has not set up — so defaulting to glyphs would raise Icons::IconNotFound.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#field_variantsObject



49
50
51
# File 'lib/phlex_forms/configuration.rb', line 49

def field_variants
  @field_variants ||= []
end

#icon_rendererObject



67
68
69
# File 'lib/phlex_forms/configuration.rb', line 67

def icon_renderer
  @icon_renderer ||= ->(name, **opts) { InlineIcons.render(name, **opts) }
end

#infer_from_modelObject



61
62
63
64
65
# File 'lib/phlex_forms/configuration.rb', line 61

def infer_from_model
  return @infer_from_model if defined?(@infer_from_model) && !@infer_from_model.nil?

  true
end

#themeObject



57
58
59
# File 'lib/phlex_forms/configuration.rb', line 57

def theme
  @theme ||= defined?(DaisyUI) ? Theme.daisy : Theme.plain
end

Class Method Details

.glyphs_rendererObject

A ready-made renderer that delegates to glyphs' LucideIcon. Raises a clear error if glyphs is not loaded.



28
29
30
31
32
33
34
35
# File 'lib/phlex_forms/configuration.rb', line 28

def self.glyphs_renderer
  unless defined?(Glyphs::LucideIcon)
    raise PhlexForms::FeatureUnavailable,
      "PhlexForms glyphs_renderer requires the `glyphs` gem to be loaded"
  end

  ->(name, **opts) { Glyphs::LucideIcon.new(name, **opts) }
end

Instance Method Details

#render_icon(name) ⇒ Object

Returns a renderable for the named icon. Components pass the result to Phlex render/raw as appropriate.



73
74
75
# File 'lib/phlex_forms/configuration.rb', line 73

def render_icon(name, **)
  icon_renderer.call(name.to_s, **)
end