Sha256: 87ee3f584bd8b379c68a22daed2732fc3a9ecbe56c21e92ec93419b267268eef

Contents?: true

Size: 1.29 KB

Versions: 6

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module Katalyst
  module Navigation
    module Editor
      class Menu < Base
        ACTIONS = <<~ACTIONS.gsub(/\s+/, " ").freeze
          submit->#{MENU_CONTROLLER}#reindex
          navigation:drop->#{MENU_CONTROLLER}#drop
          navigation:reindex->#{MENU_CONTROLLER}#reindex
          navigation:reset->#{MENU_CONTROLLER}#reset
        ACTIONS

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

        private

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

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

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

          depth = options.delete(:depth) || menu.depth

          add_option(options, :data, :"#{MENU_CONTROLLER}-max-depth-value", depth) if depth

          options
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
katalyst-navigation-1.4.1 app/helpers/katalyst/navigation/editor/menu.rb
katalyst-navigation-1.4.0 app/helpers/katalyst/navigation/editor/menu.rb
katalyst-navigation-1.3.4 app/helpers/katalyst/navigation/editor/menu.rb
katalyst-navigation-1.3.3 app/helpers/katalyst/navigation/editor/menu.rb
katalyst-navigation-1.3.2 app/helpers/katalyst/navigation/editor/menu.rb
katalyst-navigation-1.3.1 app/helpers/katalyst/navigation/editor/menu.rb