Sha256: cb323c2f292375199a7a8d86a229aba6d7c6bc631a0827d1bc0703a5a65be8d7

Contents?: true

Size: 1014 Bytes

Versions: 4

Compression:

Stored size: 1014 Bytes

Contents

# frozen_string_literal: true

module Katalyst
  module Navigation
    module Editor
      class Menu < Base
        ACTIONS = <<~ACTIONS.gsub(/\s+/, " ").freeze
          submit->#{MENU_CONTROLLER}#reindex
          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(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 default_options(options)
          add_option(options, :data, :controller, MENU_CONTROLLER)
          add_option(options, :data, :action, ACTIONS)

          options
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
katalyst-navigation-1.0.3 app/helpers/katalyst/navigation/editor/menu.rb
katalyst-navigation-1.0.2 app/helpers/katalyst/navigation/editor/menu.rb
katalyst-navigation-1.0.1 app/helpers/katalyst/navigation/editor/menu.rb
katalyst-navigation-1.0.0 app/helpers/katalyst/navigation/editor/menu.rb