thinreports 0.10.2 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CONTRIBUTING.md +2 -2
  3. data/.github/dependabot.yml +11 -0
  4. data/.github/workflows/test.yml +50 -0
  5. data/.gitignore +1 -0
  6. data/CHANGELOG.md +43 -0
  7. data/Gemfile +2 -1
  8. data/{MIT-LICENSE → LICENSE.txt} +2 -0
  9. data/README.md +70 -56
  10. data/Rakefile +12 -25
  11. data/gemfiles/prawn-2.2.gemfile +5 -0
  12. data/gemfiles/prawn-2.3.gemfile +5 -0
  13. data/gemfiles/prawn-2.4.gemfile +5 -0
  14. data/lib/thinreports/core/shape/basic/format.rb +5 -0
  15. data/lib/thinreports/core/shape/image_block.rb +1 -1
  16. data/lib/thinreports/core/shape/list.rb +1 -1
  17. data/lib/thinreports/core/shape/page_number.rb +1 -1
  18. data/lib/thinreports/core/shape/stack_view/format.rb +27 -0
  19. data/lib/thinreports/core/shape/stack_view/interface.rb +17 -0
  20. data/lib/thinreports/core/shape/stack_view/internal.rb +22 -0
  21. data/lib/thinreports/core/shape/stack_view/row_format.rb +39 -0
  22. data/lib/thinreports/core/shape/stack_view.rb +17 -0
  23. data/lib/thinreports/core/shape/style/basic.rb +4 -1
  24. data/lib/thinreports/core/shape/text.rb +1 -1
  25. data/lib/thinreports/core/shape/text_block/formatter/number.rb +6 -1
  26. data/lib/thinreports/core/shape/text_block/internal.rb +0 -2
  27. data/lib/thinreports/core/shape/text_block.rb +1 -1
  28. data/lib/thinreports/core/shape.rb +2 -0
  29. data/lib/thinreports/generate.rb +11 -0
  30. data/lib/thinreports/generator/pdf/document/draw_shape.rb +31 -10
  31. data/lib/thinreports/generator/pdf/document/draw_template_items.rb +1 -1
  32. data/lib/thinreports/generator/pdf/document/graphics/image.rb +19 -1
  33. data/lib/thinreports/generator/pdf/document/graphics/text.rb +10 -5
  34. data/lib/thinreports/generator/pdf/document/page.rb +12 -0
  35. data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +7 -7
  36. data/lib/thinreports/layout/base.rb +1 -1
  37. data/lib/thinreports/layout/legacy_schema.rb +1 -0
  38. data/lib/thinreports/layout/version.rb +1 -1
  39. data/lib/thinreports/report/internal.rb +2 -0
  40. data/lib/thinreports/report.rb +2 -2
  41. data/lib/thinreports/section_report/build.rb +32 -0
  42. data/lib/thinreports/section_report/builder/item_builder.rb +49 -0
  43. data/lib/thinreports/section_report/builder/report_builder.rb +82 -0
  44. data/lib/thinreports/section_report/builder/report_data.rb +13 -0
  45. data/lib/thinreports/section_report/builder/stack_view_builder.rb +53 -0
  46. data/lib/thinreports/section_report/builder/stack_view_data.rb +11 -0
  47. data/lib/thinreports/section_report/generate.rb +26 -0
  48. data/lib/thinreports/section_report/pdf/render.rb +23 -0
  49. data/lib/thinreports/section_report/pdf/renderer/draw_item.rb +68 -0
  50. data/lib/thinreports/section_report/pdf/renderer/group_renderer.rb +57 -0
  51. data/lib/thinreports/section_report/pdf/renderer/section_height.rb +100 -0
  52. data/lib/thinreports/section_report/pdf/renderer/section_renderer.rb +39 -0
  53. data/lib/thinreports/section_report/pdf/renderer/stack_view_renderer.rb +55 -0
  54. data/lib/thinreports/section_report/pdf/renderer/stack_view_row_renderer.rb +38 -0
  55. data/lib/thinreports/section_report/schema/loader.rb +28 -0
  56. data/lib/thinreports/section_report/schema/parser.rb +52 -0
  57. data/lib/thinreports/section_report/schema/report.rb +30 -0
  58. data/lib/thinreports/section_report/schema/section.rb +47 -0
  59. data/lib/thinreports/version.rb +1 -1
  60. data/lib/thinreports.rb +5 -0
  61. data/thinreports.gemspec +11 -10
  62. metadata +48 -150
  63. data/.travis.yml +0 -16
  64. data/examples/character_spacing/character_spacing.rb +0 -8
  65. data/examples/character_spacing/character_spacing.tlf +0 -293
  66. data/examples/dynamic_image/dynamic_image.rb +0 -31
  67. data/examples/dynamic_image/dynamic_image.tlf +0 -661
  68. data/examples/dynamic_image/img200x100.png +0 -0
  69. data/examples/dynamic_image/img50x50.png +0 -0
  70. data/examples/dynamic_style/dynamic_style.rb +0 -150
  71. data/examples/dynamic_style/dynamic_style.tlf +0 -1835
  72. data/examples/dynamic_style/dynamic_style_in_list.tlf +0 -344
  73. data/examples/dynamic_style/image.png +0 -0
  74. data/examples/eudc/eudc.rb +0 -20
  75. data/examples/eudc/eudc.tlf +0 -180
  76. data/examples/eudc/eudc.ttf +0 -0
  77. data/examples/helper.rb +0 -50
  78. data/examples/hidden_shapes/hidden_shapes.rb +0 -9
  79. data/examples/hidden_shapes/hidden_shapes.tlf +0 -449
  80. data/examples/list_events/list_events.rb +0 -32
  81. data/examples/list_events/list_events.tlf +0 -361
  82. data/examples/list_manual_generation/list_manual_generation.rb +0 -22
  83. data/examples/list_manual_generation/list_manual_generation.tlf +0 -132
  84. data/examples/list_page_number/list_page_number.rb +0 -17
  85. data/examples/list_page_number/list_page_number.tlf +0 -254
  86. data/examples/page_number/page_number.rb +0 -33
  87. data/examples/page_number/page_number.tlf +0 -215
  88. data/examples/palleted_png/palleted_png.png +0 -0
  89. data/examples/palleted_png/palleted_png.rb +0 -9
  90. data/examples/palleted_png/palleted_png.tlf +0 -47
  91. data/examples/password_setting/password_setting.rb +0 -10
  92. data/examples/password_setting/password_setting.tlf +0 -45
  93. data/examples/report_callbacks/report_callbacks.rb +0 -14
  94. data/examples/report_callbacks/report_callbacks.tlf +0 -147
  95. data/examples/single_line_tblock/single_line_tblock.rb +0 -13
  96. data/examples/single_line_tblock/single_line_tblock.tlf +0 -170
  97. data/examples/tblock_overflow/tblock_overflow.rb +0 -20
  98. data/examples/tblock_overflow/tblock_overflow.tlf +0 -538
  99. data/examples/tblock_styles/font_size.tlf +0 -383
  100. data/examples/tblock_styles/tblock_styles.rb +0 -43
  101. data/examples/tblock_styles/tblock_styles.tlf +0 -889
  102. data/examples/text_align/text_align.rb +0 -8
  103. data/examples/text_align/text_align.tlf +0 -241
  104. data/examples/typeB_page_size/B4_ISO.tlf +0 -45
  105. data/examples/typeB_page_size/B4_JIS.tlf +0 -45
  106. data/examples/typeB_page_size/typeB_page_size.rb +0 -17
  107. data/examples/word_wrap/word_wrap.rb +0 -26
  108. data/examples/word_wrap/word_wrap.tlf +0 -297
  109. data/test/data/font.ttf +0 -0
  110. data/test/data/image_normal.jpg +0 -0
  111. data/test/data/image_normal.png +0 -0
  112. data/test/data/image_normal_jpg_noext +0 -0
  113. data/test/data/image_normal_png_noext +0 -0
  114. data/test/data/image_pallete_based.png +0 -0
  115. data/test/data/legacy_layout/all-items.tlf +0 -1
  116. data/test/schema_helper.rb +0 -122
  117. data/test/test_helper.rb +0 -48
  118. data/test/tmp/.gitkeep +0 -0
  119. data/test/unit/core/format/test_base.rb +0 -152
  120. data/test/unit/core/shape/base/test_internal.rb +0 -87
  121. data/test/unit/core/shape/basic/test_block_format.rb +0 -23
  122. data/test/unit/core/shape/basic/test_block_interface.rb +0 -29
  123. data/test/unit/core/shape/basic/test_block_internal.rb +0 -55
  124. data/test/unit/core/shape/basic/test_format.rb +0 -37
  125. data/test/unit/core/shape/basic/test_interface.rb +0 -108
  126. data/test/unit/core/shape/basic/test_internal.rb +0 -55
  127. data/test/unit/core/shape/image_block/test_interface.rb +0 -24
  128. data/test/unit/core/shape/image_block/test_internal.rb +0 -31
  129. data/test/unit/core/shape/list/test_format.rb +0 -111
  130. data/test/unit/core/shape/list/test_manager.rb +0 -67
  131. data/test/unit/core/shape/list/test_page.rb +0 -156
  132. data/test/unit/core/shape/list/test_page_state.rb +0 -31
  133. data/test/unit/core/shape/list/test_section_format.rb +0 -36
  134. data/test/unit/core/shape/list/test_section_interface.rb +0 -75
  135. data/test/unit/core/shape/list/test_section_internal.rb +0 -50
  136. data/test/unit/core/shape/manager/test_format.rb +0 -38
  137. data/test/unit/core/shape/manager/test_internal.rb +0 -132
  138. data/test/unit/core/shape/manager/test_target.rb +0 -140
  139. data/test/unit/core/shape/page_number/test_format.rb +0 -55
  140. data/test/unit/core/shape/page_number/test_interface.rb +0 -33
  141. data/test/unit/core/shape/page_number/test_internal.rb +0 -81
  142. data/test/unit/core/shape/styles/test_base.rb +0 -191
  143. data/test/unit/core/shape/styles/test_basic.rb +0 -24
  144. data/test/unit/core/shape/styles/test_graphic.rb +0 -50
  145. data/test/unit/core/shape/styles/test_text.rb +0 -97
  146. data/test/unit/core/shape/text/test_format.rb +0 -44
  147. data/test/unit/core/shape/text/test_internal.rb +0 -20
  148. data/test/unit/core/shape/text_block/formatter/test_basic.rb +0 -24
  149. data/test/unit/core/shape/text_block/formatter/test_datetime.rb +0 -49
  150. data/test/unit/core/shape/text_block/formatter/test_number.rb +0 -76
  151. data/test/unit/core/shape/text_block/formatter/test_padding.rb +0 -77
  152. data/test/unit/core/shape/text_block/test_format.rb +0 -169
  153. data/test/unit/core/shape/text_block/test_formatter.rb +0 -28
  154. data/test/unit/core/shape/text_block/test_interface.rb +0 -63
  155. data/test/unit/core/shape/text_block/test_internal.rb +0 -128
  156. data/test/unit/core/test_shape.rb +0 -52
  157. data/test/unit/core/test_utils.rb +0 -68
  158. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +0 -135
  159. data/test/unit/generator/pdf/document/graphics/test_basic.rb +0 -46
  160. data/test/unit/generator/pdf/document/graphics/test_image.rb +0 -46
  161. data/test/unit/generator/pdf/document/graphics/test_text.rb +0 -171
  162. data/test/unit/generator/pdf/document/test_font.rb +0 -110
  163. data/test/unit/generator/pdf/document/test_graphics.rb +0 -42
  164. data/test/unit/generator/pdf/document/test_page.rb +0 -122
  165. data/test/unit/generator/pdf/document/test_parse_color.rb +0 -30
  166. data/test/unit/generator/pdf/prawn_ext/test_calc_image_dimensions.rb +0 -41
  167. data/test/unit/generator/pdf/prawn_ext/test_width_of.rb +0 -22
  168. data/test/unit/generator/pdf/test_document.rb +0 -22
  169. data/test/unit/generator/test_pdf.rb +0 -26
  170. data/test/unit/layout/test_base.rb +0 -41
  171. data/test/unit/layout/test_format.rb +0 -100
  172. data/test/unit/layout/test_legacy_schema.rb +0 -574
  173. data/test/unit/layout/test_version.rb +0 -26
  174. data/test/unit/report/test_base.rb +0 -248
  175. data/test/unit/report/test_internal.rb +0 -206
  176. data/test/unit/test_config.rb +0 -36
  177. data/test/unit/test_layout.rb +0 -12
  178. data/test/unit/test_report.rb +0 -18
@@ -1,108 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Core::Shape::Basic::TestInterface < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- # Alias
9
- Basic = Thinreports::Core::Shape::Basic
10
-
11
- def create_interface(format_config = {})
12
- report = Thinreports::Report.new layout: layout_file.path
13
- parent = report.start_new_page
14
-
15
- Basic::Interface.new parent, Basic::Format.new(format_config)
16
- end
17
-
18
- def test_id_should_return_id_with_reference_to_internal
19
- basic = create_interface('id' => 'foo')
20
- assert_equal basic.id, basic.internal.id
21
- end
22
-
23
- def test_id_should_return_cloned_id
24
- basic = create_interface('id' => 'basic-id')
25
- refute_same basic.id, basic.internal.id
26
- end
27
-
28
- def test_type_should_operate_as_delegator_of_internal
29
- basic = create_interface('type' => 'rect')
30
- assert_same basic.type, basic.internal.type
31
- end
32
-
33
- def test_visible_asker_should_return_result_with_reference_to_style_of_internal
34
- basic = create_interface('display' => false)
35
- assert_equal basic.visible?, basic.internal.style.visible
36
- end
37
-
38
- def test_visible_should_properly_set_visibility_to_style_of_internal
39
- basic = create_interface('display' => false)
40
- basic.visible(true)
41
-
42
- assert_equal basic.internal.style.visible, true
43
- end
44
-
45
- def test_style_should_operate_as_reader_when_one_argument_is_given
46
- basic = create_interface('style' => { 'fill-color' => '#ff0000' })
47
-
48
- assert_equal basic.style(:fill_color), '#ff0000'
49
- end
50
-
51
- def test_style_should_operate_as_writer_when_two_arguments_are_given
52
- basic = create_interface
53
- basic.style(:border_color, '#000000')
54
-
55
- assert_equal basic.style(:border_color), '#000000'
56
- end
57
-
58
- def test_style_should_operate_as_writer_for_border_style_when_three_arguments_are_given
59
- basic = create_interface
60
- basic.style(:border, 1, '#ffffff')
61
-
62
- assert_equal basic.style(:border), [1, '#ffffff']
63
- end
64
-
65
- def test_style_should_return_self_when_two_arguments_are_given
66
- assert_instance_of Basic::Interface, create_interface.style(:border_width, 1)
67
- end
68
-
69
- def test_style_should_return_self_when_three_arguments_are_given
70
- assert_instance_of Basic::Interface, create_interface.style(:border, 1, '#000000')
71
- end
72
-
73
- def test_styles_should_properly_set_the_specified_styles_as_Hash
74
- basic = create_interface
75
- basic.styles(fill_color: '#ff0000',
76
- border_color: '#000000',
77
- border_width: 5,
78
- visible: false)
79
-
80
- assert_equal [basic.style(:fill_color),
81
- basic.style(:border_color),
82
- basic.style(:border_width),
83
- basic.style(:visible)],
84
- ['#ff0000', '#000000', 5, false]
85
- end
86
-
87
- def test_hide_should_properly_set_false_to_visibility
88
- basic = create_interface
89
- basic.hide
90
-
91
- assert_equal basic.visible?, false
92
- end
93
-
94
- def test_hide_should_return_self
95
- assert_instance_of Basic::Interface, create_interface.hide
96
- end
97
-
98
- def test_show_should_properly_set_true_to_visibility
99
- basic = create_interface
100
- basic.show
101
-
102
- assert_equal basic.visible?, true
103
- end
104
-
105
- def test_show_should_return_self
106
- assert_instance_of Basic::Interface, create_interface.show
107
- end
108
- end
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Core::Shape::Basic::TestInternal < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- # Alias
9
- Basic = Thinreports::Core::Shape::Basic
10
-
11
- def create_internal(format_config = {})
12
- report = Thinreports::Report.new layout: layout_file.path
13
-
14
- Basic::Internal.new report.page, Basic::Format.new(format_config)
15
- end
16
-
17
- def test_id_should_operate_as_delegator_of_format
18
- basic = create_internal('id' => 'basic-id')
19
- assert_same basic.id, basic.format.id
20
- end
21
-
22
- def test_type_should_operate_as_delegator_of_format
23
- basic = create_internal('type' => 'ellipse')
24
- assert_same basic.type, basic.format.type
25
- end
26
-
27
- def test_style_should_return_instance_of_StyleGraphic
28
- assert_instance_of Thinreports::Core::Shape::Style::Graphic,
29
- create_internal.style
30
- end
31
-
32
- def test_type_of_asker_should_already_return_true_when_the_specified_type_is_basic
33
- assert_equal create_internal.type_of?(:basic), true
34
- end
35
-
36
- def test_type_of_asker_should_return_true_when_the_specified_type_equal_self_type_name
37
- result = []
38
-
39
- result << create_internal('type' => 'rect').type_of?('rect')
40
- result << create_internal('type' => 'ellipse').type_of?('ellipse')
41
- result << create_internal('type' => 'line').type_of?('line')
42
- result << create_internal('type' => 'image').type_of?('image')
43
-
44
- assert_equal result.all?, true
45
- end
46
-
47
- def test_identifier
48
- basic = create_internal 'id' => 'basic-id'
49
-
50
- assert_equal 'basic-id', basic.identifier
51
-
52
- basic.style.stubs(identifier: 'style-identifier')
53
- assert_equal basic.identifier, 'basic-idstyle-identifier'
54
- end
55
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Core::Shape::ImageBlock::TestInterface < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- ImageBlock = Thinreports::Core::Shape::ImageBlock
9
-
10
- def setup
11
- @report = Thinreports::Report.new layout: layout_file.path
12
- @page = @report.start_new_page
13
- end
14
-
15
- def test_src
16
- @page.item(:image_block).src('/path/to/image.png')
17
- assert_equal '/path/to/image.png', @page.item(:image_block).src
18
- end
19
-
20
- def test_src=
21
- @page.item(:image_block).src = '/path/to/image.png'
22
- assert_equal '/path/to/image.png', @page.item(:image_block).src
23
- end
24
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Core::Shape::ImageBlock::TestInternal < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- ImageBlock = Thinreports::Core::Shape::ImageBlock
9
-
10
- def test_src_should_return_the_same_value_as_value_method
11
- internal = create_internal
12
- internal.write_value('/path/to/image.png')
13
-
14
- assert_same internal.src, internal.read_value
15
- end
16
-
17
- def test_type_of_asker_should_return_true_when_iblock_value_is_given
18
- assert_equal create_internal.type_of?('image-block'), true
19
- end
20
-
21
- def test_type_of_asker_should_return_true_when_block_value_is_given
22
- assert_equal create_internal.type_of?(:block), true
23
- end
24
-
25
- def create_internal
26
- report = Thinreports::Report.new layout: layout_file.path
27
- parent = report.start_new_page
28
-
29
- ImageBlock::Internal.new parent, ImageBlock::Format.new({})
30
- end
31
- end
@@ -1,111 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Core::Shape::List::TestFormat < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- LIST_FORMAT = {
9
- 'type' => 'list',
10
- 'id' => 'list',
11
- 'display' => true,
12
- 'x' => 10.0,
13
- 'y' => 20.0,
14
- 'width' => 30.0,
15
- 'height' => 40.0,
16
- 'content-height' => 255,
17
- 'auto-page-break' => true,
18
- 'header' => {
19
- 'enabled' => true,
20
- 'height' => 10.0,
21
- 'translate' => { 'x' => 210.0, 'y' => 310.0 },
22
- 'items' => []
23
- },
24
- 'detail' => {
25
- 'height' => 20.0,
26
- 'translate' => { 'x' => 220.0, 'y' => 320.0 },
27
- 'items' => []
28
- },
29
- 'page-footer' => {
30
- 'enabled' => true,
31
- 'height' => 30.0,
32
- 'translate' => { 'x' => 230.0, 'y' => 330.0 },
33
- 'items' => []
34
- },
35
- 'footer' => {
36
- 'enabled' => false,
37
- 'height' => 40.0,
38
- 'translate' => { 'x' => 240.0, 'y' => 340.0 },
39
- 'items' => []
40
- }
41
- }
42
-
43
- List = Thinreports::Core::Shape::List
44
-
45
- def test_has_section?
46
- format = List::Format.new(LIST_FORMAT)
47
-
48
- assert_equal true, format.has_section?(:detail)
49
- assert_equal true, format.has_section?(:page_footer)
50
- assert_equal false, format.has_section?(:footer)
51
- end
52
-
53
- def test_section_height
54
- format = List::Format.new(LIST_FORMAT)
55
-
56
- assert_equal 10.0, format.section_height(:header)
57
- end
58
-
59
- def test_attribute_readers
60
- format = List::Format.new(LIST_FORMAT)
61
-
62
- assert_equal 255, format.height
63
- assert_equal true, format.auto_page_break?
64
- assert_equal true, format.has_header?
65
- assert_equal true, format.has_page_footer?
66
- assert_equal false, format.has_footer?
67
- assert_equal 20.0, format.detail_height
68
- assert_equal 30.0, format.page_footer_height
69
- assert_equal 40.0, format.footer_height
70
- assert_equal 10.0, format.header_height
71
- end
72
-
73
- def test_section_base_position_top
74
- page_footer_disabled = LIST_FORMAT
75
-
76
- format = List::Format.new(page_footer_disabled)
77
- assert_equal 310.0, format.section_base_position_top(:header)
78
- assert_equal 320.0, format.section_base_position_top(:detail)
79
- assert_equal 310.0, format.section_base_position_top(:page_footer)
80
- assert_equal 0, format.section_base_position_top(:footer)
81
-
82
- format_footer_enabled = format_section_enabled(true, 'footer', LIST_FORMAT)
83
-
84
- format = List::Format.new(format_footer_enabled)
85
- assert_equal 290.0, format.section_base_position_top(:footer)
86
-
87
- format_footer_enabld_and_page_footer_disabled = format_section_enabled(false, 'page-footer', format_footer_enabled)
88
-
89
- format = List::Format.new(format_footer_enabld_and_page_footer_disabled)
90
- assert_equal 320.0, format.section_base_position_top(:footer)
91
- end
92
-
93
- def test_initialize_sections
94
- format = List::Format.new(LIST_FORMAT)
95
-
96
- assert_instance_of List::SectionFormat, format.sections[:header]
97
- assert_instance_of List::SectionFormat, format.sections[:detail]
98
- assert_instance_of List::SectionFormat, format.sections[:page_footer]
99
-
100
- assert_nil format.sections[:footer]
101
- end
102
-
103
- private
104
-
105
- def format_section_enabled(enable, section, list_format)
106
- section_format = list_format[section].dup
107
- section_format['enabled'] = enable
108
-
109
- list_format.merge(section => section_format)
110
- end
111
- end
@@ -1,67 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Core::Shape::List::TestManager < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- # Alias
9
- List = Thinreports::Core::Shape::List
10
-
11
- def create_report(&block)
12
- report = Thinreports::Report.new layout: layout_file.path
13
- block.call(report) if block_given?
14
- report
15
- end
16
-
17
- def list_manager
18
- report = create_report {|r| r.start_new_page }
19
- report.page.list.manager
20
- end
21
-
22
- def test_current_page_should_return_the_instance_of_ListPage
23
- assert_instance_of List::Page, list_manager.current_page
24
- end
25
-
26
- def test_current_page_state_should_return_the_instance_of_ListPageState
27
- assert_instance_of List::PageState, list_manager.current_page_state
28
- end
29
-
30
- def test_switch_current_should_replace_own_current_page_property_by_the_given_page
31
- report = create_report {|r| r.start_new_page }
32
- list = report.page.list
33
- new_page = List::Page.new(report.page, list.internal.format)
34
-
35
- list.manager.switch_current!(new_page)
36
-
37
- assert_same list.manager.current_page, new_page
38
- end
39
-
40
- def test_switch_current_should_replace_own_current_page_state_property_by_internal_property_of_the_given_page
41
- report = create_report {|r| r.start_new_page }
42
- list = report.page.list
43
- new_page = List::Page.new(report.page, list.internal.format)
44
-
45
- list.manager.switch_current!(new_page)
46
-
47
- assert_same list.manager.current_page_state, new_page.internal
48
- end
49
-
50
- def test_switch_current_should_return_the_self
51
- report = create_report {|r| r.start_new_page }
52
- list = report.page.list
53
- new_page = List::Page.new(report.page, list.internal.format)
54
-
55
- assert_same list.manager.switch_current!(new_page), list.manager
56
- end
57
-
58
- def test_page_count
59
- report = create_report
60
- assert_equal report.page_count, 0
61
-
62
- report.list.page_break
63
- report.list.page_break
64
-
65
- assert_equal report.list.manager.page_count, 2
66
- end
67
- end
@@ -1,156 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Core::Shape::List::TestPage < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- # Alias
9
- List = Thinreports::Core::Shape::List
10
-
11
- LIST_SCHEMA = {
12
- 'type' => 'list',
13
- 'id' => 'list',
14
- 'display' => true,
15
- 'x' => 10.0,
16
- 'y' => 20.0,
17
- 'width' => 30.0,
18
- 'height' => 40.0,
19
- 'content-height' => 255,
20
- 'auto-page-break' => true,
21
- 'header' => {
22
- 'enabled' => true,
23
- 'height' => 10.0,
24
- 'translate' => { 'x' => 210.0, 'y' => 310.0 },
25
- 'items' => []
26
- },
27
- 'detail' => {
28
- 'height' => 20.0,
29
- 'translate' => { 'x' => 220.0, 'y' => 320.0 },
30
- 'items' => []
31
- },
32
- 'page-footer' => {
33
- 'enabled' => false,
34
- 'height' => 30.0,
35
- 'translate' => { 'x' => 230.0, 'y' => 330.0 },
36
- 'items' => []
37
- },
38
- 'footer' => {
39
- 'enabled' => false,
40
- 'height' => 40.0,
41
- 'translate' => { 'x' => 240.0, 'y' => 340.0 },
42
- 'items' => []
43
- }
44
- }
45
-
46
- def create_report(&block)
47
- report = Thinreports::Report.new layout: layout_file.path
48
- block.call(report) if block_given?
49
- report
50
- end
51
-
52
- def test_on_page_finalize_callback
53
- report = create_report
54
- list = report.list
55
-
56
- counter = 0
57
- callback = -> { counter += 1 }
58
-
59
- list.on_page_finalize(&callback)
60
-
61
- 5.times { list.add_row }
62
- assert_equal 1, counter
63
-
64
- report.finalize
65
- assert_equal 2, counter
66
- end
67
-
68
- def test_on_page_footer_insert_callback
69
- report = create_report
70
- list = report.list
71
-
72
- tester = 0
73
- callback = -> footer {
74
- assert_instance_of List::SectionInterface, footer
75
- assert_equal footer.internal.section_name, :page_footer
76
-
77
- tester += 1
78
- }
79
-
80
- list.on_page_footer_insert(&callback)
81
-
82
- 5.times { list.add_row }
83
- assert_equal 1, tester
84
-
85
- report.finalize
86
- assert_equal 2, tester
87
- end
88
-
89
- def test_on_footer_insert_callback
90
- report = create_report
91
- list = report.list
92
-
93
- tester = 0
94
- callback = -> footer {
95
- assert_instance_of List::SectionInterface, footer
96
- assert_equal footer.internal.section_name, :footer
97
-
98
- tester += 1
99
- }
100
-
101
- list.on_footer_insert(&callback)
102
-
103
- 5.times { list.add_row }
104
- assert_equal 0, tester
105
-
106
- report.finalize
107
- assert_equal 1, tester
108
- end
109
-
110
- def test_copy_should_properly_work_when_list_has_not_header
111
- report = Thinreports::Report.new layout: layout_file(schema: LIST_NO_HEADER_SCHEMA_JSON).path
112
-
113
- 10.times { report.list.add_row }
114
- rescue => e
115
- flunk exception_details(e, 'Not worked when list has not header')
116
- end
117
-
118
- def test_copy_when_auto_page_break_disabled
119
- list_schema = LIST_SCHEMA.merge('auto-page-break' => false)
120
-
121
- report = Thinreports::Report::Base.new
122
- layout = Thinreports::Layout::Base.new(layout_file.path)
123
-
124
- list_format = Thinreports::Core::Shape::List::Format.new(list_schema)
125
-
126
- list_page = List::Page.new(report.page, list_format)
127
-
128
- 2.times { list_page.add_row }
129
-
130
- copied_list_page = list_page.copy(Thinreports::Report::Page.new(report, layout))
131
-
132
- assert list_page.manager.finalized?
133
- assert copied_list_page.manager.finalized?
134
- assert_equal 2, copied_list_page.internal.rows.count
135
- end
136
-
137
- def test_copy_when_auto_page_break_enabled
138
- list_schema = LIST_SCHEMA.merge('auto-page-break' => true)
139
-
140
- report = Thinreports::Report::Base.new
141
- layout = Thinreports::Layout::Base.new(layout_file.path)
142
-
143
- list_format = Thinreports::Core::Shape::List::Format.new(list_schema)
144
-
145
- list_page = List::Page.new(report.page, list_format)
146
-
147
- 2.times { list_page.add_row }
148
- list_page.manager.finalize_page
149
-
150
- copied_list_page = list_page.copy(Thinreports::Report::Page.new(report, layout))
151
-
152
- refute list_page.manager.finalized?
153
- refute copied_list_page.manager.finalized?
154
- assert_empty copied_list_page.internal.rows
155
- end
156
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Core::Shape::List::TestPageState < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- # Alias
9
- List = Thinreports::Core::Shape::List
10
-
11
- def setup
12
- parent = mock('parent')
13
- format = mock('format')
14
-
15
- @state = List::PageState.new(parent, format)
16
- end
17
-
18
- def test_alias_class
19
- assert_same List::PageState, List::Internal
20
- end
21
-
22
- def test_type_of?
23
- assert_equal @state.type_of?('list'), true
24
- end
25
-
26
- def test_finalized!
27
- assert_equal @state.finalized?, false
28
- @state.finalized!
29
- assert_equal @state.finalized?, true
30
- end
31
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Core::Shape::List::TestSectionFormat < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- LIST_SECTION_FORMAT = {
9
- 'enabled' => true,
10
- 'height' => 47.7,
11
- 'translate' => { 'x' => 0, 'y' => -64.2 },
12
- 'items' => [
13
- { 'type' => 'rect', 'id' => '' },
14
- { 'type' => 'text-block', 'id' => 'text_block' }
15
- ]
16
- }
17
-
18
- Shape = Thinreports::Core::Shape
19
- List = Thinreports::Core::Shape::List
20
-
21
- def test_attribute_readers
22
- format = List::SectionFormat.new(LIST_SECTION_FORMAT)
23
-
24
- assert_equal 47.7, format.height
25
- assert_equal 0, format.relative_left
26
- assert_equal(-64.2, format.relative_top)
27
- assert_equal true, format.display?
28
- end
29
-
30
- def test_initialize_items
31
- format = List::SectionFormat.new(LIST_SECTION_FORMAT)
32
-
33
- assert_equal 1, format.shapes.count
34
- assert_instance_of Shape::TextBlock::Format, format.shapes[:text_block]
35
- end
36
- end
@@ -1,75 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Core::Shape::List::TestSectionInterface < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- BASIC_SECTION_SCHEMA = {
9
- 'height' => 1.0,
10
- 'enabled' => true,
11
- 'items' => []
12
- }
13
-
14
- # Alias
15
- List = Thinreports::Core::Shape::List
16
-
17
- def setup
18
- @report = Thinreports::Report.new layout: layout_file.path
19
- end
20
-
21
- def create_interface(extra_section_schema = {})
22
- parent = @report.start_new_page
23
-
24
- List::SectionInterface.new(
25
- parent,
26
- List::SectionFormat.new(BASIC_SECTION_SCHEMA.merge(extra_section_schema)),
27
- :section
28
- )
29
- end
30
-
31
- def test_internal_should_return_instance_of_SectionInternal
32
- assert_instance_of List::SectionInternal, create_interface.internal
33
- end
34
-
35
- def test_initialize_should_properly_set_the_specified_section_name_to_internal
36
- assert_equal create_interface.internal.section_name, :section
37
- end
38
-
39
- def test_initialize_should_properly_initialize_manager
40
- assert_instance_of Thinreports::Core::Shape::Manager::Internal,
41
- create_interface.manager
42
- end
43
-
44
- def test_height_should_operate_as_delegator_of_internal
45
- list = create_interface('height' => 100)
46
- assert_same list.height, list.internal.height
47
- end
48
-
49
- def test_copied_interface_should_succeed_an_section_name_of_original
50
- list = create_interface
51
- new_parent = @report.start_new_page
52
-
53
- assert_same list.copy(new_parent).internal.section_name,
54
- list.internal.section_name
55
- end
56
-
57
- def test_copied_interface_should_have_all_the_copies_of_Shape_which_original_holds
58
- list = create_interface
59
- copied_list(list) do |new_list|
60
- assert_equal new_list.manager.shapes.size, 3
61
- end
62
- end
63
-
64
- def copied_list(list, &block)
65
- tblock = Thinreports::Core::Shape::TextBlock
66
- new_parent = @report.start_new_page
67
-
68
- %w( foo bar hoge ).each do |id|
69
- list.manager.format.shapes[id.to_sym] = tblock::Format.new('type' => 'text-block', 'id' => id)
70
- list.item(id).value(10)
71
- end
72
-
73
- block.call(list.copy(new_parent))
74
- end
75
- end