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.36.2 lib/avo/tab_group_builder.rb
avo-2.36.1 lib/avo/tab_group_builder.rb
avo-2.36.0 lib/avo/tab_group_builder.rb
avo-2.35.0 lib/avo/tab_group_builder.rb
avo-2.34.7.pre.1 lib/avo/tab_group_builder.rb
avo-2.34.6 lib/avo/tab_group_builder.rb
avo-2.34.5 lib/avo/tab_group_builder.rb
avo-2.34.4 lib/avo/tab_group_builder.rb
avo-2.34.4.pre.1 lib/avo/tab_group_builder.rb
avo-2.34.3 lib/avo/tab_group_builder.rb
avo-2.34.2 lib/avo/tab_group_builder.rb
avo-2.34.1 lib/avo/tab_group_builder.rb
avo-2.34.0 lib/avo/tab_group_builder.rb
avo-2.33.3 lib/avo/tab_group_builder.rb
avo-2.33.3.pre.2 lib/avo/tab_group_builder.rb
avo-2.33.3.pre.1 lib/avo/tab_group_builder.rb
avo-2.33.2 lib/avo/tab_group_builder.rb
avo-2.33.1 lib/avo/tab_group_builder.rb
avo-2.33.0 lib/avo/tab_group_builder.rb
avo-2.32.6 lib/avo/tab_group_builder.rb