Class: PandaCms::PageMenuComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/panda_cms/page_menu_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page:, start_depth:, styles: {}, show_heading: true) ⇒ PageMenuComponent

Returns a new instance of PageMenuComponent.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/components/panda_cms/page_menu_component.rb', line 9

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

Instance Attribute Details

Returns the value of attribute menu_item.



6
7
8
# File 'app/components/panda_cms/page_menu_component.rb', line 6

def menu_item
  @menu_item
end

#pageObject

Returns the value of attribute page.



5
6
7
# File 'app/components/panda_cms/page_menu_component.rb', line 5

def page
  @page
end

#stylesObject

Returns the value of attribute styles.



7
8
9
# File 'app/components/panda_cms/page_menu_component.rb', line 7

def styles
  @styles
end

Instance Method Details

#render?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'app/components/panda_cms/page_menu_component.rb', line 32

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