Class: Spina::Api::NavigationSerializer

Inherits:
BaseSerializer show all
Defined in:
app/serializers/spina/api/navigation_serializer.rb

Class Method Summary collapse

Class Method Details

.items_to_tree(collection) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/serializers/spina/api/navigation_serializer.rb', line 12

def items_to_tree(collection)
  collection.map do |item|
    {
      depth: item.depth,
      page: {
        id: item.page_id,
        menu_title: item.menu_title,
        materialized_path: item.materialized_path
      },
      children: items_to_tree(item.children.sorted.in_menu.live.joins(:page))
    }
  end
end