Class: Panda::CMS::PageMenuComponent
- Inherits:
-
Panda::Core::Base
- Object
- Panda::Core::Base
- Panda::CMS::PageMenuComponent
- 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_template ⇒ Object
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 = @start_page&. return if .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/#{.id}/#{.updated_at.to_i}/items" cached_items = Rails.cache.fetch(cache_key, expires_in: 1.hour) do ..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_template ⇒ Object
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 end end end |