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.21.0 lib/avo/tab_group_builder.rb
avo-2.21.1.pre.pr1476 lib/avo/tab_group_builder.rb
avo-2.21.1.pre.issue1450 lib/avo/tab_group_builder.rb
avo-2.21.1.pre.issue1444 lib/avo/tab_group_builder.rb
avo-2.20.0 lib/avo/tab_group_builder.rb
avo-2.19.0 lib/avo/tab_group_builder.rb
avo-2.18.1 lib/avo/tab_group_builder.rb
avo-2.18.1.pre.1.eagerloaddirs lib/avo/tab_group_builder.rb
avo-2.18.0 lib/avo/tab_group_builder.rb
avo-2.17.1.pre.5.stackedlayout lib/avo/tab_group_builder.rb
avo-2.17.1.pre.4.issue.1342 lib/avo/tab_group_builder.rb
avo-2.17.1.pre.3 lib/avo/tab_group_builder.rb
avo-2.17.1.pre.2.customauthorizationclients lib/avo/tab_group_builder.rb
avo-2.17.1.pre.1.zeitwerk.eager.load.dir lib/avo/tab_group_builder.rb
avo-2.17.0 lib/avo/tab_group_builder.rb
avo-2.16.1.pre.1.nativefields lib/avo/tab_group_builder.rb
avo-2.16.0 lib/avo/tab_group_builder.rb
avo-2.15.3 lib/avo/tab_group_builder.rb
avo-2.15.3.pre.1.data.attrs.to.sidebar.items lib/avo/tab_group_builder.rb
avo-2.15.2 lib/avo/tab_group_builder.rb