Class: Panda::CMS::PageMenuComponent

Inherits:
Panda::Core::Base
  • Object
show all
Defined in:
app/components/panda/cms/page_menu_component.rb

Overview

Page menu component for rendering hierarchical page navigation

Instance Method Summary collapse

Instance Method Details

#before_templateObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/components/panda/cms/page_menu_component.rb', line 27

def before_template
  return if @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?

  # Fragment caching: Cache menu items for this page menu
  # Cache key includes menu's updated_at to auto-invalidate on changes
  cache_key = "panda_cms_page_menu/#{menu.id}/#{menu.updated_at.to_i}/items"

  cached_items = Rails.cache.fetch(cache_key, expires_in: 1.hour) do
    menu.menu_items.order(:lft).to_a
  end

  @menu_item = cached_items.first

  # Set default styles if not already set
  @styles[:indent_with] ||= "pl-2" if @styles
end

#view_templateObject



16
17
18
19
20
21
22
23
24
25
# File 'app/components/panda/cms/page_menu_component.rb', line 16

def view_template
  return unless should_render?

  nav(class: @styles[:container]) do
    ul(role: "list", class: "p-0 m-0") do
      render_heading if @show_heading
      render_menu_items
    end
  end
end