Class: PhlexUI::Select::Builder
- Defined in:
- lib/phlex_ui/select/builder.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(object, method, collection: [], placeholder: "", value: nil, input_attrs: {}, trigger_attrs: {}, value_attrs: {}, content_attrs: {}, group_attrs: {}, item_attrs: {}, **attrs) ⇒ Builder
constructor
A new instance of Builder.
- #view_template ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(object, method, collection: [], placeholder: "", value: nil, input_attrs: {}, trigger_attrs: {}, value_attrs: {}, content_attrs: {}, group_attrs: {}, item_attrs: {}, **attrs) ⇒ Builder
Returns a new instance of Builder.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/phlex_ui/select/builder.rb', line 5 def initialize(object, method, collection: [], placeholder: "", value: nil, input_attrs: {}, trigger_attrs: {}, value_attrs: {}, content_attrs: {}, group_attrs: {}, item_attrs: {}, **attrs) @object = set_object(object) @method = method @collection = collection @placeholder = placeholder @value = value || @object.send(@method) @input_attrs = input_attrs @trigger_attrs = trigger_attrs @value_attrs = value_attrs @content_attrs = content_attrs @group_attrs = group_attrs @item_attrs = item_attrs super(**attrs) end |
Instance Method Details
#view_template ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/phlex_ui/select/builder.rb', line 20 def view_template render PhlexUI::Select.new(**attrs) do render PhlexUI::Select::Input.new(value: @object.send(@method), id: select_id, name: input_name, type: "hidden", **@input_attrs) render PhlexUI::Select::Trigger.new(**@trigger_attrs) do if @value render PhlexUI::Select::Value.new(id: select_id, **@value_attrs) { @collection.find { |choice| choice[1] == @value }[0] } else render PhlexUI::Select::Value.new(placeholder: @placeholder, id: select_id, **@value_attrs) end end render PhlexUI::Select::Content.new(outlet_id: select_id, **@content_attrs) do render PhlexUI::Select::Group.new(**@group_attrs) do @collection.each do |choice| render PhlexUI::Select::Item.new(value: choice[1], selected: @object&.send(@method) == choice[1], **@item_attrs) { choice[0] } end end end end end |