thinreports 0.9.1 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +41 -0
- data/.travis.yml +4 -6
- data/CHANGELOG.md +21 -2
- data/Gemfile +2 -4
- data/README.md +4 -5
- data/Rakefile +7 -8
- data/examples/character_spacing/character_spacing.rb +1 -1
- data/examples/dynamic_image/dynamic_image.rb +3 -3
- data/examples/dynamic_style/dynamic_style.rb +1 -1
- data/examples/eudc/eudc.rb +1 -1
- data/examples/helper.rb +2 -2
- data/examples/hidden_shapes/hidden_shapes.rb +1 -1
- data/examples/list_events/list_events.rb +1 -1
- data/examples/list_manual_generation/list_manual_generation.rb +1 -1
- data/examples/list_page_number/list_page_number.rb +1 -1
- data/examples/page_number/page_number.rb +1 -1
- data/examples/palleted_png/palleted_png.rb +1 -3
- data/examples/password_setting/password_setting.rb +1 -1
- data/examples/report_callbacks/report_callbacks.rb +1 -1
- data/examples/single_line_tblock/single_line_tblock.rb +1 -1
- data/examples/tblock_overflow/tblock_overflow.rb +1 -1
- data/examples/tblock_styles/tblock_styles.rb +1 -1
- data/examples/text_align/text_align.rb +1 -1
- data/examples/typeB_page_size/typeB_page_size.rb +1 -1
- data/examples/word_wrap/word_wrap.rb +1 -1
- data/lib/thinreports.rb +16 -15
- data/lib/thinreports/config.rb +2 -24
- data/lib/thinreports/core/errors.rb +6 -17
- data/lib/thinreports/core/format/base.rb +62 -61
- data/lib/thinreports/core/shape.rb +13 -14
- data/lib/thinreports/core/shape/base.rb +3 -12
- data/lib/thinreports/core/shape/base/interface.rb +35 -32
- data/lib/thinreports/core/shape/base/internal.rb +45 -43
- data/lib/thinreports/core/shape/basic.rb +12 -12
- data/lib/thinreports/core/shape/basic/block_format.rb +8 -6
- data/lib/thinreports/core/shape/basic/block_interface.rb +24 -22
- data/lib/thinreports/core/shape/basic/block_internal.rb +28 -26
- data/lib/thinreports/core/shape/basic/format.rb +11 -9
- data/lib/thinreports/core/shape/basic/interface.rb +79 -77
- data/lib/thinreports/core/shape/basic/internal.rb +17 -14
- data/lib/thinreports/core/shape/image_block.rb +9 -9
- data/lib/thinreports/core/shape/image_block/format.rb +7 -5
- data/lib/thinreports/core/shape/image_block/interface.rb +15 -13
- data/lib/thinreports/core/shape/image_block/internal.rb +10 -8
- data/lib/thinreports/core/shape/list.rb +13 -13
- data/lib/thinreports/core/shape/list/format.rb +83 -77
- data/lib/thinreports/core/shape/list/manager.rb +182 -176
- data/lib/thinreports/core/shape/list/page.rb +94 -93
- data/lib/thinreports/core/shape/list/page_state.rb +42 -40
- data/lib/thinreports/core/shape/list/section_format.rb +28 -26
- data/lib/thinreports/core/shape/list/section_interface.rb +42 -40
- data/lib/thinreports/core/shape/list/section_internal.rb +21 -19
- data/lib/thinreports/core/shape/manager.rb +4 -13
- data/lib/thinreports/core/shape/manager/format.rb +21 -19
- data/lib/thinreports/core/shape/manager/internal.rb +88 -84
- data/lib/thinreports/core/shape/manager/target.rb +93 -95
- data/lib/thinreports/core/shape/page_number.rb +9 -9
- data/lib/thinreports/core/shape/page_number/format.rb +20 -18
- data/lib/thinreports/core/shape/page_number/interface.rb +20 -18
- data/lib/thinreports/core/shape/page_number/internal.rb +47 -44
- data/lib/thinreports/core/shape/style.rb +5 -14
- data/lib/thinreports/core/shape/style/base.rb +121 -120
- data/lib/thinreports/core/shape/style/basic.rb +12 -10
- data/lib/thinreports/core/shape/style/graphic.rb +35 -33
- data/lib/thinreports/core/shape/style/text.rb +113 -107
- data/lib/thinreports/core/shape/text.rb +9 -9
- data/lib/thinreports/core/shape/text/format.rb +10 -9
- data/lib/thinreports/core/shape/text/interface.rb +13 -11
- data/lib/thinreports/core/shape/text/internal.rb +14 -12
- data/lib/thinreports/core/shape/text_block.rb +10 -10
- data/lib/thinreports/core/shape/text_block/format.rb +35 -33
- data/lib/thinreports/core/shape/text_block/formatter.rb +26 -24
- data/lib/thinreports/core/shape/text_block/formatter/basic.rb +25 -25
- data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +15 -12
- data/lib/thinreports/core/shape/text_block/formatter/number.rb +45 -39
- data/lib/thinreports/core/shape/text_block/formatter/padding.rb +17 -14
- data/lib/thinreports/core/shape/text_block/interface.rb +25 -23
- data/lib/thinreports/core/shape/text_block/internal.rb +68 -68
- data/lib/thinreports/core/utils.rb +4 -3
- data/lib/thinreports/generator/pdf.rb +24 -25
- data/lib/thinreports/generator/pdf/document.rb +109 -110
- data/lib/thinreports/generator/pdf/document/draw_shape.rb +58 -51
- data/lib/thinreports/generator/pdf/document/draw_template_items.rb +51 -47
- data/lib/thinreports/generator/pdf/document/font.rb +62 -59
- data/lib/thinreports/generator/pdf/document/graphics.rb +32 -33
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +122 -121
- data/lib/thinreports/generator/pdf/document/graphics/basic.rb +113 -114
- data/lib/thinreports/generator/pdf/document/graphics/image.rb +58 -150
- data/lib/thinreports/generator/pdf/document/graphics/text.rb +152 -137
- data/lib/thinreports/generator/pdf/document/page.rb +63 -64
- data/lib/thinreports/generator/pdf/document/parse_color.rb +37 -37
- data/lib/thinreports/generator/pdf/drawer/base.rb +41 -41
- data/lib/thinreports/generator/pdf/drawer/list.rb +48 -45
- data/lib/thinreports/generator/pdf/drawer/list_section.rb +42 -40
- data/lib/thinreports/generator/pdf/drawer/page.rb +101 -96
- data/lib/thinreports/generator/pdf/prawn_ext.rb +4 -30
- data/lib/thinreports/generator/pdf/prawn_ext/calc_image_dimensions.rb +34 -0
- data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +29 -0
- data/lib/thinreports/layout.rb +5 -7
- data/lib/thinreports/layout/base.rb +5 -7
- data/lib/thinreports/layout/format.rb +18 -13
- data/lib/thinreports/layout/legacy_schema.rb +18 -10
- data/lib/thinreports/layout/version.rb +22 -25
- data/lib/thinreports/report.rb +4 -6
- data/lib/thinreports/report/base.rb +24 -51
- data/lib/thinreports/report/internal.rb +9 -11
- data/lib/thinreports/report/page.rb +5 -6
- data/lib/thinreports/version.rb +2 -2
- data/test/schema_helper.rb +4 -3
- data/test/test_helper.rb +9 -3
- data/test/unit/core/format/test_base.rb +1 -1
- data/test/unit/core/shape/base/test_internal.rb +1 -1
- data/test/unit/core/shape/basic/test_block_format.rb +1 -1
- data/test/unit/core/shape/basic/test_block_interface.rb +1 -1
- data/test/unit/core/shape/basic/test_block_internal.rb +1 -1
- data/test/unit/core/shape/basic/test_format.rb +1 -1
- data/test/unit/core/shape/basic/test_interface.rb +1 -1
- data/test/unit/core/shape/basic/test_internal.rb +1 -1
- data/test/unit/core/shape/image_block/test_interface.rb +1 -1
- data/test/unit/core/shape/image_block/test_internal.rb +1 -1
- data/test/unit/core/shape/list/test_format.rb +1 -1
- data/test/unit/core/shape/list/test_manager.rb +4 -4
- data/test/unit/core/shape/list/test_page.rb +1 -1
- data/test/unit/core/shape/list/test_page_state.rb +1 -1
- data/test/unit/core/shape/list/test_section_format.rb +1 -1
- data/test/unit/core/shape/list/test_section_interface.rb +2 -2
- data/test/unit/core/shape/list/test_section_internal.rb +1 -1
- data/test/unit/core/shape/manager/test_format.rb +2 -2
- data/test/unit/core/shape/manager/test_internal.rb +3 -3
- data/test/unit/core/shape/manager/test_target.rb +1 -1
- data/test/unit/core/shape/page_number/test_format.rb +1 -1
- data/test/unit/core/shape/page_number/test_interface.rb +1 -1
- data/test/unit/core/shape/page_number/test_internal.rb +1 -1
- data/test/unit/core/shape/styles/test_base.rb +1 -1
- data/test/unit/core/shape/styles/test_basic.rb +1 -1
- data/test/unit/core/shape/styles/test_graphic.rb +1 -1
- data/test/unit/core/shape/styles/test_text.rb +1 -1
- data/test/unit/core/shape/text/test_format.rb +1 -1
- data/test/unit/core/shape/text/test_internal.rb +1 -1
- data/test/unit/core/shape/text_block/formatter/test_basic.rb +1 -1
- data/test/unit/core/shape/text_block/formatter/test_datetime.rb +1 -1
- data/test/unit/core/shape/text_block/formatter/test_number.rb +1 -1
- data/test/unit/core/shape/text_block/formatter/test_padding.rb +2 -2
- data/test/unit/core/shape/text_block/test_format.rb +1 -1
- data/test/unit/core/shape/text_block/test_formatter.rb +1 -1
- data/test/unit/core/shape/text_block/test_interface.rb +1 -1
- data/test/unit/core/shape/text_block/test_internal.rb +3 -3
- data/test/unit/core/test_shape.rb +1 -1
- data/test/unit/core/test_utils.rb +2 -2
- data/test/unit/generator/pdf/document/graphics/test_attributes.rb +1 -1
- data/test/unit/generator/pdf/document/graphics/test_basic.rb +2 -1
- data/test/unit/generator/pdf/document/graphics/test_image.rb +27 -131
- data/test/unit/generator/pdf/document/graphics/test_text.rb +1 -1
- data/test/unit/generator/pdf/document/test_font.rb +2 -2
- data/test/unit/generator/pdf/document/test_graphics.rb +1 -1
- data/test/unit/generator/pdf/document/test_page.rb +7 -7
- data/test/unit/generator/pdf/document/test_parse_color.rb +1 -1
- data/test/unit/generator/pdf/prawn_ext/test_calc_image_dimensions.rb +41 -0
- data/test/unit/generator/pdf/prawn_ext/test_width_of.rb +22 -0
- data/test/unit/generator/pdf/test_document.rb +8 -6
- data/test/unit/generator/test_pdf.rb +12 -10
- data/test/unit/layout/test_base.rb +1 -1
- data/test/unit/layout/test_format.rb +2 -2
- data/test/unit/layout/test_legacy_schema.rb +4 -4
- data/test/unit/layout/test_version.rb +11 -80
- data/test/unit/report/test_base.rb +45 -59
- data/test/unit/report/test_internal.rb +1 -1
- data/test/unit/test_config.rb +1 -16
- data/test/unit/test_layout.rb +1 -1
- data/test/unit/test_report.rb +1 -1
- data/thinreports.gemspec +11 -14
- metadata +42 -103
- data/lib/thinreports/generator.rb +0 -29
- data/lib/thinreports/generator/base.rb +0 -40
- data/lib/thinreports/generator/configuration.rb +0 -31
- data/lib/thinreports/report/events.rb +0 -32
- data/test/unit/generator/test_base.rb +0 -40
- data/test/unit/generator/test_configuration.rb +0 -21
@@ -1,226 +1,232 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
|
-
module Core
|
4
|
+
module Core
|
5
|
+
module Shape
|
6
|
+
module List
|
7
|
+
# rubocop:disable Metrics/ClassLength
|
8
|
+
class Manager
|
9
|
+
include Utils
|
5
10
|
|
6
|
-
|
7
|
-
|
11
|
+
# @return [Thinreports::Core::Shape:::List::Page]
|
12
|
+
attr_reader :current_page
|
8
13
|
|
9
|
-
|
10
|
-
|
14
|
+
# @return [Thinreports::Core::Shape::List::PageState]
|
15
|
+
attr_reader :current_page_state
|
11
16
|
|
12
|
-
|
13
|
-
|
17
|
+
# @return [Integer]
|
18
|
+
attr_accessor :page_count
|
14
19
|
|
15
|
-
|
16
|
-
|
20
|
+
# @return [Proc]
|
21
|
+
attr_accessor :page_finalize_handler
|
17
22
|
|
18
|
-
|
19
|
-
|
23
|
+
# @return [Proc]
|
24
|
+
attr_accessor :page_footer_handler
|
20
25
|
|
21
|
-
|
22
|
-
|
26
|
+
# @return [Proc]
|
27
|
+
attr_accessor :footer_handler
|
23
28
|
|
24
|
-
|
25
|
-
|
29
|
+
# @param [Thinreports::Core::Shape::List::Page] page
|
30
|
+
def initialize(page)
|
31
|
+
switch_current!(page)
|
26
32
|
|
27
|
-
|
28
|
-
|
29
|
-
switch_current!(page)
|
33
|
+
@finalized = false
|
34
|
+
@page_count = 0
|
30
35
|
|
31
|
-
|
32
|
-
|
36
|
+
@page_finalize_handler = nil
|
37
|
+
@page_footer_handler = nil
|
38
|
+
@footer_handler = nil
|
39
|
+
end
|
33
40
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
41
|
+
# @param [Thinreports::Core::Shape::List::Page] page
|
42
|
+
# @return [Thinreports::Core::Shape::List::Manager]
|
43
|
+
def switch_current!(page)
|
44
|
+
@current_page = page
|
45
|
+
@current_page_state = page.internal
|
46
|
+
self
|
47
|
+
end
|
38
48
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
self
|
45
|
-
end
|
49
|
+
# @yield [new_list]
|
50
|
+
# @yieldparam [Thinreports::Core::Shape::List::Page] new_list
|
51
|
+
def change_new_page(&block)
|
52
|
+
finalize_page
|
53
|
+
new_page = report.internal.copy_page
|
46
54
|
|
47
|
-
|
48
|
-
|
49
|
-
def change_new_page(&block)
|
50
|
-
finalize_page
|
51
|
-
new_page = report.internal.copy_page
|
55
|
+
block.call(new_page.list(current_page.id)) if block_given?
|
56
|
+
end
|
52
57
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
58
|
+
# @param [Hash] values ({})
|
59
|
+
# @yield [header]
|
60
|
+
# @yieldparam [Thinreports::Core::Shape::List::SectionInterface] header
|
61
|
+
# @return [Thinreports::Core::Shape::List::SectionInterface]
|
62
|
+
# @raise [Thinreports::Errors::DisabledListSection]
|
63
|
+
def build_header(values = {}, &block)
|
64
|
+
raise Thinreports::Errors::DisabledListSection, 'header' unless format.has_header?
|
57
65
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
# @return [Thinreports::Core::Shape::List::SectionInterface]
|
62
|
-
# @raise [Thinreports::Errors::DisabledListSection]
|
63
|
-
def build_header(values = {}, &block)
|
64
|
-
unless format.has_header?
|
65
|
-
raise Thinreports::Errors::DisabledListSection.new('header')
|
66
|
-
end
|
67
|
-
current_page_state.header ||= init_section(:header)
|
68
|
-
build_section(header_section, values, &block)
|
69
|
-
end
|
66
|
+
current_page_state.header ||= init_section(:header)
|
67
|
+
build_section(header_section, values, &block)
|
68
|
+
end
|
70
69
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
70
|
+
# @return [Thinreports::Core::Shape::List::SectionInterface]
|
71
|
+
def header_section
|
72
|
+
current_page_state.header
|
73
|
+
end
|
75
74
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
75
|
+
# @param (see #build_section)
|
76
|
+
# @return [Boolean]
|
77
|
+
def add_detail(values = {}, &block)
|
78
|
+
return false if current_page_state.finalized?
|
79
|
+
|
80
|
+
successful = true
|
81
|
+
|
82
|
+
if overflow_with?(:detail)
|
83
|
+
if auto_page_break?
|
84
|
+
change_new_page do |new_list|
|
85
|
+
new_list.manager.insert_detail(values, &block)
|
86
|
+
end
|
87
|
+
else
|
88
|
+
finalize
|
89
|
+
successful = false
|
90
|
+
end
|
91
|
+
else
|
92
|
+
insert_detail(values, &block)
|
93
|
+
end
|
94
|
+
successful
|
95
|
+
end
|
80
96
|
|
81
|
-
|
97
|
+
# @param values (see Thinreports::Core::Shape::Manager::Target#values)
|
98
|
+
# @yield [section,]
|
99
|
+
# @yieldparam [Thinreports::Core::Shape::List::SectionInterface] section
|
100
|
+
# @return [Thinreports::Core::Shape::List::SectionInterface]
|
101
|
+
def insert_detail(values = {}, &block)
|
102
|
+
detail = build_section(init_section(:detail), values, &block)
|
103
|
+
insert_row(detail)
|
104
|
+
end
|
82
105
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
106
|
+
# @param [Thinreports::Core::Shape::List::SectionInterface] row
|
107
|
+
# @return [Thinreports::Core::Shape::List::SectionInterface]
|
108
|
+
def insert_row(row)
|
109
|
+
row.internal.move_top_to(current_page_state.height)
|
110
|
+
|
111
|
+
current_page_state.rows << row
|
112
|
+
current_page_state.height += row.height
|
113
|
+
row
|
91
114
|
end
|
92
|
-
else
|
93
|
-
insert_detail(values, &block)
|
94
|
-
end
|
95
|
-
successful
|
96
|
-
end
|
97
115
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
116
|
+
# @param [Thinreports::Core::Shape::List::SectionInterface] section
|
117
|
+
# @param values (see Thinreports::Core::Shape::Manager::Target#values)
|
118
|
+
# @yield [section,]
|
119
|
+
# @yieldparam [Thinreports::Core::Shape::List::SectionInterface] section
|
120
|
+
# @return [Thinreports::Core::Shape::List::SectionInterface]
|
121
|
+
def build_section(section, values = {}, &block)
|
122
|
+
section.values(values)
|
123
|
+
call_block_in(section, &block)
|
124
|
+
end
|
106
125
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
126
|
+
# @param [Symbol] section_name
|
127
|
+
# @return [Thinreports::Core::Shape::List::SectionInterface]
|
128
|
+
def init_section(section_name)
|
129
|
+
List::SectionInterface.new(current_page,
|
130
|
+
format.sections[section_name],
|
131
|
+
section_name)
|
132
|
+
end
|
111
133
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
134
|
+
# @param [Symbol] section_name
|
135
|
+
# @return [Boolean]
|
136
|
+
def overflow_with?(section_name = :detail)
|
137
|
+
max_height = page_max_height
|
116
138
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
# @yieldparam [Thinreports::Core::Shape::List::SectionInterface] section
|
121
|
-
# @return [Thinreports::Core::Shape::List::SectionInterface]
|
122
|
-
def build_section(section, values = {}, &block)
|
123
|
-
section.values(values)
|
124
|
-
call_block_in(section, &block)
|
125
|
-
end
|
139
|
+
if section_name == :footer && format.has_page_footer?
|
140
|
+
max_height += format.section_height(:page_footer)
|
141
|
+
end
|
126
142
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
List::SectionInterface.new(current_page,
|
131
|
-
format.sections[section_name],
|
132
|
-
section_name)
|
133
|
-
end
|
143
|
+
height = format.section_height(section_name)
|
144
|
+
(current_page_state.height + height) > max_height
|
145
|
+
end
|
134
146
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
147
|
+
# @return [Numeric]
|
148
|
+
def page_max_height
|
149
|
+
@page_max_height ||= begin
|
150
|
+
h = format.height
|
151
|
+
h -= format.section_height(:page_footer)
|
152
|
+
h -= format.section_height(:footer) unless auto_page_break?
|
153
|
+
h
|
154
|
+
end
|
155
|
+
end
|
139
156
|
|
140
|
-
|
141
|
-
|
142
|
-
|
157
|
+
# @return [Boolean]
|
158
|
+
def auto_page_break?
|
159
|
+
format.auto_page_break?
|
160
|
+
end
|
143
161
|
|
144
|
-
|
145
|
-
|
146
|
-
|
162
|
+
# @param [Hash] options
|
163
|
+
# @option options [Boolean] :ignore_page_footer (false)
|
164
|
+
# When the switch of the page is generated by #finalize, it is used.
|
165
|
+
def finalize_page(options = {})
|
166
|
+
return if current_page_state.finalized?
|
147
167
|
|
148
|
-
|
149
|
-
def page_max_height
|
150
|
-
@page_max_height ||= begin
|
151
|
-
h = format.height
|
152
|
-
h -= format.section_height(:page_footer)
|
153
|
-
h -= format.section_height(:footer) unless auto_page_break?
|
154
|
-
h
|
155
|
-
end
|
156
|
-
end
|
168
|
+
build_header if format.has_header?
|
157
169
|
|
158
|
-
|
159
|
-
def auto_page_break?
|
160
|
-
format.auto_page_break?
|
161
|
-
end
|
170
|
+
finalize_page_footer unless options[:ignore_page_footer]
|
162
171
|
|
163
|
-
|
164
|
-
|
165
|
-
# When the switch of the page is generated by #finalize, it is used.
|
166
|
-
def finalize_page(options = {})
|
167
|
-
return if current_page_state.finalized?
|
172
|
+
current_page_state.finalized!
|
173
|
+
@page_finalize_handler.call if @page_finalize_handler
|
168
174
|
|
169
|
-
|
175
|
+
@page_count += 1
|
176
|
+
current_page_state.no = @page_count
|
177
|
+
end
|
170
178
|
|
171
|
-
|
172
|
-
|
173
|
-
@page_footer_handler.call(page_footer) if @page_footer_handler
|
174
|
-
end
|
179
|
+
def finalize_page_footer
|
180
|
+
return unless format.has_page_footer?
|
175
181
|
|
176
|
-
|
177
|
-
|
182
|
+
page_footer = init_section(:page_footer)
|
183
|
+
insert_row(page_footer)
|
178
184
|
|
179
|
-
|
180
|
-
|
181
|
-
end
|
185
|
+
@page_footer_handler.call(page_footer) if @page_footer_handler
|
186
|
+
end
|
182
187
|
|
183
|
-
|
184
|
-
|
185
|
-
|
188
|
+
def finalize
|
189
|
+
return if finalized?
|
190
|
+
finalize_page
|
186
191
|
|
187
|
-
|
188
|
-
|
192
|
+
if format.has_footer?
|
193
|
+
footer = init_section(:footer)
|
189
194
|
|
190
|
-
|
195
|
+
@footer_handler.call(footer) if @footer_handler
|
191
196
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
197
|
+
if auto_page_break? && overflow_with?(:footer)
|
198
|
+
change_new_page do |new_list|
|
199
|
+
new_list.manager.insert_row(footer)
|
200
|
+
new_list.manager.finalize_page(ignore_page_footer: true)
|
201
|
+
end
|
202
|
+
else
|
203
|
+
insert_row(footer)
|
204
|
+
end
|
196
205
|
end
|
197
|
-
|
198
|
-
insert_row(footer)
|
206
|
+
@finalized = true
|
199
207
|
end
|
200
|
-
end
|
201
|
-
@finalized = true
|
202
|
-
end
|
203
208
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
209
|
+
# @return [Boolean]
|
210
|
+
def finalized?
|
211
|
+
@finalized
|
212
|
+
end
|
208
213
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
214
|
+
# @return [Thinreports::Report::Base]
|
215
|
+
def report
|
216
|
+
current_page_state.parent.report
|
217
|
+
end
|
213
218
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
219
|
+
# @return [Thinreports::Layout::Base]
|
220
|
+
def layout
|
221
|
+
current_page_state.parent.layout
|
222
|
+
end
|
218
223
|
|
219
|
-
|
220
|
-
|
221
|
-
|
224
|
+
# @return [Thinreports::Core::Shape::List::Format]
|
225
|
+
def format
|
226
|
+
current_page_state.format
|
227
|
+
end
|
228
|
+
end
|
222
229
|
end
|
223
230
|
end
|
224
|
-
|
225
231
|
end
|
226
232
|
end
|
@@ -1,112 +1,113 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
|
-
module Core
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
4
|
+
module Core
|
5
|
+
module Shape
|
6
|
+
module List
|
7
|
+
class Page < Basic::Interface
|
8
|
+
extend Forwardable
|
9
|
+
|
10
|
+
attr_reader :manager
|
11
|
+
|
12
|
+
# @param [Thinreports::Report::Page] parent
|
13
|
+
# @param [Thinreports::Core::Shape::Basic::Format] format
|
14
|
+
# @param [Thinreports::Core::Shape::List::PageState] internal (nil)
|
15
|
+
# @param [Thinreports::Core::Shape::List::Manager] manager (nil)
|
16
|
+
def initialize(parent, format, internal = nil, manager = nil)
|
17
|
+
super(parent, format, internal)
|
18
|
+
|
19
|
+
@manager =
|
20
|
+
if manager
|
21
|
+
manager.switch_current!(self)
|
22
|
+
else
|
23
|
+
List::Manager.new(self)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Set a reference to List::PageState List::Manager
|
27
|
+
self.internal.manager = self.manager
|
21
28
|
end
|
22
29
|
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
# @see Thinreports::Core::Shape::List::Manager#build_header
|
28
|
-
def_delegator :manager, :build_header, :header
|
29
|
-
|
30
|
-
def on_page_finalize(&block)
|
31
|
-
manager.page_finalize_handler = block
|
32
|
-
end
|
30
|
+
# @see Thinreports::Core::Shape::List::Manager#build_header
|
31
|
+
def_delegator :manager, :build_header, :header
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
manager.page_footer_handler = block
|
38
|
-
end
|
33
|
+
def on_page_finalize(&block)
|
34
|
+
manager.page_finalize_handler = block
|
35
|
+
end
|
39
36
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
37
|
+
# @yield [page_footer]
|
38
|
+
# @yieldparam [Thinreports::Core::Shape::List::SectionInterface] page_footer
|
39
|
+
def on_page_footer_insert(&block)
|
40
|
+
manager.page_footer_handler = block
|
41
|
+
end
|
46
42
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
43
|
+
# @yield [footer]
|
44
|
+
# @yieldparam [Thinreports::Core::Shape::List::SectionInterface] footer
|
45
|
+
# @return [Thinreports::Core::Shape::List::SectionInterface]
|
46
|
+
def on_footer_insert(&block)
|
47
|
+
manager.footer_handler = block
|
48
|
+
end
|
54
49
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
63
|
-
end
|
64
|
-
alias_method :finalize, :page_break
|
50
|
+
# @param [Hash] values ({})
|
51
|
+
# @yield [row,]
|
52
|
+
# @yieldparam [Thinreports::Core::Shape::List::SectionInterface] row
|
53
|
+
# @return [Boolean]
|
54
|
+
def add_row(values = {}, &block)
|
55
|
+
manager.add_detail(values, &block)
|
56
|
+
end
|
65
57
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
58
|
+
# If enabled, the auto-page-break of the list will force a page break
|
59
|
+
# at the time this method is called. Otherwise, this list will be finalized.
|
60
|
+
def page_break
|
61
|
+
if manager.auto_page_break?
|
62
|
+
manager.change_new_page
|
63
|
+
else
|
64
|
+
manager.finalize_page
|
65
|
+
end
|
66
|
+
end
|
67
|
+
alias finalize page_break
|
71
68
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
new_list = self.class.new(new_parent, internal.format,
|
77
|
-
nil, manager)
|
78
|
-
else
|
79
|
-
manager.finalize
|
80
|
-
|
81
|
-
new_list = self.class.new(new_parent, internal.format,
|
82
|
-
internal.copy(new_parent), manager)
|
83
|
-
internal.rows.each do |row|
|
84
|
-
new_list.internal.rows << row.copy(new_list)
|
69
|
+
# @return [Boolean] Returns true if list has overflowed
|
70
|
+
# when `list#add_row` is called at the next time.
|
71
|
+
def overflow?
|
72
|
+
manager.overflow_with?(:detail)
|
85
73
|
end
|
86
|
-
new_list.finalized!
|
87
|
-
end
|
88
74
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
75
|
+
# @param [Thinreports::Report::Page] new_parent
|
76
|
+
# @return [Thinreports::Core::Shape::List::Page]
|
77
|
+
# rubocop:disable Metrics/AbcSize
|
78
|
+
def copy(new_parent)
|
79
|
+
if manager.auto_page_break?
|
80
|
+
new_list = self.class.new(new_parent, internal.format,
|
81
|
+
nil, manager)
|
82
|
+
else
|
83
|
+
manager.finalize
|
84
|
+
|
85
|
+
new_list = self.class.new(new_parent, internal.format,
|
86
|
+
internal.copy(new_parent), manager)
|
87
|
+
internal.rows.each do |row|
|
88
|
+
new_list.internal.rows << row.copy(new_list)
|
89
|
+
end
|
90
|
+
new_list.finalized!
|
91
|
+
end
|
92
|
+
|
93
|
+
if internal.format.has_header?
|
94
|
+
new_list.internal.header = internal.header.copy(new_list)
|
95
|
+
end
|
96
|
+
new_list
|
97
|
+
end
|
94
98
|
|
95
|
-
|
96
|
-
@manager
|
97
|
-
end
|
99
|
+
private
|
98
100
|
|
99
|
-
|
101
|
+
# @see Thinreports::Core::Shape::Base::Interface#init_internal
|
102
|
+
def init_internal(parent, format)
|
103
|
+
List::PageState.new(parent, format)
|
104
|
+
end
|
105
|
+
end
|
100
106
|
|
101
|
-
|
102
|
-
|
103
|
-
List::
|
107
|
+
# Alias to List::Page.
|
108
|
+
# @see Thinreports::Core::Shape::List::Page
|
109
|
+
List::Interface = List::Page
|
104
110
|
end
|
105
111
|
end
|
106
|
-
|
107
|
-
# Alias to List::Page.
|
108
|
-
# @see Thinreports::Core::Shape::List::Page
|
109
|
-
List::Interface = List::Page
|
110
|
-
|
111
112
|
end
|
112
113
|
end
|