Class: PhlexUI::Form::Builder

Inherits:
Base
  • Object
show all
Defined in:
lib/phlex_ui/form/builder.rb

Instance Attribute Summary

Attributes inherited from Base

#attrs

Instance Method Summary collapse

Methods inherited from Base

#before_template, #initialize

Constructor Details

This class inherits a constructor from PhlexUI::Base

Instance Method Details

#button(**button_attrs) ⇒ Object



24
25
26
# File 'lib/phlex_ui/form/builder.rb', line 24

def button(**button_attrs, &)
  render PhlexUI::Button.new(**button_attrs, &)
end

#input(name, label: nil, hint: false, error: nil, **input_attrs) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/phlex_ui/form/builder.rb', line 13

def input(name, label: nil, hint: false, error: nil, **input_attrs)
  name = name.to_s
  label ||= convert_name_to_label(name)

  render PhlexUI::Form::Item.new do
    render PhlexUI::Label.new(for: name) { label } if label
    render PhlexUI::Input.new(name: name, id: name, **input_attrs)
    render PhlexUI::Hint.new { hint } if hint
  end
end

#view_template(&block) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/phlex_ui/form/builder.rb', line 5

def view_template(&block)
  render PhlexUI::Form.new(**attrs) do
    render PhlexUI::Form::Spacer.new do
      block.call
    end
  end
end