Class: PandaCms::PageMenuComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- PandaCms::PageMenuComponent
- Defined in:
- app/components/panda_cms/page_menu_component.rb
Instance Attribute Summary collapse
-
#menu_item ⇒ Object
Returns the value of attribute menu_item.
-
#page ⇒ Object
Returns the value of attribute page.
-
#styles ⇒ Object
Returns the value of attribute styles.
Instance Method Summary collapse
-
#initialize(page:, start_depth:, styles: {}, show_heading: true) ⇒ PageMenuComponent
constructor
A new instance of PageMenuComponent.
- #render? ⇒ Boolean
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 = start_page&. return if .nil? @menu_item = ..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
#menu_item ⇒ Object
Returns the value of attribute menu_item.
6 7 8 |
# File 'app/components/panda_cms/page_menu_component.rb', line 6 def @menu_item end |
#page ⇒ Object
Returns the value of attribute page.
5 6 7 |
# File 'app/components/panda_cms/page_menu_component.rb', line 5 def page @page end |
#styles ⇒ Object
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
32 33 34 |
# File 'app/components/panda_cms/page_menu_component.rb', line 32 def render? @page&.path != "/" && @menu_item.present? end |