Sha256: 4d2c18e135659d933b1d6bf4c9f8be4005e056841ce0fbe8925087e4a1ec374b

Contents?: true

Size: 1.04 KB

Versions: 115

Compression:

Stored size: 1.04 KB

Contents

class Avo::TabGroupBuilder
  class << self
    def parse_block(**args, &block)
      Docile.dsl_eval(new(**args), &block).build
    end
  end

  attr_reader :items_holder

  delegate :tab, to: :items_holder

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

  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

  # Fetch the tab
  def build
    @group.items_holder = @items_holder
    @group
  end
end

Version data entries

115 entries across 115 versions & 1 rubygems

Version Path
avo-2.53.0 lib/avo/tab_group_builder.rb
avo-2.52.0 lib/avo/tab_group_builder.rb
avo-2.49.0 lib/avo/tab_group_builder.rb
avo-2.48.0 lib/avo/tab_group_builder.rb
avo-2.47.0 lib/avo/tab_group_builder.rb
avo-2.46.0 lib/avo/tab_group_builder.rb
avo-2.45.0 lib/avo/tab_group_builder.rb
avo-2.44.0 lib/avo/tab_group_builder.rb
avo-2.43.0 lib/avo/tab_group_builder.rb
avo-2.42.2 lib/avo/tab_group_builder.rb
avo-2.42.1 lib/avo/tab_group_builder.rb
avo-2.42.0 lib/avo/tab_group_builder.rb
avo-2.41.0 lib/avo/tab_group_builder.rb
avo-2.40.0 lib/avo/tab_group_builder.rb
avo-2.39.0 lib/avo/tab_group_builder.rb
avo-2.38.0 lib/avo/tab_group_builder.rb
avo-2.37.2 lib/avo/tab_group_builder.rb
avo-2.37.1 lib/avo/tab_group_builder.rb
avo-2.37.0 lib/avo/tab_group_builder.rb
avo-2.36.3 lib/avo/tab_group_builder.rb