Class: Arrolio::GenericFlowBuilder
- Inherits:
-
Object
- Object
- Arrolio::GenericFlowBuilder
- Defined in:
- lib/arrolio/generic_flow_builder.rb
Instance Attribute Summary collapse
-
#asset_resolver ⇒ Object
readonly
Returns the value of attribute asset_resolver.
-
#layout_spec ⇒ Object
readonly
Returns the value of attribute layout_spec.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
- #append_endnotes(document, flowables) ⇒ Object
-
#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. - #build(document) ⇒ Object
-
#initialize(layout_spec:, rules:, asset_resolver: nil) ⇒ GenericFlowBuilder
constructor
A new instance of GenericFlowBuilder.
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_resolver ⇒ Object (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_spec ⇒ Object (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 |
#rules ⇒ Object (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 |