Sha256: 439d8243fe3ff9ba46b244360dd18c44402414090be2c5a2d657a3c44200bb2b

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module Katalyst
  module Content
    module Editor
      class Container < Base
        ACTIONS = <<~ACTIONS.gsub(/\s+/, " ").freeze
          submit->#{CONTAINER_CONTROLLER}#reindex
          content:reindex->#{CONTAINER_CONTROLLER}#reindex
          content:reset->#{CONTAINER_CONTROLLER}#reset
        ACTIONS

        def build(options)
          form_with(model: container, **default_options(id: container_form_id, **options)) do |form|
            concat hidden_input
            concat(capture { yield form })
          end
        end

        private

        # Hidden input ensures that if the container is empty then the controller
        # receives an empty array.
        def hidden_input
          tag.input(type: "hidden", name: "#{attributes_scope}[id]")
        end

        def default_options(options)
          add_option(options, :data, :controller, CONTAINER_CONTROLLER)
          add_option(options, :data, :action, ACTIONS)

          # depth = options.delete(:depth) || container.depth
          #
          # add_option(options, :data, :"#{CONTAINER_CONTROLLER}-max-depth-value", depth) if depth

          options
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
katalyst-content-0.1.2 app/helpers/katalyst/content/editor/container.rb
katalyst-content-0.1.1 app/helpers/katalyst/content/editor/container.rb
katalyst-content-0.1.0 app/helpers/katalyst/content/editor/container.rb