Sha256: bbbcd836c37a5631da7e740ddc1c859deb3bd3a2ab46622b2cd1adf5b68f1ed1

Contents?: true

Size: 1.17 KB

Versions: 7

Compression:

Stored size: 1.17 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:drop->#{CONTAINER_CONTROLLER}#drop
          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 errors
            concat(capture { yield form })
          end
        end

        private

        def errors
          Editor::Errors.new(self, container).build
        end

        # 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)

          options
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
katalyst-content-1.1.1 app/helpers/katalyst/content/editor/container.rb
katalyst-content-1.1.0 app/helpers/katalyst/content/editor/container.rb
katalyst-content-1.0.2 app/helpers/katalyst/content/editor/container.rb
katalyst-content-1.0.1 app/helpers/katalyst/content/editor/container.rb
katalyst-content-1.0.0 app/helpers/katalyst/content/editor/container.rb
katalyst-content-0.2.2 app/helpers/katalyst/content/editor/container.rb
katalyst-content-0.2.1 app/helpers/katalyst/content/editor/container.rb