Class: Arrolio::Engine::Paged
- Inherits:
-
Object
- Object
- Arrolio::Engine::Paged
- Defined in:
- lib/arrolio/engine/paged.rb
Overview
Two-pass page-flow driver.
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#flowables ⇒ Object
readonly
Returns the value of attribute flowables.
-
#layout_spec ⇒ Object
readonly
Returns the value of attribute layout_spec.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
Instance Method Summary collapse
-
#initialize(layout_spec:, flowables:) ⇒ Paged
constructor
A new instance of Paged.
- #layout ⇒ Object
Constructor Details
#initialize(layout_spec:, flowables:) ⇒ Paged
Returns a new instance of Paged.
9 10 11 12 13 |
# File 'lib/arrolio/engine/paged.rb', line 9 def initialize(layout_spec:, flowables:) @layout_spec = layout_spec @flowables = flowables @pages = [] end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
7 8 9 |
# File 'lib/arrolio/engine/paged.rb', line 7 def context @context end |
#flowables ⇒ Object (readonly)
Returns the value of attribute flowables.
7 8 9 |
# File 'lib/arrolio/engine/paged.rb', line 7 def flowables @flowables end |
#layout_spec ⇒ Object (readonly)
Returns the value of attribute layout_spec.
7 8 9 |
# File 'lib/arrolio/engine/paged.rb', line 7 def layout_spec @layout_spec end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
7 8 9 |
# File 'lib/arrolio/engine/paged.rb', line 7 def pages @pages end |
Instance Method Details
#layout ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/arrolio/engine/paged.rb', line 15 def layout @pages = [] @page_count_opened = 0 @footnote_page_map = {} @prev_space_after = 0.0 context = FlowContext.new(layout_spec: @layout_spec, page_number: 1) pending = @flowables.dup page_state = open_page(context) until pending.empty? flowable = pending.shift if flowable.is_a?(Flowables::PageSequenceStart) @current_role = flowable.role @current_header = flowable.header_template @current_footer = flowable. @current_header_align = flowable.header_align @current_footer_align = flowable. unless page_state.fresh && page_state.body_boxes.empty? page_state = open_page(context) end page_state.role = @current_role page_state.header = @current_header page_state. = @current_footer page_state.header_align = @current_header_align page_state. = @current_footer_align page_state.title_template = flowable.title_template @title_template = nil @prev_space_after = 0.0 next end if flowable.is_a?(Flowables::PageBreak) page_state = open_page(context) @prev_space_after = 0.0 next end if flowable.is_a?(Flowables::FootnoteMarkerFlowable) key = flowable.footnote.id || flowable.footnote.marker @footnote_page_map[key] ||= page_state.page_number page_state.footnotes << flowable.footnote unless page_state.footnotes.include?(flowable.footnote) next end page_state = open_page(context) if flowable.page_break_before? && @pages.any? && !page_state.fresh if page_state.frame.full? page_state = open_page(context) @prev_space_after = 0.0 end page_state.frame.width page_state = whole_move_page(flowable, page_state, context) page_state = keep_with_next_page(flowable, pending, page_state, context) if flowable.is_a?(Flowables::HeadingFlowable) context.record_heading(number: flowable.number, title: flowable.title, level: flowable.level, page_number: page_state.page_number, id: flowable.id) end page_state.fresh = false page_state = place(page_state, flowable, context, pending) end @context = context context.page_count = @pages.length finalize_pages @pages end |