thinreports 0.9.1 → 0.10.0

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