Class: Spina::Pages::PageComponent

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#draggableObject (readonly)

Returns the value of attribute draggable.



4
5
6
# File 'app/components/spina/pages/page_component.rb', line 4

def draggable
  @draggable
end

#pageObject (readonly)

Returns the value of attribute page.



4
5
6
# File 'app/components/spina/pages/page_component.rb', line 4

def page
  @page
end

#sortableObject (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

#childrenObject



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

Returns:

  • (Boolean)


30
31
32
# File 'app/components/spina/pages/page_component.rb', line 30

def collapsed?
  page.resource_id.present?
end

#css_classObject



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

#depthObject



34
35
36
# File 'app/components/spina/pages/page_component.rb', line 34

def depth
  page.depth
end

#draggable?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


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

#labelObject



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.show_in_menu?
  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

Returns:

  • (Boolean)


21
22
23
# File 'app/components/spina/pages/page_component.rb', line 21

def sortable?
  sortable
end