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,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
@@ -1,574 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Layout::TestLegacySchema < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- Layout = Thinreports::Layout
9
-
10
- def test_upgrade
11
- legacy_schema = {
12
- 'version' => '0.8.2',
13
- 'finger-print' => 'abcd',
14
- 'config' => {
15
- 'title' => 'Report Title',
16
- 'page' => {
17
- 'paper-type' => 'A4',
18
- 'width' => '100.0',
19
- 'height' => '200.0',
20
- 'orientation' => 'landscape',
21
- 'margin-top' => '0.1',
22
- 'margin-right' => '0.2',
23
- 'margin-bottom' => '0.3',
24
- 'margin-left' => '0.4'
25
- }
26
- },
27
- 'svg' => '<svg><g class="canvas"></g></svg>',
28
- 'state' => {
29
- 'layout-guide' => []
30
- }
31
- }
32
-
33
- assert_equal(
34
- {
35
- 'version' => '0.8.2',
36
- 'title' => 'Report Title',
37
- 'report' => {
38
- 'paper-type' => 'A4',
39
- 'width' => 100.0,
40
- 'height' => 200.0,
41
- 'orientation' => 'landscape',
42
- 'margin' => [0.1, 0.2, 0.3, 0.4]
43
- },
44
- 'items' => []
45
- },
46
- Layout::LegacySchema.new(legacy_schema).upgrade
47
- )
48
- end
49
-
50
- def test_text_item_schema
51
- legacy_attributes = {
52
- 'x-id' => 'text_id',
53
- 'x-left' => '100.1',
54
- 'x-top' => '200.1',
55
- 'x-width' => '300.1',
56
- 'x-height' => '400.1',
57
- 'x-display' => 'true',
58
- 'font-family' => 'Helvetica',
59
- 'font-size' => '18',
60
- 'font-weight' => 'normal',
61
- 'font-style' => 'normal',
62
- 'text-decoration' => 'underline line-through',
63
- 'fill' => 'red',
64
- 'text-anchor' => 'start',
65
- 'x-valign' => 'top',
66
- 'x-line-height' => '20.1',
67
- 'kerning' => '2.1'
68
- }
69
- legacy_texts = %w( line1 line2 )
70
-
71
- assert_equal(
72
- {
73
- 'id' => 'text_id',
74
- 'type' => 'text',
75
- 'x' => 100.1,
76
- 'y' => 200.1,
77
- 'width' => 300.1,
78
- 'height' => 400.1,
79
- 'display' => true,
80
- 'texts' => %w( line1 line2 ),
81
- 'style' => {
82
- 'font-family' => %w( Helvetica ),
83
- 'font-size' => 18.0,
84
- 'color' => 'red',
85
- 'font-style' => %w( underline linethrough ),
86
- 'text-align' => 'left',
87
- 'vertical-align' => 'top',
88
- 'line-height' => 20.1,
89
- 'letter-spacing' => 2.1
90
- }
91
- },
92
- layout_legacy_schema.text_item_schema(legacy_attributes, legacy_texts)
93
- )
94
- end
95
-
96
- def test_rect_item_schema
97
- legacy_attributes = {
98
- 'x-id' => 'rect_id',
99
- 'x' => '100.1',
100
- 'y' => '200.1',
101
- 'width' => '300.1',
102
- 'height' => '400.1',
103
- 'x-display' => 'false',
104
- 'stroke-width' => '2.5',
105
- 'stroke' => '#ff0000',
106
- 'x-stroke-type' => 'dotted',
107
- 'fill' => 'red'
108
- }
109
- assert_equal(
110
- {
111
- 'id' => 'rect_id',
112
- 'type' => 'rect',
113
- 'x' => 100.1,
114
- 'y' => 200.1,
115
- 'width' => 300.1,
116
- 'height' => 400.1,
117
- 'display' => false,
118
- 'style' => {
119
- 'border-width' => 2.5,
120
- 'border-color' => '#ff0000',
121
- 'border-style' => 'dotted',
122
- 'fill-color' => 'red'
123
- }
124
- },
125
- layout_legacy_schema.rect_item_schema(legacy_attributes)
126
- )
127
- end
128
-
129
- def test_line_item_schema
130
- legacy_attributes = {
131
- 'x-id' => 'line_id',
132
- 'x1' => '100.1',
133
- 'y1' => '200.1',
134
- 'x2' => '300.1',
135
- 'y2' => '400.1',
136
- 'x-display' => 'true',
137
- 'stroke-width' => '1',
138
- 'stroke' => 'red',
139
- 'x-stroke-type' => 'solid'
140
- }
141
- assert_equal(
142
- {
143
- 'id' => 'line_id',
144
- 'type' => 'line',
145
- 'x1' => 100.1,
146
- 'y1' => 200.1,
147
- 'x2' => 300.1,
148
- 'y2' => 400.1,
149
- 'display' => true,
150
- 'style' => {
151
- 'border-width' => 1.0,
152
- 'border-color' => 'red',
153
- 'border-style' => 'solid'
154
- }
155
- },
156
- layout_legacy_schema.line_item_schema(legacy_attributes)
157
- )
158
- end
159
-
160
- def test_ellipse_item_schema
161
- legacy_attributes = {
162
- 'x-id' => 'ellipse_id',
163
- 'cx' => '100.1',
164
- 'cy' => '200.1',
165
- 'rx' => '300.1',
166
- 'ry' => '400.1',
167
- 'x-display' => 'true',
168
- 'stroke-width' => '1',
169
- 'stroke' => 'red',
170
- 'x-stroke-type' => 'solid',
171
- 'fill' => 'blue'
172
- }
173
- assert_equal(
174
- {
175
- 'id' => 'ellipse_id',
176
- 'type' => 'ellipse',
177
- 'cx' => 100.1,
178
- 'cy' => 200.1,
179
- 'rx' => 300.1,
180
- 'ry' => 400.1,
181
- 'display' => true,
182
- 'style' => {
183
- 'border-width' => 1.0,
184
- 'border-color' => 'red',
185
- 'border-style' => 'solid',
186
- 'fill-color' => 'blue'
187
- }
188
- },
189
- layout_legacy_schema.ellipse_item_schema(legacy_attributes)
190
- )
191
- end
192
-
193
- def test_image_item_schema
194
- legacy_attributes = {
195
- 'x-id' => 'image_id',
196
- 'x' => '100.1',
197
- 'y' => '200.1',
198
- 'width' => '300.1',
199
- 'height' => '400.1',
200
- 'x-display' => 'true',
201
- 'xlink:href' => 'data:image/png;base64,xxxxxxxxxxxxx'
202
- }
203
- assert_equal(
204
- {
205
- 'id' => 'image_id',
206
- 'type' => 'image',
207
- 'x' => 100.1,
208
- 'y' => 200.1,
209
- 'width' => 300.1,
210
- 'height' => 400.1,
211
- 'display' => true,
212
- 'data' => {
213
- 'mime-type' => 'image/png',
214
- 'base64' => 'xxxxxxxxxxxxx'
215
- }
216
- },
217
- layout_legacy_schema.image_item_schema(legacy_attributes)
218
- )
219
- end
220
-
221
- def test_page_number_item_schema
222
- legacy_attributes = {
223
- 'x-id' => 'page_number_id',
224
- 'x-left' => '100.1',
225
- 'x-top' => '200.1',
226
- 'x-width' => '300.1',
227
- 'x-height' => '400.1',
228
- 'x-format' => '{page}',
229
- 'x-target' => 'report',
230
- 'x-display' => 'true',
231
- 'font-family' => 'IPAMincho',
232
- 'font-size' => '18.5',
233
- 'fill' => 'red',
234
- 'font-weight' => 'bold',
235
- 'font-style' => 'italic',
236
- 'text-decoration' => '',
237
- 'text-anchor' => 'end',
238
- 'x-overflow' => 'fit'
239
- }
240
- assert_equal(
241
- {
242
- 'id' => 'page_number_id',
243
- 'type' => 'page-number',
244
- 'x' => 100.1,
245
- 'y' => 200.1,
246
- 'width' => 300.1,
247
- 'height' => 400.1,
248
- 'format' => '{page}',
249
- 'target' => 'report',
250
- 'display' => true,
251
- 'style' => {
252
- 'font-family' => %w( IPAMincho ),
253
- 'font-size' => 18.5,
254
- 'color' => 'red',
255
- 'font-style' => %w( bold italic ),
256
- 'text-align' => 'right',
257
- 'overflow' => 'fit'
258
- }
259
- },
260
- layout_legacy_schema.page_number_item_schema(legacy_attributes)
261
- )
262
- end
263
-
264
- def test_image_block_item_schema
265
- legacy_attributes = {
266
- 'x-id' => 'image_block_id',
267
- 'x-left' => '100.1',
268
- 'x-top' => '200.1',
269
- 'x-width' => '300.1',
270
- 'x-height' => '400.1',
271
- 'x-display' => 'false',
272
- 'x-position-x' => 'right',
273
- 'x-position-y' => 'bottom'
274
- }
275
- assert_equal(
276
- {
277
- 'id' => 'image_block_id',
278
- 'type' => 'image-block',
279
- 'x' => 100.1,
280
- 'y' => 200.1,
281
- 'width' => 300.1,
282
- 'height' => 400.1,
283
- 'display' => false,
284
- 'style' => {
285
- 'position-x' => 'right',
286
- 'position-y' => 'bottom'
287
- }
288
- },
289
- layout_legacy_schema.image_block_item_schema(legacy_attributes)
290
- )
291
- end
292
-
293
- def test_text_block_schema
294
- base_legacy_attributes = {
295
- 'x-id' => 'text_block_id',
296
- 'x-left' => '100.1',
297
- 'x-top' => '200.1',
298
- 'x-width' => '300.1',
299
- 'x-height' => '400.1',
300
- 'x-display' => 'true',
301
- 'x-value' => 'default value',
302
- 'x-multiple' => 'true',
303
- 'font-family' => 'Helvetica',
304
- 'font-size' => '18',
305
- 'font-weight' => 'bold',
306
- 'font-style' => 'normal',
307
- 'text-decoration' => 'line-through',
308
- 'fill' => 'red',
309
- 'text-anchor' => 'start',
310
- 'x-valign' => 'top',
311
- 'x-line-height' => '20.1',
312
- 'kerning' => '2.1',
313
- 'x-overflow' => 'expand',
314
- 'x-word-wrap' => 'break-word',
315
- 'x-format-base' => '$ {value}',
316
- 'x-format-type' => '',
317
- 'x-ref-id' => 'other_text_block_id'
318
- }
319
- assert_equal(
320
- {
321
- 'id' => 'text_block_id',
322
- 'type' => 'text-block',
323
- 'x' => 100.1,
324
- 'y' => 200.1,
325
- 'width' => 300.1,
326
- 'height' => 400.1,
327
- 'display' => true,
328
- 'value' => 'default value',
329
- 'multiple-line' => true,
330
- 'reference-id' => 'other_text_block_id',
331
- 'format' => {
332
- 'base' => '$ {value}',
333
- 'type' => ''
334
- },
335
- 'style' => {
336
- 'font-family' => %w( Helvetica ),
337
- 'font-size' => 18.0,
338
- 'color' => 'red',
339
- 'font-style' => %w( bold linethrough ),
340
- 'text-align' => 'left',
341
- 'vertical-align' => 'top',
342
- 'line-height' => 20.1,
343
- 'letter-spacing' => 2.1,
344
- 'overflow' => 'expand',
345
- 'word-wrap' => 'break-word'
346
- }
347
- },
348
- layout_legacy_schema.text_block_item_schema(base_legacy_attributes)
349
- )
350
-
351
- schema_with_datetime_format = layout_legacy_schema.text_block_item_schema(base_legacy_attributes.merge(
352
- 'x-format-type' => 'datetime',
353
- 'x-format-datetime-format' => '%Y'
354
- ))
355
- assert_equal(
356
- {
357
- 'base' => '$ {value}',
358
- 'type' => 'datetime',
359
- 'datetime' => {
360
- 'format' => '%Y'
361
- }
362
- },
363
- schema_with_datetime_format['format']
364
- )
365
-
366
- schema_with_number_format = layout_legacy_schema.text_block_item_schema(base_legacy_attributes.merge(
367
- 'x-format-type' => 'number',
368
- 'x-format-number-precision' => '1',
369
- 'x-format-number-delimiter' => ','
370
- ))
371
- assert_equal(
372
- {
373
- 'base' => '$ {value}',
374
- 'type' => 'number',
375
- 'number' => {
376
- 'delimiter' => ',',
377
- 'precision' => 1
378
- }
379
- },
380
- schema_with_number_format['format']
381
- )
382
-
383
- schema_with_padding_format = layout_legacy_schema.text_block_item_schema(base_legacy_attributes.merge(
384
- 'x-format-type' => 'padding',
385
- 'x-format-padding-char' => '0',
386
- 'x-format-padding-length' => '10',
387
- 'x-format-padding-direction' => 'L'
388
- ))
389
- assert_equal(
390
- {
391
- 'base' => '$ {value}',
392
- 'type' => 'padding',
393
- 'padding' => {
394
- 'length' => 10,
395
- 'char' => '0',
396
- 'direction' => 'L'
397
- }
398
- },
399
- schema_with_padding_format['format']
400
- )
401
- end
402
-
403
- def test_list_item_schema
404
- legacy_schema = {
405
- 'id' => 'default',
406
- 'type' => 's-list',
407
- 'content-height' => '300',
408
- 'page-break' => 'true',
409
- 'display' => 'false',
410
- 'header-enabled' => 'false',
411
- 'page-footer-enabled' => 'true',
412
- 'footer-enabled' => 'true',
413
- 'header' => {
414
- 'height' => '100.1',
415
- 'translate' => {
416
- 'x' => '100',
417
- 'y' => '200'
418
- },
419
- 'svg' => { 'content' => '' }
420
- },
421
- 'detail' => {
422
- 'height' => '200.1',
423
- 'translate' => {
424
- 'x' => '300',
425
- 'y' => '400'
426
- },
427
- 'svg' => { 'content' => '' }
428
- },
429
- 'page-footer' => {
430
- 'height' => '300.1',
431
- 'translate' => {
432
- 'x' => '500',
433
- 'y' => '600'
434
- },
435
- 'svg' => { 'content' => '' }
436
- },
437
- 'footer' => {
438
- 'height' => '400.1',
439
- 'translate' => {
440
- 'x' => '700',
441
- 'y' => '800'
442
- },
443
- 'svg' => { 'content' => '' }
444
- }
445
- }
446
-
447
- layout_legacy_schema.stubs(:legacy_item_schemas).returns({ 'default' => legacy_schema })
448
-
449
- legacy_element = mock()
450
- legacy_element.stubs(:attributes).returns({ 'x-id' => 'default' })
451
- legacy_element.stubs(:elements).returns({})
452
-
453
- assert_equal(
454
- {
455
- 'id' => 'default',
456
- 'type' => 'list',
457
- 'content-height' => 300.0,
458
- 'auto-page-break' => true,
459
- 'display' => false,
460
- 'header' => {
461
- 'height' => 100.1,
462
- 'translate' => {
463
- 'x' => 100.0,
464
- 'y' => 200.0
465
- },
466
- 'items' => [],
467
- 'enabled' => false
468
- },
469
- 'detail' => {
470
- 'height' => 200.1,
471
- 'translate' => {
472
- 'x' => 300.0,
473
- 'y' => 400.0
474
- },
475
- 'items' => []
476
- },
477
- 'page-footer' => {
478
- 'height' => 300.1,
479
- 'translate' => {
480
- 'x' => 500.0,
481
- 'y' => 800.1
482
- },
483
- 'items' => [],
484
- 'enabled' => true
485
- },
486
- 'footer' => {
487
- 'height' => 400.1,
488
- 'translate' => {
489
- 'x' => 700.0,
490
- 'y' => 1300.2
491
- },
492
- 'items' => [],
493
- 'enabled' => true
494
- }
495
- },
496
- layout_legacy_schema.list_item_schema(legacy_element)
497
- )
498
- end
499
-
500
- def test_image_position_y
501
- assert_equal 'top', layout_legacy_schema.image_position_y('top')
502
- assert_equal 'middle', layout_legacy_schema.image_position_y('center')
503
- assert_equal 'bottom', layout_legacy_schema.image_position_y('bottom')
504
- end
505
-
506
- def test_display
507
- assert_equal true, layout_legacy_schema.display('true')
508
- assert_equal false, layout_legacy_schema.display('false')
509
- end
510
-
511
- def test_font_style
512
- no_style = {
513
- 'font-weight' => 'normal',
514
- 'font-style' => 'normal',
515
- 'text-decoration' => 'none'
516
- }
517
- assert_equal [], layout_legacy_schema.font_style(no_style)
518
- assert_equal %w( bold ), layout_legacy_schema.font_style(no_style.merge('font-weight' => 'bold'))
519
- assert_equal %w( italic ), layout_legacy_schema.font_style(no_style.merge('font-style' => 'italic'))
520
- assert_equal %w( underline ), layout_legacy_schema.font_style(no_style.merge('text-decoration' => 'underline'))
521
- assert_equal %w( linethrough ), layout_legacy_schema.font_style(no_style.merge('text-decoration' => 'line-through'))
522
- assert_equal %w( underline linethrough ), layout_legacy_schema.font_style(no_style.merge('text-decoration' => 'line-through underline'))
523
- end
524
-
525
- def test_text_align
526
- assert_equal 'left', layout_legacy_schema.text_align('start')
527
- assert_equal 'center', layout_legacy_schema.text_align('middle')
528
- assert_equal 'right', layout_legacy_schema.text_align('end')
529
- end
530
-
531
- def test_vertical_align
532
- assert_equal '', layout_legacy_schema.vertical_align(nil)
533
- assert_equal 'top', layout_legacy_schema.vertical_align('top')
534
- assert_equal 'middle', layout_legacy_schema.vertical_align('center')
535
- assert_equal 'bottom', layout_legacy_schema.vertical_align('bottom')
536
- assert_equal 'top', layout_legacy_schema.vertical_align('')
537
- end
538
-
539
- def test_line_height
540
- assert_equal '', layout_legacy_schema.line_height('')
541
- assert_equal '', layout_legacy_schema.line_height(nil)
542
- assert_equal 20.1, layout_legacy_schema.line_height('20.1')
543
- end
544
-
545
- def test_letter_spacing
546
- assert_equal '', layout_legacy_schema.letter_spacing('')
547
- assert_equal '', layout_legacy_schema.letter_spacing('auto')
548
- assert_equal 2.5, layout_legacy_schema.letter_spacing('2.5')
549
- end
550
-
551
- def test_extract_item_schemas
552
- svg = <<-SVG
553
- <!--SHAPE{"id":"item1"}SHAPE-->
554
- <!--LAYOUT<rect id="item2"/>LAYOUT-->
555
- <!--SHAPE{"id":"item3"}SHAPE-->
556
- SVG
557
- assert_equal(
558
- { 'item1' => { 'id' => 'item1' }, 'item3' => { 'id' => 'item3' } },
559
- layout_legacy_schema.extract_legacy_item_schemas(svg)
560
- )
561
- end
562
-
563
- def test_cleanup_svg
564
- svg = '<!--SHAPE{"id":"item1"}SHAPE--><!--LAYOUT<rect id="item2"/>LAYOUT--><!--SHAPE{"id":"item2"}SHAPE-->'
565
-
566
- assert_equal '<rect id="item2"/>', layout_legacy_schema.cleanup_svg(svg)
567
- end
568
-
569
- private
570
-
571
- def layout_legacy_schema
572
- @layout_legacy_schema ||= Layout::LegacySchema.new({ 'svg' => '' })
573
- end
574
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class Thinreports::Layout::TestVersion < Minitest::Test
6
- include Thinreports::TestHelper
7
-
8
- # Alias
9
- Version = Thinreports::Layout::Version
10
-
11
- def test_compatible?
12
- Version.stubs(:compatible_rules).returns(['>= 0.8.0', '< 1.0.0'])
13
-
14
- assert Version.new('0.8.0').compatible?
15
- assert Version.new('0.9.9').compatible?
16
- assert Version.new('0.10.0').compatible?
17
-
18
- refute Version.new('0.7.9').compatible?
19
- refute Version.new('1.0.0').compatible?
20
- end
21
-
22
- def test_legacy?
23
- assert Version.new('0.8.9').legacy?
24
- refute Version.new('0.9.0').legacy?
25
- end
26
- end