Class: Arrolio::GenericFlowBuilder

Inherits:
Object
  • Object
show all
Includes:
Bibliography, Figures, Lists, Notes, Sequences, Tables, Terms
Defined in:
lib/arrolio/generic_flow_builder.rb,
lib/arrolio/generic_flow_builder/lists.rb,
lib/arrolio/generic_flow_builder/notes.rb,
lib/arrolio/generic_flow_builder/terms.rb,
lib/arrolio/generic_flow_builder/tables.rb,
lib/arrolio/generic_flow_builder/figures.rb,
lib/arrolio/generic_flow_builder/sequences.rb,
lib/arrolio/generic_flow_builder/bibliography.rb

Defined Under Namespace

Modules: Bibliography, Figures, Lists, Notes, Sequences, Tables, Terms

Constant Summary

Constants included from Figures

Figures::INLINE_SVG_PREFIX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Tables

#caption_runs_for, #table_geometry

Methods included from Bibliography

#bibliography_body_paragraph, #bibliography_item_flowable, #marker_width_of

Methods included from Lists

#default_marker, #flowable_for_list_content, #list_flowable, #list_geometry

Methods included from Figures

#figure_group_flowable, #image_flowable, #resolve_image_source, #svg_dimension, #with_block_gap, #write_inline_svg

Methods included from Notes

#example_flowable, #formatted_note_label, #note_body_flowable, #note_flowable, #with_note_body_spacing

Methods included from Terms

#apply_sibling_spacing, #term_config, #term_entry_flowable, #widen_first_definition_widows

Methods included from Sequences

#append_endnotes, #build_cover_content, #build_sequence_content, #content_for, #page_sequences, #preface_clause_breaks?, #sequence_start, #title_text

Constructor Details

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

Returns a new instance of GenericFlowBuilder.



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

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.



25
26
27
# File 'lib/arrolio/generic_flow_builder.rb', line 25

def asset_resolver
  @asset_resolver
end

#layout_specObject (readonly)

Returns the value of attribute layout_spec.



25
26
27
# File 'lib/arrolio/generic_flow_builder.rb', line 25

def layout_spec
  @layout_spec
end

#rulesObject (readonly)

Returns the value of attribute rules.



25
26
27
# File 'lib/arrolio/generic_flow_builder.rb', line 25

def rules
  @rules
end

Instance Method Details

#build(document) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/arrolio/generic_flow_builder.rb', line 33

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?

    start = sequence_start(document, sequence)
    flowables << start
    # The part-title overlay consumes layout space in the
    # reference (title glyph top to the first heading: 58pt on
    # the first body page); reserve it so following content
    # lands where the reference puts it.
    flowables << Flowables::Spacer.new(title_block_space) if start.title_template
    build_sequence_content(document, source, sequence, flowables)
    flowables << Flowables::PageBreak.new if sequence['page_break_after']
  end
  append_endnotes(document, flowables)
  flowables
end