thinreports 0.10.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. checksums.yaml +5 -5
  2. data/.github/CONTRIBUTING.md +2 -2
  3. data/.github/workflows/test.yml +51 -0
  4. data/.gitignore +1 -0
  5. data/CHANGELOG.md +49 -0
  6. data/Dockerfile +12 -0
  7. data/Gemfile +2 -1
  8. data/README.md +46 -21
  9. data/Rakefile +13 -29
  10. data/gemfiles/prawn-2.2.gemfile +5 -0
  11. data/gemfiles/prawn-2.3.gemfile +5 -0
  12. data/gemfiles/prawn-2.4.gemfile +5 -0
  13. data/lib/thinreports.rb +5 -0
  14. data/lib/thinreports/core/shape.rb +4 -3
  15. data/lib/thinreports/core/shape/base/interface.rb +0 -1
  16. data/lib/thinreports/core/shape/basic/format.rb +5 -0
  17. data/lib/thinreports/core/shape/image_block.rb +1 -1
  18. data/lib/thinreports/core/shape/list.rb +1 -1
  19. data/lib/thinreports/core/shape/list/manager.rb +1 -4
  20. data/lib/thinreports/core/shape/list/page.rb +2 -5
  21. data/lib/thinreports/core/shape/manager/internal.rb +0 -1
  22. data/lib/thinreports/core/shape/page_number.rb +1 -1
  23. data/lib/thinreports/core/shape/page_number/internal.rb +0 -1
  24. data/lib/thinreports/core/shape/stack_view.rb +17 -0
  25. data/lib/thinreports/core/shape/stack_view/format.rb +27 -0
  26. data/lib/thinreports/core/shape/stack_view/interface.rb +17 -0
  27. data/lib/thinreports/core/shape/stack_view/internal.rb +22 -0
  28. data/lib/thinreports/core/shape/stack_view/row_format.rb +39 -0
  29. data/lib/thinreports/core/shape/style/basic.rb +4 -1
  30. data/lib/thinreports/core/shape/text.rb +1 -1
  31. data/lib/thinreports/core/shape/text_block.rb +1 -1
  32. data/lib/thinreports/core/shape/text_block/formatter/number.rb +21 -9
  33. data/lib/thinreports/core/shape/text_block/internal.rb +0 -2
  34. data/lib/thinreports/core/utils.rb +6 -3
  35. data/lib/thinreports/generate.rb +11 -0
  36. data/lib/thinreports/generator/pdf/document/draw_shape.rb +31 -11
  37. data/lib/thinreports/generator/pdf/document/draw_template_items.rb +1 -2
  38. data/lib/thinreports/generator/pdf/document/font.rb +16 -10
  39. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +0 -1
  40. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +0 -1
  41. data/lib/thinreports/generator/pdf/document/graphics/image.rb +19 -1
  42. data/lib/thinreports/generator/pdf/document/graphics/text.rb +10 -8
  43. data/lib/thinreports/generator/pdf/document/page.rb +13 -4
  44. data/lib/thinreports/generator/pdf/drawer/list.rb +0 -1
  45. data/lib/thinreports/generator/pdf/prawn_ext/calc_image_dimensions.rb +1 -3
  46. data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +7 -7
  47. data/lib/thinreports/layout/base.rb +2 -4
  48. data/lib/thinreports/layout/format.rb +0 -1
  49. data/lib/thinreports/layout/legacy_schema.rb +2 -6
  50. data/lib/thinreports/layout/version.rb +1 -1
  51. data/lib/thinreports/report/internal.rb +4 -4
  52. data/lib/thinreports/report/page.rb +2 -7
  53. data/lib/thinreports/section_report/build.rb +32 -0
  54. data/lib/thinreports/section_report/builder/item_builder.rb +49 -0
  55. data/lib/thinreports/section_report/builder/report_builder.rb +82 -0
  56. data/lib/thinreports/section_report/builder/report_data.rb +13 -0
  57. data/lib/thinreports/section_report/builder/stack_view_builder.rb +55 -0
  58. data/lib/thinreports/section_report/builder/stack_view_data.rb +11 -0
  59. data/lib/thinreports/section_report/generate.rb +26 -0
  60. data/lib/thinreports/section_report/pdf/render.rb +23 -0
  61. data/lib/thinreports/section_report/pdf/renderer/draw_item.rb +68 -0
  62. data/lib/thinreports/section_report/pdf/renderer/group_renderer.rb +57 -0
  63. data/lib/thinreports/section_report/pdf/renderer/headers_renderer.rb +24 -0
  64. data/lib/thinreports/section_report/pdf/renderer/section_height.rb +100 -0
  65. data/lib/thinreports/section_report/pdf/renderer/section_renderer.rb +39 -0
  66. data/lib/thinreports/section_report/pdf/renderer/stack_view_renderer.rb +55 -0
  67. data/lib/thinreports/section_report/pdf/renderer/stack_view_row_renderer.rb +38 -0
  68. data/lib/thinreports/section_report/schema/loader.rb +28 -0
  69. data/lib/thinreports/section_report/schema/parser.rb +52 -0
  70. data/lib/thinreports/section_report/schema/report.rb +30 -0
  71. data/lib/thinreports/section_report/schema/section.rb +47 -0
  72. data/lib/thinreports/version.rb +1 -1
  73. data/thinreports.gemspec +11 -11
  74. metadata +48 -164
  75. data/.rubocop.yml +0 -41
  76. data/.travis.yml +0 -17
  77. data/examples/character_spacing/character_spacing.rb +0 -8
  78. data/examples/character_spacing/character_spacing.tlf +0 -293
  79. data/examples/dynamic_image/dynamic_image.rb +0 -31
  80. data/examples/dynamic_image/dynamic_image.tlf +0 -661
  81. data/examples/dynamic_image/img200x100.png +0 -0
  82. data/examples/dynamic_image/img50x50.png +0 -0
  83. data/examples/dynamic_style/dynamic_style.rb +0 -150
  84. data/examples/dynamic_style/dynamic_style.tlf +0 -1835
  85. data/examples/dynamic_style/dynamic_style_in_list.tlf +0 -344
  86. data/examples/dynamic_style/image.png +0 -0
  87. data/examples/eudc/eudc.rb +0 -20
  88. data/examples/eudc/eudc.tlf +0 -180
  89. data/examples/eudc/eudc.ttf +0 -0
  90. data/examples/helper.rb +0 -50
  91. data/examples/hidden_shapes/hidden_shapes.rb +0 -9
  92. data/examples/hidden_shapes/hidden_shapes.tlf +0 -449
  93. data/examples/list_events/list_events.rb +0 -32
  94. data/examples/list_events/list_events.tlf +0 -361
  95. data/examples/list_manual_generation/list_manual_generation.rb +0 -22
  96. data/examples/list_manual_generation/list_manual_generation.tlf +0 -132
  97. data/examples/list_page_number/list_page_number.rb +0 -17
  98. data/examples/list_page_number/list_page_number.tlf +0 -254
  99. data/examples/page_number/page_number.rb +0 -33
  100. data/examples/page_number/page_number.tlf +0 -215
  101. data/examples/palleted_png/palleted_png.png +0 -0
  102. data/examples/palleted_png/palleted_png.rb +0 -9
  103. data/examples/palleted_png/palleted_png.tlf +0 -47
  104. data/examples/password_setting/password_setting.rb +0 -10
  105. data/examples/password_setting/password_setting.tlf +0 -45
  106. data/examples/report_callbacks/report_callbacks.rb +0 -14
  107. data/examples/report_callbacks/report_callbacks.tlf +0 -147
  108. data/examples/single_line_tblock/single_line_tblock.rb +0 -13
  109. data/examples/single_line_tblock/single_line_tblock.tlf +0 -170
  110. data/examples/tblock_overflow/tblock_overflow.rb +0 -20
  111. data/examples/tblock_overflow/tblock_overflow.tlf +0 -538
  112. data/examples/tblock_styles/font_size.tlf +0 -383
  113. data/examples/tblock_styles/tblock_styles.rb +0 -43
  114. data/examples/tblock_styles/tblock_styles.tlf +0 -889
  115. data/examples/text_align/text_align.rb +0 -8
  116. data/examples/text_align/text_align.tlf +0 -241
  117. data/examples/typeB_page_size/B4_ISO.tlf +0 -45
  118. data/examples/typeB_page_size/B4_JIS.tlf +0 -45
  119. data/examples/typeB_page_size/typeB_page_size.rb +0 -17
  120. data/examples/word_wrap/word_wrap.rb +0 -26
  121. data/examples/word_wrap/word_wrap.tlf +0 -297
  122. data/test/data/font.ttf +0 -0
  123. data/test/data/image_normal.jpg +0 -0
  124. data/test/data/image_normal.png +0 -0
  125. data/test/data/image_normal_jpg_noext +0 -0
  126. data/test/data/image_normal_png_noext +0 -0
  127. data/test/data/image_pallete_based.png +0 -0
  128. data/test/data/legacy_layout/all-items.tlf +0 -1
  129. data/test/schema_helper.rb +0 -122
  130. data/test/test_helper.rb +0 -48
  131. data/test/tmp/.gitkeep +0 -0
  132. data/test/unit/core/format/test_base.rb +0 -152
  133. data/test/unit/core/shape/base/test_internal.rb +0 -87
  134. data/test/unit/core/shape/basic/test_block_format.rb +0 -23
  135. data/test/unit/core/shape/basic/test_block_interface.rb +0 -29
  136. data/test/unit/core/shape/basic/test_block_internal.rb +0 -55
  137. data/test/unit/core/shape/basic/test_format.rb +0 -37
  138. data/test/unit/core/shape/basic/test_interface.rb +0 -108
  139. data/test/unit/core/shape/basic/test_internal.rb +0 -55
  140. data/test/unit/core/shape/image_block/test_interface.rb +0 -24
  141. data/test/unit/core/shape/image_block/test_internal.rb +0 -31
  142. data/test/unit/core/shape/list/test_format.rb +0 -111
  143. data/test/unit/core/shape/list/test_manager.rb +0 -67
  144. data/test/unit/core/shape/list/test_page.rb +0 -82
  145. data/test/unit/core/shape/list/test_page_state.rb +0 -31
  146. data/test/unit/core/shape/list/test_section_format.rb +0 -36
  147. data/test/unit/core/shape/list/test_section_interface.rb +0 -75
  148. data/test/unit/core/shape/list/test_section_internal.rb +0 -50
  149. data/test/unit/core/shape/manager/test_format.rb +0 -38
  150. data/test/unit/core/shape/manager/test_internal.rb +0 -132
  151. data/test/unit/core/shape/manager/test_target.rb +0 -140
  152. data/test/unit/core/shape/page_number/test_format.rb +0 -55
  153. data/test/unit/core/shape/page_number/test_interface.rb +0 -33
  154. data/test/unit/core/shape/page_number/test_internal.rb +0 -81
  155. data/test/unit/core/shape/styles/test_base.rb +0 -191
  156. data/test/unit/core/shape/styles/test_basic.rb +0 -24
  157. data/test/unit/core/shape/styles/test_graphic.rb +0 -50
  158. data/test/unit/core/shape/styles/test_text.rb +0 -97
  159. data/test/unit/core/shape/text/test_format.rb +0 -44
  160. data/test/unit/core/shape/text/test_internal.rb +0 -20
  161. data/test/unit/core/shape/text_block/formatter/test_basic.rb +0 -24
  162. data/test/unit/core/shape/text_block/formatter/test_datetime.rb +0 -49
  163. data/test/unit/core/shape/text_block/formatter/test_number.rb +0 -76
  164. data/test/unit/core/shape/text_block/formatter/test_padding.rb +0 -77
  165. data/test/unit/core/shape/text_block/test_format.rb +0 -169
  166. data/test/unit/core/shape/text_block/test_formatter.rb +0 -28
  167. data/test/unit/core/shape/text_block/test_interface.rb +0 -63
  168. data/test/unit/core/shape/text_block/test_internal.rb +0 -128
  169. data/test/unit/core/test_shape.rb +0 -52
  170. data/test/unit/core/test_utils.rb +0 -68
  171. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +0 -135
  172. data/test/unit/generator/pdf/document/graphics/test_basic.rb +0 -46
  173. data/test/unit/generator/pdf/document/graphics/test_image.rb +0 -46
  174. data/test/unit/generator/pdf/document/graphics/test_text.rb +0 -171
  175. data/test/unit/generator/pdf/document/test_font.rb +0 -84
  176. data/test/unit/generator/pdf/document/test_graphics.rb +0 -42
  177. data/test/unit/generator/pdf/document/test_page.rb +0 -122
  178. data/test/unit/generator/pdf/document/test_parse_color.rb +0 -30
  179. data/test/unit/generator/pdf/prawn_ext/test_calc_image_dimensions.rb +0 -41
  180. data/test/unit/generator/pdf/prawn_ext/test_width_of.rb +0 -22
  181. data/test/unit/generator/pdf/test_document.rb +0 -22
  182. data/test/unit/generator/test_pdf.rb +0 -26
  183. data/test/unit/layout/test_base.rb +0 -41
  184. data/test/unit/layout/test_format.rb +0 -100
  185. data/test/unit/layout/test_legacy_schema.rb +0 -574
  186. data/test/unit/layout/test_version.rb +0 -26
  187. data/test/unit/report/test_base.rb +0 -248
  188. data/test/unit/report/test_internal.rb +0 -206
  189. data/test/unit/test_config.rb +0 -36
  190. data/test/unit/test_layout.rb +0 -12
  191. data/test/unit/test_report.rb +0 -18
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Generator::PDF::TestGraphics < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- class TestGraphics
9
- attr_accessor :pdf
10
- include Thinreports::Generator::PDF::Graphics
11
- end
12
-
13
- def setup
14
- @g = TestGraphics.new
15
- @g.pdf = mock('pdf')
16
- end
17
-
18
- def test_setup_custom_graphic_states
19
- @g.pdf.expects(:line_width).
20
- with(TestGraphics::BASE_LINE_WIDTH).once
21
-
22
- @g.send(:setup_custom_graphic_states)
23
- end
24
-
25
- def test_line_width
26
- @g.pdf.
27
- expects(:line_width).
28
- with(10 * TestGraphics::BASE_LINE_WIDTH).once
29
-
30
- @g.send(:line_width, 10)
31
- end
32
-
33
- def test_save_graphics_state
34
- @g.pdf.expects(:save_graphics_state).once
35
- @g.send(:save_graphics_state)
36
- end
37
-
38
- def test_restore_graphics_state
39
- @g.pdf.expects(:restore_graphics_state).once
40
- @g.send(:restore_graphics_state)
41
- end
42
- end
@@ -1,122 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Generator::PDF::Document::TestPage < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- def create_pdf
9
- @pdf = Thinreports::Generator::PDF::Document.new
10
- end
11
-
12
- def test_JIS_page_size
13
- sizes = Thinreports::Generator::PDF::Document::JIS_SIZES
14
- assert_equal sizes['B4'], [728.5, 1031.8]
15
- assert_equal sizes['B5'], [515.9, 728.5]
16
- end
17
-
18
- def test_B4_paper_size_should_returns_size_as_B4_JIS
19
- create_pdf
20
-
21
- format = Thinreports::Layout::Format.build(layout_file.path)
22
- format.stubs(page_paper_type: 'B4')
23
-
24
- @pdf.start_new_page(format)
25
- assert_equal @pdf.internal.page.size, [728.5, 1031.8]
26
- end
27
-
28
- def test_B4_ISO_paper_size_should_be_converted_to_B4
29
- create_pdf
30
-
31
- format = Thinreports::Layout::Format.build(layout_file.path)
32
- format.stubs(page_paper_type: 'B4_ISO')
33
-
34
- @pdf.start_new_page(format)
35
- assert_equal @pdf.internal.page.size, 'B4'
36
- end
37
-
38
- def test_change_page_format_should_return_true_at_first_time
39
- create_pdf
40
- format = Thinreports::Layout::Format.build(layout_file.path)
41
-
42
- assert_equal @pdf.send(:change_page_format?, format), true
43
- end
44
-
45
- def test_change_page_format_should_return_false_when_given_the_same_format
46
- create_pdf
47
- format = Thinreports::Layout::Format.build(layout_file.path)
48
-
49
- @pdf.instance_variable_set(:@current_page_format, format)
50
- assert_equal @pdf.send(:change_page_format?, format), false
51
- end
52
-
53
- def test_change_page_format_should_return_true_when_given_the_other_format
54
- create_pdf
55
- format1 = Thinreports::Layout::Format.build(layout_file.path)
56
- format2 = Thinreports::Layout::Format.build(layout_file.path)
57
-
58
- @pdf.instance_variable_set(:@current_page_format, format1)
59
- assert_equal @pdf.send(:change_page_format?, format2), true
60
- end
61
-
62
- def test_new_basic_page_options
63
- format = Thinreports::Layout::Format.build(layout_file.path)
64
- options = create_pdf.send(:new_basic_page_options, format)
65
-
66
- assert_equal options[:layout], format.page_orientation.to_sym
67
- assert_equal options[:size], format.page_paper_type
68
- end
69
-
70
- def test_new_basic_page_options_when_the_layout_has_customize_size
71
- format = stub user_paper_type?: true,
72
- page_width: 100,
73
- page_height: 100,
74
- page_orientation: 'portrait'
75
-
76
- options = create_pdf.send(:new_basic_page_options, format)
77
- assert_equal options[:size], [100, 100]
78
- end
79
-
80
- def test_start_new_page_should_create_stamp
81
- create_pdf
82
- format = Thinreports::Layout::Format.build(layout_file.path)
83
- @pdf.start_new_page(format)
84
-
85
- assert_includes @pdf.send(:format_stamp_registry), format.identifier
86
- end
87
-
88
- def test_start_new_page_should_not_create_stamp
89
- create_pdf
90
- format = Thinreports::Layout::Format.build(layout_file.path)
91
- @pdf.start_new_page(format)
92
- @pdf.start_new_page(format)
93
-
94
- assert_equal @pdf.send(:format_stamp_registry).size, 1
95
- end
96
-
97
- def test_start_new_page_should_stamp_constantly
98
- create_pdf
99
- format = Thinreports::Layout::Format.build(layout_file.path)
100
- @pdf.expects(:stamp).with(format.identifier.to_s).times(2)
101
-
102
- @pdf.start_new_page(format)
103
- @pdf.start_new_page(format)
104
- end
105
-
106
- def test_add_blank_page_should_create_an_A4_size_page_in_first_page
107
- create_pdf
108
- @pdf.internal.expects(:start_new_page).with(size: 'A4').once
109
-
110
- @pdf.add_blank_page
111
- end
112
-
113
- def test_add_blank_page_should_call_with_no_arguments_since_second_page
114
- create_pdf
115
- format = Thinreports::Layout::Format.build(layout_file.path)
116
-
117
- @pdf.start_new_page(format)
118
- @pdf.internal.expects(:start_new_page).with({}).once
119
-
120
- @pdf.add_blank_page
121
- end
122
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Generator::PDF::TestParseColor < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- class TestColorParser
9
- include Thinreports::Generator::PDF::ParseColor
10
- end
11
-
12
- def setup
13
- @parser = TestColorParser.new
14
- end
15
-
16
- def test_parse_color_with_hexcolor
17
- assert_equal @parser.parse_color('#ff0000'), 'ff0000'
18
- assert_equal @parser.parse_color('000000'), '000000'
19
- end
20
-
21
- def test_parse_color_with_colorname
22
- assert_equal @parser.parse_color('red'), 'ff0000'
23
- end
24
-
25
- def test_parse_color_with_colorname_raise_when_unknown_name_given
26
- assert_raises Thinreports::Errors::UnsupportedColorName do
27
- @parser.parse_color('whitesmoke')
28
- end
29
- end
30
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Generator::PrawnExt::TestCalcImageDimensions < Minitest::Test
6
- class Klass
7
- prepend Thinreports::Generator::PrawnExt::CalcImageDimensions
8
-
9
- def calc_image_dimensions(options)
10
- options
11
- end
12
- end
13
-
14
- def setup
15
- @klass = Klass.new
16
- end
17
-
18
- def test_calc_image_dimensions
19
- res_options = @klass.calc_image_dimensions(
20
- auto_fit: [100, 200],
21
- width: 101,
22
- height: 199
23
- )
24
- assert_equal [100, 200], res_options[:fit]
25
- refute_includes res_options.keys, :auto_fit
26
-
27
- res_options = @klass.calc_image_dimensions(
28
- auto_fit: [100, 200],
29
- width: 99,
30
- height: 201
31
- )
32
- assert_equal [100, 200], res_options[:fit]
33
-
34
- res_options = @klass.calc_image_dimensions(
35
- auto_fit: [100, 200],
36
- width: 99,
37
- height: 199
38
- )
39
- refute_includes res_options.keys, :fit
40
- end
41
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Generator::PrawnExt::TestWidthOf < Minitest::Test
6
- def setup
7
- @pdf = Prawn::Document.new
8
- end
9
-
10
- def test_width_of
11
- text_width = @pdf.width_of('abcd')
12
-
13
- @pdf.character_spacing(1) do
14
- expected_character_space_width = 1 * 3
15
- assert_equal text_width + expected_character_space_width, @pdf.width_of('abcd')
16
- end
17
-
18
- @pdf.character_spacing(1) do
19
- assert_equal 0, @pdf.width_of('')
20
- end
21
- end
22
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Generator::PDF::TestDocument < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- # Alias
9
- Document = Thinreports::Generator::PDF::Document
10
-
11
- def test_new
12
- pdf = Document.new
13
- assert_equal pdf.internal.page_count, 0
14
- assert_equal pdf.internal.page.margins.values, [0, 0, 0, 0]
15
-
16
- pdf = Document.new(security: { owner_password: 'abc' })
17
- assert_equal true, pdf.internal.state.encrypt
18
-
19
- pdf = Document.new(title: 'Title')
20
- assert_equal 'Title', pdf.internal.state.store.info.data[:Title]
21
- end
22
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Generator::TestPDF < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- PDF = Thinreports::Generator::PDF
9
-
10
- def test_default_layout
11
- layout_filename = layout_file.path
12
- report = Thinreports::Report.new layout: layout_filename
13
-
14
- generator = PDF.new report
15
- assert_equal layout_filename, generator.default_layout.filename
16
- end
17
-
18
- def test_initialize
19
- report = Thinreports::Report.new layout: layout_file.path
20
- report.start_new_page
21
-
22
- PDF.new(report)
23
-
24
- assert_equal true, report.finalized?
25
- end
26
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Layout::TestBase < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- Layout = Thinreports::Layout
9
-
10
- def test_load_format
11
- assert_instance_of Layout::Format, Layout::Base.load_format(layout_file.path)
12
- assert_raises Thinreports::Errors::LayoutFileNotFound do
13
- Layout::Base.load_format 'unknown.tlf'
14
- end
15
- end
16
-
17
- def test_new
18
- layout_filename = layout_file.path
19
- layout = Layout::Base.new(layout_filename)
20
-
21
- assert_nil layout.id
22
- assert_equal layout_filename, layout.filename
23
- assert_instance_of Layout::Format, layout.format
24
- end
25
-
26
- def test_id
27
- layout_without_id = Layout::Base.new(layout_file.path)
28
- assert_nil layout_without_id.id
29
-
30
- layout_with_id = Layout::Base.new(layout_file.path, id: 'foo')
31
- assert_equal 'foo', layout_with_id.id
32
- end
33
-
34
- def test_default?
35
- layout_without_id = Layout::Base.new(layout_file.path)
36
- assert_equal true, layout_without_id.default?
37
-
38
- layout_with_id = Layout::Base.new(layout_file.path, id: 'bar')
39
- assert_equal false, layout_with_id.default?
40
- end
41
- end
@@ -1,100 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Layout::TestFormat < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- LAYOUT_SCHEMA = {
9
- 'version' => '0.9.0',
10
- 'title' => 'Report Title',
11
- 'report' => {
12
- 'paper-type' => 'A4',
13
- 'width' => 100.0,
14
- 'height' => 200.0,
15
- 'orientation' => 'landscape',
16
- 'margin' => [100.0, 200.0, 300.0, 999.9]
17
- },
18
- 'state' => {
19
- 'layout-guides' => [
20
- { 'type' => 'x', 'position' => 0.1 }
21
- ]
22
- },
23
- 'items' => [
24
- { 'type'=> 'rect', 'id'=> '', 'x'=> 100.0, 'y'=> 100.0, 'width'=> 100.0, 'height'=> 100.0, 'style'=> {'stroke-width'=> 1}},
25
- { 'type'=> 'text-block', 'id'=> 'text_block', 'x'=> 100.0, 'y'=> 100.0 },
26
- { 'type'=> 'page-number', 'id'=> '', 'x'=> 100.0, 'y'=> 100.0 }
27
- ]
28
- }
29
-
30
- Shape = Thinreports::Core::Shape
31
- Layout = Thinreports::Layout
32
-
33
- def test_attribute_readers
34
- format = Layout::Format.new(layout_schema)
35
-
36
- assert_equal 'Report Title', format.report_title
37
- assert_equal Thinreports::VERSION, format.last_version
38
- assert_equal 'A4', format.page_paper_type
39
- assert_equal 100.0, format.page_width
40
- assert_equal 200.0, format.page_height
41
- assert_equal 'landscape', format.page_orientation
42
- end
43
-
44
- def test_user_paper_type?
45
- format_paper_type_is_not_user = Layout::Format.new(layout_schema)
46
- assert_equal false, format_paper_type_is_not_user.user_paper_type?
47
-
48
- format_paper_type_is_user = Layout::Format.new(layout_schema.merge(
49
- {
50
- 'report' => {
51
- 'paper-type' => 'user'
52
- }
53
- }
54
- ))
55
- assert_equal true, format_paper_type_is_user.user_paper_type?
56
- end
57
-
58
- def test_build
59
- compatible_layout_file = layout_file
60
- assert_instance_of Layout::Format, Layout::Format.build(compatible_layout_file.path)
61
-
62
- incompatible_layout_file = layout_file(version: '0.0.1')
63
- assert_raises Thinreports::Errors::IncompatibleLayoutFormat do
64
- Layout::Format.build(incompatible_layout_file.path)
65
- end
66
- end
67
-
68
- def test_build_legacy_layout
69
- format = nil
70
-
71
- assert_deprecated { format = Layout::Format.build(data_file('legacy_layout', 'all-items.tlf')) }
72
-
73
- assert_equal 'Report Title', format.report_title
74
- assert_equal '0.8.2', format.last_version
75
- assert_equal 'A4', format.page_paper_type
76
- assert_equal 'portrait', format.page_orientation
77
-
78
- item_types = format.attributes['items'].map { |items| items['type'] }
79
-
80
- assert_equal 9, item_types.count
81
- assert_equal %w( rect ellipse line image image-block text-block list page-number text ).sort,
82
- item_types.sort
83
- end
84
-
85
- def test_initialize_items
86
- format = Layout::Format.new(layout_schema)
87
-
88
- assert_equal 2, format.shapes.count
89
-
90
- shape_classes = format.shapes.values.map(&:class)
91
- assert_includes shape_classes, Shape::TextBlock::Format
92
- assert_includes shape_classes, Shape::PageNumber::Format
93
- end
94
-
95
- private
96
-
97
- def layout_schema(version = Thinreports::VERSION)
98
- LAYOUT_SCHEMA.merge('version' => version)
99
- end
100
- end