Class: Spina::Pages::PageComponent
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- Spina::Pages::PageComponent
- Defined in:
- app/components/spina/pages/page_component.rb
Instance Attribute Summary collapse
-
#draggable ⇒ Object
readonly
Returns the value of attribute draggable.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#sortable ⇒ Object
readonly
Returns the value of attribute sortable.
Instance Method Summary collapse
- #children ⇒ Object
-
#collapsed? ⇒ Boolean
Pages are collapsed by default if they’re inside a resource.
- #css_class ⇒ Object
- #depth ⇒ Object
- #draggable? ⇒ Boolean
-
#has_children? ⇒ Boolean
Explicitly check for “== 0” to account for older Spina setups where ancestry_children_count is still NULL.
-
#initialize(page:, sortable: true, draggable: true) ⇒ PageComponent
constructor
A new instance of PageComponent.
- #label ⇒ Object
- #sortable? ⇒ Boolean
Constructor Details
#initialize(page:, sortable: true, draggable: true) ⇒ PageComponent
Returns a new instance of PageComponent.
6 7 8 9 10 |
# File 'app/components/spina/pages/page_component.rb', line 6 def initialize(page:, sortable: true, draggable: true) @page = page @sortable = sortable @draggable = draggable end |
Instance Attribute Details
#draggable ⇒ Object (readonly)
Returns the value of attribute draggable.
4 5 6 |
# File 'app/components/spina/pages/page_component.rb', line 4 def draggable @draggable end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
4 5 6 |
# File 'app/components/spina/pages/page_component.rb', line 4 def page @page end |
#sortable ⇒ Object (readonly)
Returns the value of attribute sortable.
4 5 6 |
# File 'app/components/spina/pages/page_component.rb', line 4 def sortable @sortable end |
Instance Method Details
#children ⇒ Object
54 55 56 |
# File 'app/components/spina/pages/page_component.rb', line 54 def children @children ||= page.children.active.sorted end |
#collapsed? ⇒ Boolean
Pages are collapsed by default if they’re inside a resource
30 31 32 |
# File 'app/components/spina/pages/page_component.rb', line 30 def collapsed? page.resource_id.present? end |
#css_class ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'app/components/spina/pages/page_component.rb', line 38 def css_class case depth when 1 "pl-5 bg-gray-100" when 2 "pl-10 bg-gray-200" end end |
#depth ⇒ Object
34 35 36 |
# File 'app/components/spina/pages/page_component.rb', line 34 def depth page.depth end |
#draggable? ⇒ Boolean
25 26 27 |
# File 'app/components/spina/pages/page_component.rb', line 25 def draggable? draggable end |
#has_children? ⇒ Boolean
Explicitly check for “== 0” to account for older Spina setups where ancestry_children_count is still NULL
49 50 51 52 |
# File 'app/components/spina/pages/page_component.rb', line 49 def has_children? return false if page.ancestry_children_count == 0 page.has_children? end |
#label ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'app/components/spina/pages/page_component.rb', line 12 def label labels = [] labels << t("spina.pages.concept") if @page.draft? labels << t("spina.pages.show_in_menu") unless @page. labels << t("spina.pages.skip_to_first_child") if @page.skip_to_first_child? return nil if labels.size.zero? "(#{labels.join(", ")})" end |
#sortable? ⇒ Boolean
21 22 23 |
# File 'app/components/spina/pages/page_component.rb', line 21 def sortable? sortable end |