Sha256: 75e4ca8c6f50b23cc98ef5b56c024bb24ece08f8232e9c63d6a813e871b1642d

Contents?: true

Size: 684 Bytes

Versions: 1

Compression:

Stored size: 684 Bytes

Contents

# frozen_string_literal: true

module PandaCms
  class PageMenuComponent < ViewComponent::Base
    attr_accessor :menu_item
    attr_accessor :children

    def initialize(page:, start_depth:, styles: {})
      start_page = if page.depth == start_depth
        page
      else
        page.ancestors.find { |anc| anc.depth == start_depth }
      end

      menu = PandaCms::Menu.find_by(kind: "auto", start_page: start_page)
      @menu_item = menu.menu_items.order(:lft)&.first unless menu.nil?

      @children = menu_item&.descendants unless menu_item.nil?

      # Set some default styles for sanity
      @styles = styles
      @styles[:indent_with] ||= "pl-2"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
panda_cms-0.5.10 app/components/panda_cms/page_menu_component.rb