thinreports 0.7.6 → 0.8.0

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