Class: MaquinaComponents::ComboboxHelper::ComboboxListBuilder
- Inherits:
-
Object
- Object
- MaquinaComponents::ComboboxHelper::ComboboxListBuilder
- Defined in:
- app/helpers/maquina_components/combobox_helper.rb
Overview
Builder for combobox list content
Instance Method Summary collapse
-
#group(**options) { ... } ⇒ Object
Adds a group.
-
#initialize(view_context) ⇒ ComboboxListBuilder
constructor
A new instance of ComboboxListBuilder.
-
#label(text = nil, **options) { ... } ⇒ Object
Adds a label.
-
#option(value:, selected: false, disabled: false, **options) { ... } ⇒ Object
Adds an option.
-
#separator(**options) ⇒ Object
Adds a separator.
-
#to_html ⇒ Object
Generates the final HTML.
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
263 264 265 266 267 268 269 270 271 |
# File 'app/helpers/maquina_components/combobox_helper.rb', line 263 def group(**, &block) group_builder = ComboboxListBuilder.new(@view) @view.capture(group_builder, &block) @parts << @view.render( "components/combobox/group", ** ) { group_builder.to_html } end |
#label(text = nil, **options) { ... } ⇒ Object
Adds a label
278 279 280 281 282 283 284 285 |
# File 'app/helpers/maquina_components/combobox_helper.rb', line 278 def label(text = nil, **, &block) @parts << @view.render( "components/combobox/label", text: text, **, &block ) end |
#option(value:, selected: false, disabled: false, **options) { ... } ⇒ Object
Adds an option
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, **, &block) content = @view.capture(&block) if block @parts << @view.render( "components/combobox/option", value: value, selected: selected, disabled: disabled, ** ) { content } end |
#separator(**options) ⇒ Object
Adds a separator
290 291 292 |
# File 'app/helpers/maquina_components/combobox_helper.rb', line 290 def separator(**) @parts << @view.render("components/combobox/separator", **) end |
#to_html ⇒ Object
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 |