Class: StimulusPlumbers::Form::Fields::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/stimulus_plumbers/form/fields/renderer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, theme, field) ⇒ Renderer

Returns a new instance of Renderer.



9
10
11
12
13
# File 'lib/stimulus_plumbers/form/fields/renderer.rb', line 9

def initialize(template, theme, field)
  @template = template
  @theme    = theme
  @field    = field
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



7
8
9
# File 'lib/stimulus_plumbers/form/fields/renderer.rb', line 7

def field
  @field
end

#templateObject (readonly)

Returns the value of attribute template.



7
8
9
# File 'lib/stimulus_plumbers/form/fields/renderer.rb', line 7

def template
  @template
end

#themeObject (readonly)

Returns the value of attribute theme.



7
8
9
# File 'lib/stimulus_plumbers/form/fields/renderer.rb', line 7

def theme
  @theme
end

Instance Method Details

#call(input_html) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/stimulus_plumbers/form/fields/renderer.rb', line 15

def call(input_html)
  field_klass = theme.resolve(:form_group, layout: field.layout, error: field.error?).fetch(:classes, "")

  template.(:div, class: field_klass) do
    label_html + input_html.html_safe + hint_html + errors_html
  end
end