Class: Avo::Resources::Items::TabGroup::Builder

Inherits:
Object
  • Object
show all
Includes:
Concerns::BorrowItemsHolder
Defined in:
lib/avo/resources/items/tab_group.rb

Instance Method Summary collapse

Constructor Details

#initialize(name:, id:, parent:, style: nil) ⇒ Builder

Returns a new instance of Builder.



69
70
71
72
# File 'lib/avo/resources/items/tab_group.rb', line 69

def initialize(name:, id:, parent:, style: nil)
  @group = Avo::Resources::Items::TabGroup.new(name: name, id: id, style: style)
  @items_holder = Avo::Resources::Items::Holder.new(parent: parent, from: self)
end

Instance Method Details

#buildObject

Fetch the tab



75
76
77
78
# File 'lib/avo/resources/items/tab_group.rb', line 75

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

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



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/avo/resources/items/tab_group.rb', line 49

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::Resources::Items::Tab.new name: name

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

  @items_holder.tabs tab
end