Class: Spina::Pages::PageSelectComponent

Inherits:
ApplicationComponent show all
Defined in:
app/components/spina/pages/page_select_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, pages, include_blank: false, selected: nil, disabled: nil) ⇒ PageSelectComponent

Returns a new instance of PageSelectComponent.



5
6
7
8
9
10
11
# File 'app/components/spina/pages/page_select_component.rb', line 5

def initialize(name, pages, include_blank: false, selected: nil, disabled: nil)
  @name = name
  @pages = pages
  @include_blank = include_blank
  @selected = selected
  @disabled = disabled
end

Instance Attribute Details

#disabledObject

Returns the value of attribute disabled.



3
4
5
# File 'app/components/spina/pages/page_select_component.rb', line 3

def disabled
  @disabled
end

#include_blankObject

Returns the value of attribute include_blank.



3
4
5
# File 'app/components/spina/pages/page_select_component.rb', line 3

def include_blank
  @include_blank
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'app/components/spina/pages/page_select_component.rb', line 3

def name
  @name
end

#pagesObject

Returns the value of attribute pages.



3
4
5
# File 'app/components/spina/pages/page_select_component.rb', line 3

def pages
  @pages
end

#selectedObject

Returns the value of attribute selected.



3
4
5
# File 'app/components/spina/pages/page_select_component.rb', line 3

def selected
  @selected
end

Instance Method Details

#optionsObject



13
14
15
16
17
18
# File 'app/components/spina/pages/page_select_component.rb', line 13

def options
  Spina::Page.sort_by_ancestry(pages.arrange(order: :position)).map do |page|
    page_menu_title = page.menu_title&.indent(page.depth, "")
    [page_menu_title, page.id]
  end
end