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.
245 246 247 248 |
# File 'app/helpers/maquina_components/combobox_helper.rb', line 245 def initialize(view_context) @view = view_context @parts = [] end |
Instance Method Details
#group(**options) { ... } ⇒ Object
Adds a group
272 273 274 275 276 277 278 279 280 |
# File 'app/helpers/maquina_components/combobox_helper.rb', line 272 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
287 288 289 290 291 292 293 294 |
# File 'app/helpers/maquina_components/combobox_helper.rb', line 287 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
257 258 259 260 261 262 263 264 265 266 |
# File 'app/helpers/maquina_components/combobox_helper.rb', line 257 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
299 300 301 |
# File 'app/helpers/maquina_components/combobox_helper.rb', line 299 def separator(**) @parts << @view.render("components/combobox/separator", **) end |
#to_html ⇒ Object
Generates the final HTML
304 305 306 |
# File 'app/helpers/maquina_components/combobox_helper.rb', line 304 def to_html @view.safe_join(@parts) end |