thinreports 0.7.7 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (280) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -6
  3. data/.travis.yml +4 -10
  4. data/CHANGELOG.md +220 -0
  5. data/Gemfile +3 -3
  6. data/MIT-LICENSE +1 -1
  7. data/README.md +286 -0
  8. data/Rakefile +38 -8
  9. data/examples/character_spacing/character_spacing.rb +8 -0
  10. data/examples/character_spacing/character_spacing.tlf +1 -0
  11. data/examples/dynamic_image/dynamic_image.rb +31 -0
  12. data/examples/dynamic_image/dynamic_image.tlf +1 -0
  13. data/{test/case → examples}/dynamic_image/img200x100.png +0 -0
  14. data/{test/case → examples}/dynamic_image/img50x50.png +0 -0
  15. data/examples/dynamic_style/dynamic_style.rb +150 -0
  16. data/examples/dynamic_style/dynamic_style.tlf +1 -0
  17. data/examples/dynamic_style/dynamic_style_in_list.tlf +1 -0
  18. data/{test/case → examples}/dynamic_style/image.png +0 -0
  19. data/examples/eudc/eudc.rb +20 -0
  20. data/examples/eudc/eudc.tlf +1 -0
  21. data/{test/case → examples}/eudc/eudc.ttf +0 -0
  22. data/{test/case → examples}/helper.rb +14 -12
  23. data/examples/hidden_shapes/hidden_shapes.rb +9 -0
  24. data/examples/hidden_shapes/hidden_shapes.tlf +1 -0
  25. data/examples/list_events/list_events.rb +59 -0
  26. data/examples/list_events/list_events_0_7_7.tlf +1 -0
  27. data/examples/list_events/list_events_0_8.tlf +1 -0
  28. data/{test/case → examples}/list_manual_generation/list_manual_generation.rb +4 -4
  29. data/examples/list_manual_generation/list_manual_generation.tlf +1 -0
  30. data/{test/case → examples}/list_page_number/list_page_number.rb +3 -3
  31. data/examples/list_page_number/list_page_number.tlf +1 -0
  32. data/examples/page_number/page_number.rb +33 -0
  33. data/examples/page_number/page_number.tlf +1 -0
  34. data/examples/password_setting/password_setting.rb +10 -0
  35. data/examples/password_setting/password_setting.tlf +1 -0
  36. data/examples/report_callbacks/report_callbacks.rb +31 -0
  37. data/examples/report_callbacks/report_callbacks.tlf +1 -0
  38. data/{test/case → examples}/single_line_tblock/single_line_tblock.rb +2 -2
  39. data/examples/single_line_tblock/single_line_tblock.tlf +1 -0
  40. data/examples/tblock_overflow/tblock_overflow.rb +20 -0
  41. data/examples/tblock_overflow/tblock_overflow.tlf +1 -0
  42. data/examples/tblock_styles/font_size.tlf +1 -0
  43. data/examples/tblock_styles/tblock_styles.rb +43 -0
  44. data/examples/tblock_styles/tblock_styles.tlf +1 -0
  45. data/examples/text_align/text_align.rb +8 -0
  46. data/examples/text_align/text_align.tlf +1 -0
  47. data/examples/typeB_page_size/B4_ISO.tlf +1 -0
  48. data/examples/typeB_page_size/B4_JIS.tlf +1 -0
  49. data/{test/case → examples}/typeB_page_size/typeB_page_size.rb +3 -3
  50. data/examples/word_wrap/word_wrap.rb +26 -0
  51. data/examples/word_wrap/word_wrap.tlf +1 -0
  52. data/{resources/fonts → fonts}/IPA_Font_License_Agreement_v1.0.txt +0 -0
  53. data/{resources/fonts → fonts}/ipag.ttf +0 -0
  54. data/{resources/fonts → fonts}/ipagp.ttf +0 -0
  55. data/{resources/fonts → fonts}/ipam.ttf +0 -0
  56. data/{resources/fonts → fonts}/ipamp.ttf +0 -0
  57. data/lib/thinreports.rb +14 -2
  58. data/lib/thinreports/config.rb +30 -10
  59. data/lib/thinreports/core/errors.rb +23 -20
  60. data/lib/thinreports/core/events.rb +18 -19
  61. data/lib/thinreports/core/format/base.rb +20 -20
  62. data/lib/thinreports/core/format/builder.rb +14 -22
  63. data/lib/thinreports/core/shape.rb +9 -13
  64. data/lib/thinreports/core/shape/base.rb +4 -5
  65. data/lib/thinreports/core/shape/base/interface.rb +15 -15
  66. data/lib/thinreports/core/shape/base/internal.rb +15 -20
  67. data/lib/thinreports/core/shape/basic.rb +1 -1
  68. data/lib/thinreports/core/shape/basic/block_format.rb +3 -4
  69. data/lib/thinreports/core/shape/basic/block_interface.rb +9 -4
  70. data/lib/thinreports/core/shape/basic/block_internal.rb +9 -10
  71. data/lib/thinreports/core/shape/basic/format.rb +11 -10
  72. data/lib/thinreports/core/shape/basic/interface.rb +3 -3
  73. data/lib/thinreports/core/shape/basic/internal.rb +4 -5
  74. data/lib/thinreports/core/shape/image_block.rb +1 -1
  75. data/lib/thinreports/core/shape/image_block/format.rb +5 -6
  76. data/lib/thinreports/core/shape/image_block/interface.rb +9 -7
  77. data/lib/thinreports/core/shape/image_block/internal.rb +5 -6
  78. data/lib/thinreports/core/shape/list.rb +1 -1
  79. data/lib/thinreports/core/shape/list/configuration.rb +30 -15
  80. data/lib/thinreports/core/shape/list/events.rb +11 -11
  81. data/lib/thinreports/core/shape/list/format.rb +27 -28
  82. data/lib/thinreports/core/shape/list/manager.rb +128 -95
  83. data/lib/thinreports/core/shape/list/page.rb +54 -50
  84. data/lib/thinreports/core/shape/list/page_state.rb +15 -16
  85. data/lib/thinreports/core/shape/list/section_format.rb +14 -15
  86. data/lib/thinreports/core/shape/list/section_interface.rb +15 -16
  87. data/lib/thinreports/core/shape/list/section_internal.rb +7 -8
  88. data/lib/thinreports/core/shape/list/store.rb +10 -11
  89. data/lib/thinreports/core/shape/manager.rb +1 -1
  90. data/lib/thinreports/core/shape/manager/format.rb +10 -11
  91. data/lib/thinreports/core/shape/manager/internal.rb +21 -20
  92. data/lib/thinreports/core/shape/manager/target.rb +63 -34
  93. data/lib/thinreports/core/shape/page_number.rb +1 -1
  94. data/lib/thinreports/core/shape/page_number/format.rb +3 -3
  95. data/lib/thinreports/core/shape/page_number/interface.rb +2 -2
  96. data/lib/thinreports/core/shape/page_number/internal.rb +3 -3
  97. data/lib/thinreports/core/shape/style.rb +1 -1
  98. data/lib/thinreports/core/shape/style/base.rb +29 -29
  99. data/lib/thinreports/core/shape/style/basic.rb +1 -1
  100. data/lib/thinreports/core/shape/style/graphic.rb +10 -25
  101. data/lib/thinreports/core/shape/style/text.rb +36 -30
  102. data/lib/thinreports/core/shape/text.rb +1 -1
  103. data/lib/thinreports/core/shape/text/format.rb +8 -9
  104. data/lib/thinreports/core/shape/text/interface.rb +2 -2
  105. data/lib/thinreports/core/shape/text/internal.rb +6 -7
  106. data/lib/thinreports/core/shape/text_block.rb +1 -1
  107. data/lib/thinreports/core/shape/text_block/format.rb +17 -18
  108. data/lib/thinreports/core/shape/text_block/formatter.rb +7 -8
  109. data/lib/thinreports/core/shape/text_block/formatter/basic.rb +13 -12
  110. data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +8 -9
  111. data/lib/thinreports/core/shape/text_block/formatter/number.rb +11 -12
  112. data/lib/thinreports/core/shape/text_block/formatter/padding.rb +9 -32
  113. data/lib/thinreports/core/shape/text_block/interface.rb +2 -2
  114. data/lib/thinreports/core/shape/text_block/internal.rb +19 -20
  115. data/lib/thinreports/core/utils.rb +33 -32
  116. data/lib/thinreports/generator.rb +6 -8
  117. data/lib/thinreports/generator/base.rb +15 -24
  118. data/lib/thinreports/generator/configuration.rb +10 -9
  119. data/lib/thinreports/generator/pdf.rb +27 -30
  120. data/lib/thinreports/generator/pdf/configuration.rb +11 -6
  121. data/lib/thinreports/generator/pdf/document.rb +28 -28
  122. data/lib/thinreports/generator/pdf/document/draw_shape.rb +30 -31
  123. data/lib/thinreports/generator/pdf/document/font.rb +53 -44
  124. data/lib/thinreports/generator/pdf/document/graphics.rb +8 -9
  125. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +25 -25
  126. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +25 -25
  127. data/lib/thinreports/generator/pdf/document/graphics/image.rb +15 -15
  128. data/lib/thinreports/generator/pdf/document/graphics/text.rb +40 -41
  129. data/lib/thinreports/generator/pdf/document/page.rb +20 -21
  130. data/lib/thinreports/generator/pdf/document/parse_color.rb +9 -10
  131. data/lib/thinreports/generator/pdf/document/parse_svg.rb +14 -15
  132. data/lib/thinreports/generator/pdf/drawer/base.rb +13 -14
  133. data/lib/thinreports/generator/pdf/drawer/list.rb +13 -14
  134. data/lib/thinreports/generator/pdf/drawer/list_section.rb +13 -14
  135. data/lib/thinreports/generator/pdf/drawer/page.rb +16 -17
  136. data/lib/thinreports/generator/pdf/prawn_ext.rb +17 -33
  137. data/lib/thinreports/layout.rb +2 -2
  138. data/lib/thinreports/layout/base.rb +22 -36
  139. data/lib/thinreports/layout/configuration.rb +11 -9
  140. data/lib/thinreports/layout/format.rb +26 -27
  141. data/lib/thinreports/layout/version.rb +8 -9
  142. data/lib/thinreports/report.rb +10 -14
  143. data/lib/thinreports/report/base.rb +104 -126
  144. data/lib/thinreports/report/events.rb +5 -5
  145. data/lib/thinreports/report/internal.rb +41 -33
  146. data/lib/thinreports/{core → report}/page.rb +38 -30
  147. data/lib/thinreports/version.rb +2 -3
  148. data/test/data/font.ttf +0 -0
  149. data/test/data/layout_block.tlf +1 -0
  150. data/test/data/layout_list.tlf +1 -0
  151. data/test/data/layout_list_noheader.tlf +1 -0
  152. data/test/data/layout_text1.tlf +1 -0
  153. data/test/data/layout_text2.tlf +1 -0
  154. data/test/test_helper.rb +74 -0
  155. data/test/{unit/tmp → tmp}/.gitkeep +0 -0
  156. data/test/unit/core/format/test_base.rb +14 -14
  157. data/test/unit/core/format/test_builder.rb +19 -23
  158. data/test/unit/core/shape/base/test_internal.rb +34 -37
  159. data/test/unit/core/shape/basic/test_basic_format.rb +4 -4
  160. data/test/unit/core/shape/basic/test_basic_interface.rb +15 -13
  161. data/test/unit/core/shape/basic/test_basic_internal.rb +19 -16
  162. data/test/unit/core/shape/basic/test_format.rb +4 -4
  163. data/test/unit/core/shape/basic/test_interface.rb +36 -46
  164. data/test/unit/core/shape/basic/test_internal.rb +23 -20
  165. data/test/unit/core/shape/image_block/test_format.rb +5 -5
  166. data/test/unit/core/shape/image_block/test_interface.rb +17 -16
  167. data/test/unit/core/shape/image_block/test_internal.rb +19 -16
  168. data/test/unit/core/shape/list/test_configuration.rb +45 -33
  169. data/test/unit/core/shape/list/test_events.rb +7 -7
  170. data/test/unit/core/shape/list/test_format.rb +16 -18
  171. data/test/unit/core/shape/list/test_manager.rb +5 -5
  172. data/test/unit/core/shape/list/test_page.rb +80 -22
  173. data/test/unit/core/shape/list/test_page_state.rb +12 -12
  174. data/test/unit/core/shape/list/test_section_format.rb +16 -17
  175. data/test/unit/core/shape/list/test_section_interface.rb +30 -22
  176. data/test/unit/core/shape/list/test_section_internal.rb +21 -19
  177. data/test/unit/core/shape/list/test_store.rb +7 -7
  178. data/test/unit/core/shape/manager/test_format.rb +11 -15
  179. data/test/unit/core/shape/manager/test_internal.rb +9 -9
  180. data/test/unit/core/shape/manager/test_target.rb +85 -57
  181. data/test/unit/core/shape/page_number/test_format.rb +4 -4
  182. data/test/unit/core/shape/page_number/test_interface.rb +11 -8
  183. data/test/unit/core/shape/page_number/test_internal.rb +5 -5
  184. data/test/unit/core/shape/styles/test_base.rb +9 -9
  185. data/test/unit/core/shape/styles/test_basic.rb +5 -5
  186. data/test/unit/core/shape/styles/test_graphic.rb +19 -33
  187. data/test/unit/core/shape/styles/test_text.rb +18 -7
  188. data/test/unit/core/shape/text/test_format.rb +6 -6
  189. data/test/unit/core/shape/text/test_internal.rb +11 -12
  190. data/test/unit/core/shape/text_block/formatter/test_basic.rb +16 -16
  191. data/test/unit/core/shape/text_block/formatter/test_datetime.rb +4 -4
  192. data/test/unit/core/shape/text_block/formatter/test_number.rb +34 -34
  193. data/test/unit/core/shape/text_block/formatter/test_padding.rb +44 -44
  194. data/test/unit/core/shape/text_block/test_format.rb +8 -8
  195. data/test/unit/core/shape/text_block/test_formatter.rb +17 -17
  196. data/test/unit/core/shape/text_block/test_interface.rb +37 -20
  197. data/test/unit/core/shape/text_block/test_internal.rb +38 -38
  198. data/test/unit/core/test_events.rb +5 -5
  199. data/test/unit/core/test_shape.rb +6 -6
  200. data/test/unit/core/test_utils.rb +68 -0
  201. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +4 -4
  202. data/test/unit/generator/pdf/document/graphics/test_text.rb +60 -53
  203. data/test/unit/generator/pdf/document/test_draw_shape.rb +9 -7
  204. data/test/unit/generator/pdf/document/test_font.rb +79 -58
  205. data/test/unit/generator/pdf/document/test_graphics.rb +18 -19
  206. data/test/unit/generator/pdf/document/test_page.rb +44 -45
  207. data/test/unit/generator/pdf/document/test_parse_color.rb +5 -5
  208. data/test/unit/generator/pdf/test_configuration.rb +16 -9
  209. data/test/unit/generator/pdf/test_document.rb +8 -16
  210. data/test/unit/generator/test_base.rb +31 -42
  211. data/test/unit/generator/test_configuration.rb +6 -6
  212. data/test/unit/generator/test_pdf.rb +17 -14
  213. data/test/unit/layout/test_base.rb +34 -79
  214. data/test/unit/layout/test_configuration.rb +12 -37
  215. data/test/unit/layout/test_format.rb +36 -39
  216. data/test/unit/layout/test_version.rb +4 -4
  217. data/test/unit/report/test_base.rb +134 -213
  218. data/test/unit/report/test_events.rb +4 -4
  219. data/test/unit/report/test_internal.rb +84 -86
  220. data/test/unit/test_config.rb +31 -12
  221. data/test/unit/test_layout.rb +7 -7
  222. data/test/unit/test_report.rb +12 -24
  223. data/thinreports.gemspec +18 -22
  224. metadata +101 -200
  225. data/LICENSE +0 -1
  226. data/README.rdoc +0 -166
  227. data/doc/yardoc_templates/default/layout/html/footer.erb +0 -10
  228. data/lib/thinreports/core.rb +0 -20
  229. data/lib/thinreports/core/ext.rb +0 -5
  230. data/lib/thinreports/core/ext/array.rb +0 -19
  231. data/lib/thinreports/core/ext/hash.rb +0 -19
  232. data/lib/thinreports/core/ext/object.rb +0 -25
  233. data/lib/thinreports/core/format.rb +0 -14
  234. data/lib/thinreports/core/ordered_hash.rb +0 -39
  235. data/lib/thinreports/generator/pdf/drawer.rb +0 -16
  236. data/tasks/doc.rake +0 -12
  237. data/tasks/test.rake +0 -56
  238. data/test/benchmark/basic_estimate.tlf +0 -1
  239. data/test/benchmark/bench_basic_estimate.rb +0 -95
  240. data/test/case/character_spacing/character_spacing.rb +0 -8
  241. data/test/case/character_spacing/character_spacing.tlf +0 -1
  242. data/test/case/dynamic_image/dynamic_image.rb +0 -41
  243. data/test/case/dynamic_image/dynamic_image.tlf +0 -1
  244. data/test/case/dynamic_style/dynamic_style.rb +0 -154
  245. data/test/case/dynamic_style/dynamic_style.tlf +0 -1
  246. data/test/case/dynamic_style/dynamic_style_in_list.tlf +0 -1
  247. data/test/case/eudc/eudc.rb +0 -20
  248. data/test/case/eudc/eudc.tlf +0 -1
  249. data/test/case/hidden_shapes/hidden_shapes.rb +0 -9
  250. data/test/case/hidden_shapes/hidden_shapes.tlf +0 -1
  251. data/test/case/list_events/list_events.rb +0 -32
  252. data/test/case/list_events/list_events.tlf +0 -1
  253. data/test/case/list_manual_generation/list_manual_generation.tlf +0 -1
  254. data/test/case/list_page_number/list_page_number.tlf +0 -1
  255. data/test/case/page_number/page_number.rb +0 -33
  256. data/test/case/page_number/page_number.tlf +0 -1
  257. data/test/case/password_setting/password_setting.rb +0 -10
  258. data/test/case/password_setting/password_setting.tlf +0 -1
  259. data/test/case/single_line_tblock/single_line_tblock.tlf +0 -1
  260. data/test/case/tblock_overflow/tblock_overflow.rb +0 -20
  261. data/test/case/tblock_overflow/tblock_overflow.tlf +0 -1
  262. data/test/case/tblock_styles/tblock_styles.rb +0 -27
  263. data/test/case/tblock_styles/tblock_styles.tlf +0 -1
  264. data/test/case/text_align/text_align.rb +0 -8
  265. data/test/case/text_align/text_align.tlf +0 -1
  266. data/test/case/typeB_page_size/B4_ISO.tlf +0 -1
  267. data/test/case/typeB_page_size/B4_JIS.tlf +0 -1
  268. data/test/case/word_wrap/word_wrap.rb +0 -26
  269. data/test/case/word_wrap/word_wrap.tlf +0 -1
  270. data/test/unit/core/ext/array_spec.rb +0 -29
  271. data/test/unit/core/ext/hash_spec.rb +0 -29
  272. data/test/unit/core/ext/object_spec.rb +0 -30
  273. data/test/unit/core/ordered_hash_spec.rb +0 -51
  274. data/test/unit/core/shape/base/test_interface.rb +0 -52
  275. data/test/unit/core/utils_spec.rb +0 -56
  276. data/test/unit/data/basic_layout1.tlf +0 -1
  277. data/test/unit/data/basic_layout2.tlf +0 -1
  278. data/test/unit/data/basic_list_layout.tlf +0 -1
  279. data/test/unit/data/basic_list_noheader_layout.tlf +0 -1
  280. data/test/unit/helper.rb +0 -87
@@ -1,122 +1,154 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
3
+ module Thinreports
4
4
  module Core::Shape
5
-
6
- # @private
5
+
7
6
  class List::Manager
8
- # @return [ThinReports::Core::Shape::List::Configuration]
7
+ include Utils
8
+
9
+ # @return [Thinreports::Core::Shape::List::Configuration]
9
10
  attr_reader :config
10
-
11
- # @return [ThinReports::Core::Shape:::List::Page]
11
+
12
+ # @return [Thinreports::Core::Shape:::List::Page]
12
13
  attr_reader :current_page
13
-
14
- # @return [ThinReports::Core::Shape::List::PageState]
14
+
15
+ # @return [Thinreports::Core::Shape::List::PageState]
15
16
  attr_reader :current_page_state
16
17
 
17
18
  # @return [Integer]
18
19
  attr_accessor :page_count
19
-
20
- # @param [ThinReports::Core::Shape::List::Page] page
20
+
21
+ # @return [Proc]
22
+ attr_accessor :page_finalize_handler
23
+
24
+ # @return [Proc]
25
+ attr_accessor :page_footer_handler
26
+
27
+ # @return [Proc]
28
+ attr_accessor :footer_handler
29
+
30
+ # @param [Thinreports::Core::Shape::List::Page] page
21
31
  def initialize(page)
22
32
  switch_current!(page)
23
33
 
24
- @config = init_config
25
- @finalized = false
34
+ @config = init_config
35
+ @finalized = false
26
36
  @page_count = 0
37
+
38
+ @page_finalize_handler = nil
39
+ @page_footer_handler = nil
40
+ @footer_handler = nil
27
41
  end
28
-
29
- # @param [ThinReports::Core::Shape::List::Page] page
30
- # @return [ThinReports::Core::Shape::List::Manager]
42
+
43
+ # @param [Thinreports::Core::Shape::List::Page] page
44
+ # @return [Thinreports::Core::Shape::List::Manager]
31
45
  def switch_current!(page)
32
46
  @current_page = page
33
47
  @current_page_state = page.internal
34
48
  self
35
49
  end
36
-
50
+
37
51
  # @yield [new_list]
38
- # @yieldparam [ThinReports::Core::Shape::List::Page] new_list
52
+ # @yieldparam [Thinreports::Core::Shape::List::Page] new_list
39
53
  def change_new_page(&block)
40
54
  finalize_page
41
55
  new_page = report.internal.copy_page
42
-
56
+
43
57
  if block_given?
44
58
  block.call(new_page.list(current_page.id))
45
59
  end
46
60
  end
47
-
48
- # @see List::Page#header
49
- def header(values = {}, &block)
61
+
62
+ # @param [Hash] values ({})
63
+ # @yield [header]
64
+ # @yieldparam [Thinreports::Core::Shape::List::SectionInterface] header
65
+ # @return [Thinreports::Core::Shape::List::SectionInterface]
66
+ # @raise [Thinreports::Errors::DisabledListSection]
67
+ def build_header(values = {}, &block)
50
68
  unless format.has_header?
51
- raise ThinReports::Errors::DisabledListSection.new('header')
52
- end
69
+ raise Thinreports::Errors::DisabledListSection.new('header')
70
+ end
53
71
  current_page_state.header ||= init_section(:header)
54
- build_section(current_page_state.header, values, &block)
72
+ build_section(header_section, values, &block)
73
+ end
74
+
75
+ # @return [Thinreports::Core::Shape::List::SectionInterface]
76
+ def header_section
77
+ current_page_state.header
55
78
  end
56
-
79
+
57
80
  # @param (see #build_section)
58
81
  # @return [Boolean]
59
- def insert_new_detail(values = {}, &block)
82
+ def add_detail(values = {}, &block)
60
83
  return false if current_page_state.finalized?
61
-
84
+
62
85
  successful = true
63
-
86
+
64
87
  if overflow_with?(:detail)
65
88
  if auto_page_break?
66
89
  change_new_page do |new_list|
67
- new_list.manager.insert_new_row(:detail, values, &block)
90
+ new_list.manager.insert_detail(values, &block)
68
91
  end
69
92
  else
70
93
  finalize
71
94
  successful = false
72
95
  end
73
96
  else
74
- insert_new_row(:detail, values, &block)
97
+ insert_detail(values, &block)
75
98
  end
76
99
  successful
77
100
  end
78
-
79
- # @see #build_section
80
- def insert_new_row(section_name, values = {}, &block)
81
- row = build_section(init_section(section_name), values, &block)
101
+
102
+ # @param values (see Thinreports::Core::Shape::Manager::Target#values)
103
+ # @yield [section,]
104
+ # @yieldparam [Thinreports::Core::Shape::List::SectionInterface] section
105
+ # @return [Thinreports::Core::Shape::List::SectionInterface]
106
+ def insert_detail(values = {}, &block)
107
+ detail = build_section(init_section(:detail), values, &block)
108
+ insert_row(detail)
109
+ end
110
+
111
+ # @param [Thinreports::Core::Shape::List::SectionInterface] row
112
+ # @return [Thinreports::Core::Shape::List::SectionInterface]
113
+ def insert_row(row)
82
114
  row.internal.move_top_to(current_page_state.height)
83
-
115
+
84
116
  current_page_state.rows << row
85
117
  current_page_state.height += row.height
86
118
  row
87
119
  end
88
-
89
- # @param [ThinReports::Core::Shape::List::SectionInterface] section
90
- # @param values (see ThinReports::Core::Shape::Manager::Target#values)
120
+
121
+ # @param [Thinreports::Core::Shape::List::SectionInterface] section
122
+ # @param values (see Thinreports::Core::Shape::Manager::Target#values)
91
123
  # @yield [section,]
92
- # @yieldparam [ThinReports::Core::Shape::List::SectionInterface] section
93
- # @return [ThinReports::Core::Shape::List::SectionInterface]
124
+ # @yieldparam [Thinreports::Core::Shape::List::SectionInterface] section
125
+ # @return [Thinreports::Core::Shape::List::SectionInterface]
94
126
  def build_section(section, values = {}, &block)
95
127
  section.values(values)
96
- block_exec_on(section, &block)
128
+ call_block_in(section, &block)
97
129
  end
98
-
130
+
99
131
  # @param [Symbol] section_name
100
- # @return [ThinReports::Core::Shape::List::SectionInterface]
132
+ # @return [Thinreports::Core::Shape::List::SectionInterface]
101
133
  def init_section(section_name)
102
134
  List::SectionInterface.new(current_page,
103
135
  format.sections[section_name],
104
136
  section_name)
105
- end
106
-
137
+ end
138
+
107
139
  # @param [Symbol] section_name
108
140
  # @return [Boolean]
109
141
  def overflow_with?(section_name = :detail)
110
142
  max_height = page_max_height
111
-
143
+
112
144
  if section_name == :footer && format.has_page_footer?
113
145
  max_height += format.section_height(:page_footer)
114
146
  end
115
-
147
+
116
148
  height = format.section_height(section_name)
117
149
  (current_page_state.height + height) > max_height
118
150
  end
119
-
151
+
120
152
  # @return [Numeric]
121
153
  def page_max_height
122
154
  unless @page_max_height
@@ -127,103 +159,104 @@ module ThinReports
127
159
  end
128
160
  @page_max_height
129
161
  end
130
-
131
- # @return [ThinReports::Core::Shape::List::Store]
162
+
163
+ # @return [Thinreports::Core::Shape::List::Store]
132
164
  def store
133
165
  config.store
134
166
  end
135
-
136
- # @return [ThinReports::Core::Shape::List::Events]
167
+
168
+ # @return [Thinreports::Core::Shape::List::Events]
137
169
  def events
138
- config.events
170
+ config.internal_events
139
171
  end
140
-
172
+
141
173
  # @return [Boolean]
142
174
  def auto_page_break?
143
175
  format.auto_page_break?
144
176
  end
145
177
 
146
178
  # @param [Hash] options
147
- # @option [Boolean] :ignore_page_footer (false)
148
- # When the switch of the page is generated by #finalize, it is used.
149
- # @private
179
+ # @option options [Boolean] :ignore_page_footer (false)
180
+ # When the switch of the page is generated by #finalize, it is used.
150
181
  def finalize_page(options = {})
151
182
  return if current_page_state.finalized?
152
-
153
- if format.has_header?
154
- current_page_state.header ||= init_section(:header)
155
- end
156
-
183
+
184
+ build_header if format.has_header?
185
+
157
186
  if !options[:ignore_page_footer] && format.has_page_footer?
158
- footer = insert_new_row(:page_footer)
159
- # Dispatch page-footer insert event.
187
+ page_footer = insert_row(init_section(:page_footer))
188
+
189
+ # [DEPRECATION] Use List::Interface#on_page_footer_insert instead.
160
190
  events.
161
191
  dispatch(List::Events::SectionEvent.new(:page_footer_insert,
162
- footer, store))
192
+ page_footer, store))
193
+ # In 0.8 or later
194
+ @page_footer_handler.call(page_footer) if @page_footer_handler
163
195
  end
164
196
  current_page_state.finalized!
165
-
166
- # Dispatch page finalize event.
197
+
198
+ # [DEPRECATION] Use List::Interface#on_page_finalize instead.
167
199
  events.
168
200
  dispatch(List::Events::PageEvent.new(:page_finalize,
169
- current_page,
201
+ current_page,
170
202
  current_page_state.parent))
203
+ # In 0.8 or later
204
+ @page_finalize_handler.call if @page_finalize_handler
205
+
171
206
  @page_count += 1
172
207
  current_page_state.no = @page_count
173
208
  end
174
-
175
- # @private
209
+
176
210
  def finalize
177
211
  return if finalized?
178
-
179
212
  finalize_page
180
-
213
+
181
214
  if format.has_footer?
182
- footer = nil
183
-
215
+ footer = init_section(:footer)
216
+
217
+ # [DEPRECATION] Use List::Interface#on_footer_insert instead.
218
+ events.dispatch(List::Events::SectionEvent.new(:footer_insert, footer, store))
219
+
220
+ # In 0.8 or later
221
+ @footer_handler.call(footer) if @footer_handler
222
+
184
223
  if auto_page_break? && overflow_with?(:footer)
185
224
  change_new_page do |new_list|
186
- footer = new_list.manager.insert_new_row(:footer)
187
- new_list.manager.finalize_page(:ignore_page_footer => true)
225
+ new_list.manager.insert_row(footer)
226
+ new_list.manager.finalize_page(ignore_page_footer: true)
188
227
  end
189
228
  else
190
- footer = insert_new_row(:footer)
229
+ insert_row(footer)
191
230
  end
192
- # Dispatch footer insert event.
193
- events.dispatch(List::Events::SectionEvent.new(:footer_insert,
194
- footer, store))
195
231
  end
196
232
  @finalized = true
197
233
  end
198
-
234
+
199
235
  # @return [Boolean]
200
- # @private
201
236
  def finalized?
202
237
  @finalized
203
- end
204
-
205
- private
206
-
207
- # @return [ThinReports::Report::Base]
238
+ end
239
+
240
+ # @return [Thinreports::Report::Base]
208
241
  def report
209
242
  current_page_state.parent.report
210
243
  end
211
-
212
- # @return [ThinReports::Layout::Base]
244
+
245
+ # @return [Thinreports::Layout::Base]
213
246
  def layout
214
247
  current_page_state.parent.layout
215
248
  end
216
-
217
- # @return [ThinReports::Core::Shape::List::Format]
249
+
250
+ # @return [Thinreports::Core::Shape::List::Format]
218
251
  def format
219
252
  current_page_state.format
220
253
  end
221
-
222
- # @return [ThinReports::Core::Shape::List::Configuration]
254
+
255
+ # @return [Thinreports::Core::Shape::List::Configuration]
223
256
  def init_config
224
257
  layout.config.activate(current_page.id) || List::Configuration.new
225
258
  end
226
259
  end
227
-
260
+
228
261
  end
229
- end
262
+ end
@@ -1,16 +1,18 @@
1
1
  # coding: utf-8
2
2
 
3
- module ThinReports
3
+ module Thinreports
4
4
  module Core::Shape
5
-
5
+
6
6
  class List::Page < Basic::Interface
7
- # @param [ThinReports::Core::Page] parent
8
- # @param [ThinReports::Core::Shape::Basic::Format] format
9
- # @param [ThinReports::Core::Shape::List::PageState] internal (nil)
10
- # @param [ThinReports::Core::Shape::List::Manager] manager (nil)
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)
11
13
  def initialize(parent, format, internal = nil, manager = nil)
12
14
  super(parent, format, internal)
13
-
15
+
14
16
  @manager = if manager
15
17
  manager.switch_current!(self)
16
18
  else
@@ -20,24 +22,35 @@ module ThinReports
20
22
  # Set a reference to List::PageState List::Manager
21
23
  self.internal.manager = self.manager
22
24
  end
23
-
24
- # @param [Hash] values ({})
25
- # @yield [header,]
26
- # @yieldparam [ThinReports::Core::Shape::List::SectionInterface] header
27
- # @return [ThinReports::Core::Shape::List::SectionInterface]
28
- # @raise [ThinReports::Errors::DisabledListSection]
29
- def header(values = {}, &block)
30
- manager.header(values, &block)
25
+
26
+ # @see Thinreports::Core::Shape::List::Manager#build_header
27
+ def_delegator :manager, :build_header, :header
28
+
29
+ def on_page_finalize(&block)
30
+ manager.page_finalize_handler = block
31
31
  end
32
-
32
+
33
+ # @yield [page_footer]
34
+ # @yieldparam [Thinreports::Core::Shape::List::SectionInterface] page_footer
35
+ def on_page_footer_insert(&block)
36
+ manager.page_footer_handler = block
37
+ end
38
+
39
+ # @yield [footer]
40
+ # @yieldparam [Thinreports::Core::Shape::List::SectionInterface] footer
41
+ # @return [Thinreports::Core::Shape::List::SectionInterface]
42
+ def on_footer_insert(&block)
43
+ manager.footer_handler = block
44
+ end
45
+
33
46
  # @param [Hash] values ({})
34
47
  # @yield [row,]
35
- # @yieldparam [ThinReports::Core::Shape::List::SectionInterface] row
48
+ # @yieldparam [Thinreports::Core::Shape::List::SectionInterface] row
36
49
  # @return [Boolean]
37
50
  def add_row(values = {}, &block)
38
- manager.insert_new_detail(values, &block)
51
+ manager.add_detail(values, &block)
39
52
  end
40
-
53
+
41
54
  # If enabled, the auto-page-break of the list will force a page break
42
55
  # at the time this method is called. Otherwise, this list will be finalized.
43
56
  def page_break
@@ -48,44 +61,37 @@ module ThinReports
48
61
  end
49
62
  end
50
63
  alias_method :finalize, :page_break
51
-
52
- # @return [Boolean] If overfilling the list to insert a detail row
53
- # or already finalized, return the true. Otherwise false.
64
+
65
+ # @return [Boolean] Returns true if list has overflowed
66
+ # when `list#add_row` is called at the next time.
54
67
  def overflow?
55
- finalized? || manager.overflow_with?(:detail)
68
+ manager.overflow_with?(:detail)
56
69
  end
57
-
58
- # @return [Boolean] Return the true,
59
- # if the current page of list is already finalized.
60
- def finalized?
61
- internal.finalized?
62
- end
63
-
64
- # @return [ThinReports::Core::Shape::List::Configuration]
70
+
71
+ # @return [Thinreports::Core::Shape::List::Configuration]
65
72
  def config
66
73
  manager.config
67
74
  end
68
-
69
- # @return [ThinReports::Core::Shape::List::Store]
75
+
76
+ # @return [Thinreports::Core::Shape::List::Store]
70
77
  def store
71
78
  config.store
72
79
  end
73
-
74
- # @return [ThinReports::Core::Shape::List::Events]
80
+
81
+ # @return [Thinreports::Core::Shape::List::Events]
75
82
  def events
76
83
  config.events
77
84
  end
78
-
79
- # @param [ThinReports::Core::Page] new_parent
80
- # @return [ThinReports::Core::Shape::List::Page]
81
- # @private
85
+
86
+ # @param [Thinreports::Report::Page] new_parent
87
+ # @return [Thinreports::Core::Shape::List::Page]
82
88
  def copy(new_parent)
83
89
  if manager.auto_page_break?
84
90
  new_list = self.class.new(new_parent, internal.format,
85
91
  nil, manager)
86
92
  else
87
93
  manager.finalize
88
-
94
+
89
95
  new_list = self.class.new(new_parent, internal.format,
90
96
  internal.copy(new_parent), manager)
91
97
  internal.rows.each do |row|
@@ -93,30 +99,28 @@ module ThinReports
93
99
  end
94
100
  new_list.finalized!
95
101
  end
96
-
102
+
97
103
  if internal.format.has_header?
98
104
  new_list.internal.header = internal.header.copy(new_list)
99
105
  end
100
106
  new_list
101
107
  end
102
-
103
- # @private
108
+
104
109
  def manager
105
110
  @manager
106
111
  end
107
-
112
+
108
113
  private
109
-
110
- # @see ThinReports::Core::Shape::Base::Interface#init_internal
114
+
115
+ # @see Thinreports::Core::Shape::Base::Interface#init_internal
111
116
  def init_internal(parent, format)
112
117
  List::PageState.new(parent, format)
113
118
  end
114
119
  end
115
-
120
+
116
121
  # Alias to List::Page.
117
- # @see ThinReports::Core::Shape::List::Page
118
- # @private
122
+ # @see Thinreports::Core::Shape::List::Page
119
123
  List::Interface = List::Page
120
-
124
+
121
125
  end
122
126
  end