Sha256: f69f8f146493dfd088d84696737382570174a0c78e245627d9ff9e36d467052b

Contents?: true

Size: 889 Bytes

Versions: 3

Compression:

Stored size: 889 Bytes

Contents

# frozen_string_literal: true

module Panda
  module CMS
    class PageMenuComponent < ViewComponent::Base
      attr_accessor :page
      attr_accessor :menu_item
      attr_accessor :styles

      def initialize(page:, start_depth:, styles: {}, show_heading: true)
        @page = page

        unless @page.nil?
          start_page = if @page.depth == start_depth
            @page
          else
            @page.ancestors.find { |anc| anc.depth == start_depth }
          end

          menu = start_page&.page_menu
          return if menu.nil?

          @menu_item = menu.menu_items.order(:lft)&.first

          @show_heading = show_heading

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

      def render?
        @page&.path != "/" && @menu_item.present?
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
panda-cms-0.7.3 app/components/panda/cms/page_menu_component.rb
panda-cms-0.7.2 app/components/panda/cms/page_menu_component.rb
panda-cms-0.7.0 app/components/panda/cms/page_menu_component.rb