Class: MaquinaComponents::ComboboxHelper::ComboboxListBuilder

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/maquina_components/combobox_helper.rb

Overview

Builder for combobox list content

Instance Method Summary collapse

Constructor Details

#initialize(view_context) ⇒ ComboboxListBuilder

Returns a new instance of ComboboxListBuilder.



236
237
238
239
# File 'app/helpers/maquina_components/combobox_helper.rb', line 236

def initialize(view_context)
  @view = view_context
  @parts = []
end

Instance Method Details

#group(**options) { ... } ⇒ Object

Adds a group

Parameters:

  • options (Hash)

    Additional options

Yields:

  • Block containing group items



263
264
265
266
267
268
269
270
271
# File 'app/helpers/maquina_components/combobox_helper.rb', line 263

def group(**options, &block)
  group_builder = ComboboxListBuilder.new(@view)
  @view.capture(group_builder, &block)

  @parts << @view.render(
    "components/combobox/group",
    **options
  ) { group_builder.to_html }
end

#label(text = nil, **options) { ... } ⇒ Object

Adds a label

Parameters:

  • text (String, nil) (defaults to: nil)

    Label text

  • options (Hash)

    Additional options

Yields:

  • Optional block for custom content



278
279
280
281
282
283
284
285
# File 'app/helpers/maquina_components/combobox_helper.rb', line 278

def label(text = nil, **options, &block)
  @parts << @view.render(
    "components/combobox/label",
    text: text,
    **options,
    &block
  )
end

#option(value:, selected: false, disabled: false, **options) { ... } ⇒ Object

Adds an option

Parameters:

  • value (String)

    Option value

  • selected (Boolean) (defaults to: false)

    Whether selected

  • disabled (Boolean) (defaults to: false)

    Whether disabled

  • options (Hash)

    Additional options

Yields:

  • Block for option content



248
249
250
251
252
253
254
255
256
257
# File 'app/helpers/maquina_components/combobox_helper.rb', line 248

def option(value:, selected: false, disabled: false, **options, &block)
  content = @view.capture(&block) if block
  @parts << @view.render(
    "components/combobox/option",
    value: value,
    selected: selected,
    disabled: disabled,
    **options
  ) { content }
end

#separator(**options) ⇒ Object

Adds a separator

Parameters:

  • options (Hash)

    Additional options



290
291
292
# File 'app/helpers/maquina_components/combobox_helper.rb', line 290

def separator(**options)
  @parts << @view.render("components/combobox/separator", **options)
end

#to_htmlObject

Generates the final HTML



295
296
297
# File 'app/helpers/maquina_components/combobox_helper.rb', line 295

def to_html
  @view.safe_join(@parts)
end