Module: Arrolio::GenericFlowBuilder::Sequences

Included in:
Arrolio::GenericFlowBuilder
Defined in:
lib/arrolio/generic_flow_builder/sequences.rb

Overview

Extracted emission seam: one module per content family, the same pattern as GenericAdapter's decomposition. The class keeps build(), dispatch, and shared helpers.

Instance Method Summary collapse

Instance Method Details

#append_endnotes(document, flowables) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/arrolio/generic_flow_builder/sequences.rb', line 80

def append_endnotes(document, flowables)
  return if document.footnotes.empty?
  return unless @rules['endnotes']

  flowables << Flowables::PageSequenceStart.new(
    role: :endnotes,
    header_template: nil,
    footer_template: nil
  )
  document.footnotes.each do |footnote|
    marker_text = footnote.marker.to_s
    body = footnote.body.map { |paragraph| paragraph_flowable(paragraph) }
    flowables << Flowables::NoteFlowable.new(
      marker_text,
      body,
      style: resolve(footnote.style_id),
      marker_width: 22.0
    )
  end
end

#build_cover_content(document, out) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/arrolio/generic_flow_builder/sequences.rb', line 64

def build_cover_content(document, out)
  Array(@rules['cover_content']).each do |entry|
    next unless condition_matches?(entry['when'], document)

    case entry['type'].to_s
    when 'spacer'
      out << Flowables::Spacer.new(entry.fetch('size').to_f)
    when 'text'
      style = resolve(entry.fetch('style'))
      style = style.with(align: :center) if entry.fetch('align', 'center').to_sym == :center
      text = interpolate(entry.fetch('source'), document)
      out << Flowables::TextFlowable.new([InlineRun.new(text, style: style)], style: style)
    end
  end
end

#build_sequence_content(document, source, sequence, out) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/arrolio/generic_flow_builder/sequences.rb', line 26

def build_sequence_content(document, source, sequence, out)
  if sequence['build_content'] == 'cover_content'
    build_cover_content(document, out)
  elsif source.is_a?(Array)
    build_sections(source, out,
                   between_breaks: preface_clause_breaks?(sequence))
  end
end

#content_for(document, role) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/arrolio/generic_flow_builder/sequences.rb', line 55

def content_for(document, role)
  case role.to_s
  when 'preface' then document.preface
  when 'body' then document.sections
  when 'bibliography' then document.bibliography
  else []
  end
end

#page_sequencesObject



9
10
11
# File 'lib/arrolio/generic_flow_builder/sequences.rb', line 9

def page_sequences
  Array(@rules['page_sequences'])
end

#preface_clause_breaks?(sequence) ⇒ Boolean

mn2pdf gives each preface clause its own page sequence (ToC page, then Foreword on a fresh page) when the flavor opts in.

Returns:

  • (Boolean)


37
38
39
40
# File 'lib/arrolio/generic_flow_builder/sequences.rb', line 37

def preface_clause_breaks?(sequence)
  sequence['role'].to_s == 'preface' &&
    @rules.dig('preface', 'page_break_between_clauses')
end

#sequence_start(document, sequence) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/arrolio/generic_flow_builder/sequences.rb', line 13

def sequence_start(document, sequence)
  title = sequence['role'].to_s == 'body' ? title_text(document) : nil
  Flowables::PageSequenceStart.new(
    role: sequence.fetch('role'),
    header_template: interpolate(sequence['header'], document),
    footer_template: sequence['footer'],
    header_align: sequence['header_align'],
    footer_align: sequence['footer_align'] || :center,
    initial_page_number: sequence['initial_page_number'],
    title_template: title
  )
end

#title_text(document) ⇒ Object

The first body page opens with the part title ("Part 1 - title") - the docidentifier's trailing part number supplies the prefix.



45
46
47
48
49
50
51
52
53
# File 'lib/arrolio/generic_flow_builder/sequences.rb', line 45

def title_text(document)
  return nil unless document.title_block

  text = document.title_block.inline_runs.map(&:text).join.strip
  return nil if text.empty?

  part = document.[:docidentifier].to_s[/-(\d+)\z/, 1]
  part ? "Part #{part} - #{text}" : text
end