Sha256: 69878551293d90a13dfe01a948be972374c74c435a6f9c7f3c457a345c146c64

Contents?: true

Size: 607 Bytes

Versions: 32

Compression:

Stored size: 607 Bytes

Contents

# frozen_string_literal: true

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

    def initialize(page:, start_depth:)
      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?
    end

    def render?
      @menu_item
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
panda_cms-0.5.7 app/components/panda_cms/page_menu_component.rb
panda_cms-0.5.6 app/components/panda_cms/page_menu_component.rb
panda_cms-0.5.5 app/components/panda_cms/page_menu_component.rb
panda_cms-0.5.4 app/components/panda_cms/page_menu_component.rb
panda_cms-0.5.3 app/components/panda_cms/page_menu_component.rb
panda_cms-0.5.2 app/components/panda_cms/page_menu_component.rb
panda_cms-0.5.1 app/components/panda_cms/page_menu_component.rb
panda_cms-0.5.0 app/components/panda_cms/page_menu_component.rb
panda_cms-0.3.15 app/components/panda_cms/page_menu_component.rb
panda_cms-0.3.14 app/components/panda_cms/page_menu_component.rb
panda_cms-0.3.13 app/components/panda_cms/page_menu_component.rb
panda_cms-0.3.12 app/components/panda_cms/page_menu_component.rb
panda_cms-0.3.11 app/components/panda_cms/page_menu_component.rb
panda_cms-0.3.10 app/components/panda_cms/page_menu_component.rb
panda_cms-0.3.9 app/components/panda_cms/page_menu_component.rb
panda_cms-0.3.8 app/components/panda_cms/page_menu_component.rb
panda_cms-0.3.7 app/components/panda_cms/page_menu_component.rb
panda_cms-0.3.6 app/components/panda_cms/page_menu_component.rb
panda_cms-0.3.5 app/components/panda_cms/page_menu_component.rb
panda_cms-0.3.4 app/components/panda_cms/page_menu_component.rb