Class: Coradoc::Reference::Presentation::CustomHierarchy

Inherits:
Base
  • Object
show all
Defined in:
lib/coradoc/reference/presentation/custom_hierarchy.rb

Overview

Caller-supplied hierarchy. The user provides a tree of node ids mapping to pages; the presentation lays out content accordingly. This is the presentation website builds use.

CustomHierarchy.new(hierarchy: [
{ id: "intro", title: "Introduction", children: [...] },
{ id: "chap1", title: "Chapter 1", children: [
  { id: "chap1-1", title: "1.1" }
] }
])

Defined Under Namespace

Classes: VisitorById

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#key

Constructor Details

#initialize(hierarchy:) ⇒ CustomHierarchy

Returns a new instance of CustomHierarchy.



23
24
25
26
# File 'lib/coradoc/reference/presentation/custom_hierarchy.rb', line 23

def initialize(hierarchy:)
  super()
  @hierarchy = normalize_hierarchy(hierarchy)
end

Instance Attribute Details

#hierarchyObject (readonly)

Returns the value of attribute hierarchy.



17
18
19
# File 'lib/coradoc/reference/presentation/custom_hierarchy.rb', line 17

def hierarchy
  @hierarchy
end

Class Method Details

.keyObject



19
20
21
# File 'lib/coradoc/reference/presentation/custom_hierarchy.rb', line 19

def self.key
  :custom_hierarchy
end

Instance Method Details

#layout(resolved_graph) ⇒ Object



28
29
30
31
32
# File 'lib/coradoc/reference/presentation/custom_hierarchy.rb', line 28

def layout(resolved_graph)
  pages = []
  walk_hierarchy(@hierarchy, parent_id: nil, pages: pages, root: resolved_graph)
  pages
end

#locate_page(_edge, target_content, pages:) ⇒ Object



34
35
36
# File 'lib/coradoc/reference/presentation/custom_hierarchy.rb', line 34

def locate_page(_edge, target_content, pages:)
  pages.find { |page| page.content.equal?(target_content) }
end