Class: Avo::TabGroupBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/avo/tab_group_builder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(style: nil) ⇒ TabGroupBuilder

Returns a new instance of TabGroupBuilder.



12
13
14
15
# File 'lib/avo/tab_group_builder.rb', line 12

def initialize(style: nil)
  @group = Avo::TabGroup.new(style: style)
  @items_holder = Avo::ItemsHolder.new
end

Instance Attribute Details

#items_holderObject (readonly)

Returns the value of attribute items_holder.



8
9
10
# File 'lib/avo/tab_group_builder.rb', line 8

def items_holder
  @items_holder
end

Class Method Details

.parse_block(**args, &block) ⇒ Object



3
4
5
# File 'lib/avo/tab_group_builder.rb', line 3

def parse_block(**args, &block)
  Docile.dsl_eval(new(**args), &block).build
end

Instance Method Details

#buildObject

Fetch the tab



39
40
41
42
# File 'lib/avo/tab_group_builder.rb', line 39

def build
  @group.items_holder = @items_holder
  @group
end

#field(field_name, **args, &block) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/avo/tab_group_builder.rb', line 17

def field(field_name, **args, &block)
  parsed = Avo::Dsl::FieldParser.new(id: field_name, order_index: @items_index, **args, &block).parse
  field_instance = parsed.instance

  name = field_instance.name
  tab = Avo::Tab.new name: name

  if field_instance.has_own_panel?
    tab.items_holder.add_item parsed.instance
    tab.holds_one_field = true
  else
    # If the field is not in a panel, create one and add it
    panel = Avo::Panel.new name: name
    panel.items_holder.add_item parsed.instance
    # Add that panel to the bag
    tab.items_holder.add_item panel
  end

  @items_holder.tabs tab
end