Module: Arrolio::GenericFlowBuilder::Notes

Included in:
Arrolio::GenericFlowBuilder
Defined in:
lib/arrolio/generic_flow_builder/notes.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

#example_flowable(example) ⇒ Object

Examples render the label as a block heading with the body indented 35.4pt — the FOP example layout.



49
50
51
52
53
54
55
56
57
58
# File 'lib/arrolio/generic_flow_builder/notes.rb', line 49

def example_flowable(example)
  body = example.body.map { |paragraph| paragraph_flowable(paragraph) }
  Flowables::NoteFlowable.new(
    example.label,
    body,
    style: resolve(example.style_id),
    body_indent: 35.4,
    label_mode: :block
  )
end

#formatted_note_label(label) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/arrolio/generic_flow_builder/notes.rb', line 37

def formatted_note_label(label)
  return '' if label.nil? || label.empty?

  suffix = @rules.dig('note', 'label_suffix') || ':'
  stripped = label.strip.chomp(':').strip
  return '' if stripped.empty?

  suffix.start_with?(':') ? "#{stripped}#{suffix} " : "#{stripped} #{suffix} "
end

#note_body_flowable(node) ⇒ Object



31
32
33
34
35
# File 'lib/arrolio/generic_flow_builder/notes.rb', line 31

def note_body_flowable(node)
  return list_flowable(node, container: :note) if node.is_a?(Content::List)

  paragraph_flowable(node)
end

#note_flowable(note) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/arrolio/generic_flow_builder/notes.rb', line 9

def note_flowable(note)
  body = note.body.map { |node| note_body_flowable(node) }
  body = with_note_body_spacing(body)
  Flowables::NoteFlowable.new(
    formatted_note_label(note.label),
    body,
    style: resolve(note.style_id),
    label_style: resolve(:note_label)
  )
end

#with_note_body_spacing(body) ⇒ Object

A note's trailing list sits ~7pt below its text in the reference (3.1.3.1: text -> list 20pt vs a plain 13pt pitch).



22
23
24
25
26
27
28
29
# File 'lib/arrolio/generic_flow_builder/notes.rb', line 22

def with_note_body_spacing(body)
  spacing = (@rules.dig('note', 'body_spacing') || 0.0).to_f
  return body if spacing.zero? || body.length < 2

  body.flat_map.with_index do |flowable, index|
    index < body.length - 1 ? [flowable, Flowables::Spacer.new(spacing)] : [flowable]
  end
end