Class: Arrolio::GenericFlowBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/arrolio/generic_flow_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(layout_spec:, rules:, asset_resolver: nil) ⇒ GenericFlowBuilder

Returns a new instance of GenericFlowBuilder.



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

def initialize(layout_spec:, rules:, asset_resolver: nil)
  @layout_spec = layout_spec
  @rules = rules.is_a?(String) ? YAML.safe_load_file(rules, aliases: true) : rules
  @asset_resolver = asset_resolver || AssetResolver.new(base_dirs: [])
end

Instance Attribute Details

#asset_resolverObject (readonly)

Returns the value of attribute asset_resolver.



7
8
9
# File 'lib/arrolio/generic_flow_builder.rb', line 7

def asset_resolver
  @asset_resolver
end

#layout_specObject (readonly)

Returns the value of attribute layout_spec.



7
8
9
# File 'lib/arrolio/generic_flow_builder.rb', line 7

def layout_spec
  @layout_spec
end

#rulesObject (readonly)

Returns the value of attribute rules.



7
8
9
# File 'lib/arrolio/generic_flow_builder.rb', line 7

def rules
  @rules
end

Instance Method Details

#append_endnotes(document, flowables) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/arrolio/generic_flow_builder.rb', line 48

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

#append_inline_footnote_markers(document, flowables) ⇒ Object

Emits a FootnoteMarkerFlowable for each Document#footnote when the flavor opts in via flow_rules.page_bottom_footnotes: true. The engine collects these onto the page where they appear (the last body page by default) and the renderer draws them at the bottom.

This is a pragmatic bridge until the adapter can emit markers inline at <fn> reference sites (TODO 60). Opt-in keeps it disabled by default so existing flavors are unaffected.



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

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

  document.footnotes.each do |footnote|
    flowables << Flowables::FootnoteMarkerFlowable.new(footnote)
  end
end

#build(document) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/arrolio/generic_flow_builder.rb', line 15

def build(document)
  @document = document
  flowables = []
  page_sequences.each do |sequence|
    source = content_for(document, sequence['role'])
    next if sequence['role'].to_s != 'cover' && sequence['role'].to_s != 'back_of_cover' && source.empty?

    flowables << sequence_start(document, sequence)
    build_sequence_content(document, source, sequence, flowables)
    flowables << Flowables::PageBreak.new if sequence['page_break_after']
  end
  append_inline_footnote_markers(document, flowables)
  append_endnotes(document, flowables)
  flowables
end