Class: Charming::Presentation::Components::Form::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/charming/presentation/components/form/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(theme: nil) ⇒ Builder

Returns a new instance of Builder.



10
11
12
13
# File 'lib/charming/presentation/components/form/builder.rb', line 10

def initialize(theme: nil)
  @theme = theme
  @fields = []
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



8
9
10
# File 'lib/charming/presentation/components/form/builder.rb', line 8

def fields
  @fields
end

#themeObject (readonly)

Returns the value of attribute theme.



8
9
10
# File 'lib/charming/presentation/components/form/builder.rb', line 8

def theme
  @theme
end

Instance Method Details

#build(state:, theme: nil) ⇒ Object



35
36
37
# File 'lib/charming/presentation/components/form/builder.rb', line 35

def build(state:, theme: nil)
  Components::Form.new(fields: fields, state: state, theme: theme || self.theme)
end

#confirm(name, **options) ⇒ Object



27
28
29
# File 'lib/charming/presentation/components/form/builder.rb', line 27

def confirm(name, **options)
  fields << Confirm.new(name, **field_options(options))
end

#input(name, **options) ⇒ Object



15
16
17
# File 'lib/charming/presentation/components/form/builder.rb', line 15

def input(name, **options)
  fields << Input.new(name, **field_options(options))
end

#note(text, **options) ⇒ Object



31
32
33
# File 'lib/charming/presentation/components/form/builder.rb', line 31

def note(text, **options)
  fields << Note.new(text, **field_options(options))
end

#select(name, **options) ⇒ Object



23
24
25
# File 'lib/charming/presentation/components/form/builder.rb', line 23

def select(name, **options)
  fields << Select.new(name, **field_options(options))
end

#textarea(name, **options) ⇒ Object



19
20
21
# File 'lib/charming/presentation/components/form/builder.rb', line 19

def textarea(name, **options)
  fields << Textarea.new(name, **field_options(options))
end