<commit_before>module Para
  module FormBuilder
    module Tabs
      def tabs(&block)
        tabs_manager = TabsManager.new(template, object)
        block.call(tabs_manager)

        template.render partial: 'para/form/tabs', locals: { tabs: tabs_manager.tabs }
      end

      class TabsManager
        attr_reader :template, :object

        def initialize(template, object)
          @template = template
          @object = object
        end

        def tab(identifier, options = {}, &block)
          tabs << Tab.new(template, object, identifier, options, &block)
          nil
        end

        def tabs
          @tabs ||= []
        end
      end

      class Tab
        attr_reader :template, :object, :identifier, :icon, :content

        delegate :capture, to: :template

        def initialize(template, object, identifier, options, &content_block)
          @template = template
          @object = object
          @identifier = identifier
          @content = capture { content_block.call }
          @icon = options[:icon]
        end

        def title
          if Symbol === identifier
            ::I18n.t("forms.tabs.#{ object.class.model_name.i18n_key }.#{ identifier }")
          else
            identifier
          end
        end

        def dom_id
          @dom_id = identifier.to_s.parameterize
        end
      end
    end
  end
end
<commit_msg>make nested fields tabs work<commit_after>module Para
  module FormBuilder
    module Tabs
      def tabs(&block)
        manager = TabsManager.new(template, object, self)
        block.call(manager)

        template.render partial: 'para/form/tabs', locals: { tabs: manager.tabs }
      end

      class TabsManager
        attr_reader :template, :object, :builder

        def initialize(template, object, builder)
          @template = template
          @object = object
          @builder = builder
        end

        def tab(identifier, options = {}, &block)
          tabs << Tab.new(template, object, builder, identifier, options, &block)
          nil
        end

        def tabs
          @tabs ||= []
        end
      end

      class Tab
        attr_reader :template, :object, :builder, :identifier, :icon, :content

        delegate :capture, to: :template

        def initialize(template, object, builder, identifier, options, &content_block)
          @template = template
          @object = object
          @builder = builder
          @identifier = identifier
          @content = capture { content_block.call }
          @icon = options[:icon]
        end

        def title
          if Symbol === identifier
            ::I18n.t("forms.tabs.#{ object.class.model_name.i18n_key }.#{ identifier }")
          else
            identifier
          end
        end

        def dom_id
          @dom_id = [
            builder.nested_resource_dom_id,
            identifier.to_s.parameterize
          ].join('-')
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.08959245537217919, 'fraction_numerical': 0.002694509936005389, 'mean_word_length': 1.737327188940092, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2619809', 'n_tokens_mistral': 804, 'n_tokens_neox': 772, 'n_words': 216}