Class: Coradoc::Reference::Presentation::SplitPages

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

Overview

Splits the document by top-level section (or a configurable boundary). Each section becomes a Page. Cross-references are rewritten to point at whichever page the target content lives on.

SplitPages.new(split_at: :section)  # default
SplitPages.new(split_at: :chapter) # HeaderElement only

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#key

Constructor Details

#initialize(split_at: :section) ⇒ SplitPages

Returns a new instance of SplitPages.



19
20
21
22
23
# File 'lib/coradoc/reference/presentation/split_pages.rb', line 19

def initialize(split_at: :section)
  super()
  @split_at = split_at.to_sym
  @page_index = nil
end

Instance Attribute Details

#split_atObject (readonly)

Returns the value of attribute split_at.



13
14
15
# File 'lib/coradoc/reference/presentation/split_pages.rb', line 13

def split_at
  @split_at
end

Class Method Details

.keyObject



15
16
17
# File 'lib/coradoc/reference/presentation/split_pages.rb', line 15

def self.key
  :split_pages
end

Instance Method Details

#layout(resolved_graph) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/coradoc/reference/presentation/split_pages.rb', line 25

def layout(resolved_graph)
  children = read_children(resolved_graph)
  return [single_page_for(resolved_graph)] if children.nil? || children.empty?

  sections = children.select { |child| matches_split?(child) }
  return [single_page_for(resolved_graph)] if sections.empty?

  pages = sections.map.with_index { |section, idx| page_for(section, resolved_graph, idx) }
  index_pages!(pages)
  pages
end

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



37
38
39
40
41
42
# File 'lib/coradoc/reference/presentation/split_pages.rb', line 37

def locate_page(_edge, target_content, pages:)
  indexed = @page_index&.[](target_content)
  return indexed if indexed

  pages.find { |page| owns_target?(page, target_content) }
end