thinreports 0.10.2 → 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/CONTRIBUTING.md +2 -2
- data/.github/dependabot.yml +11 -0
- data/.github/workflows/test.yml +50 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +43 -0
- data/Gemfile +2 -1
- data/{MIT-LICENSE → LICENSE.txt} +2 -0
- data/README.md +70 -56
- data/Rakefile +12 -25
- data/gemfiles/prawn-2.2.gemfile +5 -0
- data/gemfiles/prawn-2.3.gemfile +5 -0
- data/gemfiles/prawn-2.4.gemfile +5 -0
- data/lib/thinreports/core/shape/basic/format.rb +5 -0
- data/lib/thinreports/core/shape/image_block.rb +1 -1
- data/lib/thinreports/core/shape/list.rb +1 -1
- data/lib/thinreports/core/shape/page_number.rb +1 -1
- data/lib/thinreports/core/shape/stack_view/format.rb +27 -0
- data/lib/thinreports/core/shape/stack_view/interface.rb +17 -0
- data/lib/thinreports/core/shape/stack_view/internal.rb +22 -0
- data/lib/thinreports/core/shape/stack_view/row_format.rb +39 -0
- data/lib/thinreports/core/shape/stack_view.rb +17 -0
- data/lib/thinreports/core/shape/style/basic.rb +4 -1
- data/lib/thinreports/core/shape/text.rb +1 -1
- data/lib/thinreports/core/shape/text_block/formatter/number.rb +6 -1
- data/lib/thinreports/core/shape/text_block/internal.rb +0 -2
- data/lib/thinreports/core/shape/text_block.rb +1 -1
- data/lib/thinreports/core/shape.rb +2 -0
- data/lib/thinreports/generate.rb +11 -0
- data/lib/thinreports/generator/pdf/document/draw_shape.rb +31 -10
- data/lib/thinreports/generator/pdf/document/draw_template_items.rb +1 -1
- data/lib/thinreports/generator/pdf/document/graphics/image.rb +19 -1
- data/lib/thinreports/generator/pdf/document/graphics/text.rb +10 -5
- data/lib/thinreports/generator/pdf/document/page.rb +12 -0
- data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +7 -7
- data/lib/thinreports/layout/base.rb +1 -1
- data/lib/thinreports/layout/legacy_schema.rb +1 -0
- data/lib/thinreports/layout/version.rb +1 -1
- data/lib/thinreports/report/internal.rb +2 -0
- data/lib/thinreports/report.rb +2 -2
- data/lib/thinreports/section_report/build.rb +32 -0
- data/lib/thinreports/section_report/builder/item_builder.rb +49 -0
- data/lib/thinreports/section_report/builder/report_builder.rb +82 -0
- data/lib/thinreports/section_report/builder/report_data.rb +13 -0
- data/lib/thinreports/section_report/builder/stack_view_builder.rb +53 -0
- data/lib/thinreports/section_report/builder/stack_view_data.rb +11 -0
- data/lib/thinreports/section_report/generate.rb +26 -0
- data/lib/thinreports/section_report/pdf/render.rb +23 -0
- data/lib/thinreports/section_report/pdf/renderer/draw_item.rb +68 -0
- data/lib/thinreports/section_report/pdf/renderer/group_renderer.rb +57 -0
- data/lib/thinreports/section_report/pdf/renderer/section_height.rb +100 -0
- data/lib/thinreports/section_report/pdf/renderer/section_renderer.rb +39 -0
- data/lib/thinreports/section_report/pdf/renderer/stack_view_renderer.rb +55 -0
- data/lib/thinreports/section_report/pdf/renderer/stack_view_row_renderer.rb +38 -0
- data/lib/thinreports/section_report/schema/loader.rb +28 -0
- data/lib/thinreports/section_report/schema/parser.rb +52 -0
- data/lib/thinreports/section_report/schema/report.rb +30 -0
- data/lib/thinreports/section_report/schema/section.rb +47 -0
- data/lib/thinreports/version.rb +1 -1
- data/lib/thinreports.rb +5 -0
- data/thinreports.gemspec +11 -10
- metadata +48 -150
- data/.travis.yml +0 -16
- data/examples/character_spacing/character_spacing.rb +0 -8
- data/examples/character_spacing/character_spacing.tlf +0 -293
- data/examples/dynamic_image/dynamic_image.rb +0 -31
- data/examples/dynamic_image/dynamic_image.tlf +0 -661
- data/examples/dynamic_image/img200x100.png +0 -0
- data/examples/dynamic_image/img50x50.png +0 -0
- data/examples/dynamic_style/dynamic_style.rb +0 -150
- data/examples/dynamic_style/dynamic_style.tlf +0 -1835
- data/examples/dynamic_style/dynamic_style_in_list.tlf +0 -344
- data/examples/dynamic_style/image.png +0 -0
- data/examples/eudc/eudc.rb +0 -20
- data/examples/eudc/eudc.tlf +0 -180
- data/examples/eudc/eudc.ttf +0 -0
- data/examples/helper.rb +0 -50
- data/examples/hidden_shapes/hidden_shapes.rb +0 -9
- data/examples/hidden_shapes/hidden_shapes.tlf +0 -449
- data/examples/list_events/list_events.rb +0 -32
- data/examples/list_events/list_events.tlf +0 -361
- data/examples/list_manual_generation/list_manual_generation.rb +0 -22
- data/examples/list_manual_generation/list_manual_generation.tlf +0 -132
- data/examples/list_page_number/list_page_number.rb +0 -17
- data/examples/list_page_number/list_page_number.tlf +0 -254
- data/examples/page_number/page_number.rb +0 -33
- data/examples/page_number/page_number.tlf +0 -215
- data/examples/palleted_png/palleted_png.png +0 -0
- data/examples/palleted_png/palleted_png.rb +0 -9
- data/examples/palleted_png/palleted_png.tlf +0 -47
- data/examples/password_setting/password_setting.rb +0 -10
- data/examples/password_setting/password_setting.tlf +0 -45
- data/examples/report_callbacks/report_callbacks.rb +0 -14
- data/examples/report_callbacks/report_callbacks.tlf +0 -147
- data/examples/single_line_tblock/single_line_tblock.rb +0 -13
- data/examples/single_line_tblock/single_line_tblock.tlf +0 -170
- data/examples/tblock_overflow/tblock_overflow.rb +0 -20
- data/examples/tblock_overflow/tblock_overflow.tlf +0 -538
- data/examples/tblock_styles/font_size.tlf +0 -383
- data/examples/tblock_styles/tblock_styles.rb +0 -43
- data/examples/tblock_styles/tblock_styles.tlf +0 -889
- data/examples/text_align/text_align.rb +0 -8
- data/examples/text_align/text_align.tlf +0 -241
- data/examples/typeB_page_size/B4_ISO.tlf +0 -45
- data/examples/typeB_page_size/B4_JIS.tlf +0 -45
- data/examples/typeB_page_size/typeB_page_size.rb +0 -17
- data/examples/word_wrap/word_wrap.rb +0 -26
- data/examples/word_wrap/word_wrap.tlf +0 -297
- data/test/data/font.ttf +0 -0
- data/test/data/image_normal.jpg +0 -0
- data/test/data/image_normal.png +0 -0
- data/test/data/image_normal_jpg_noext +0 -0
- data/test/data/image_normal_png_noext +0 -0
- data/test/data/image_pallete_based.png +0 -0
- data/test/data/legacy_layout/all-items.tlf +0 -1
- data/test/schema_helper.rb +0 -122
- data/test/test_helper.rb +0 -48
- data/test/tmp/.gitkeep +0 -0
- data/test/unit/core/format/test_base.rb +0 -152
- data/test/unit/core/shape/base/test_internal.rb +0 -87
- data/test/unit/core/shape/basic/test_block_format.rb +0 -23
- data/test/unit/core/shape/basic/test_block_interface.rb +0 -29
- data/test/unit/core/shape/basic/test_block_internal.rb +0 -55
- data/test/unit/core/shape/basic/test_format.rb +0 -37
- data/test/unit/core/shape/basic/test_interface.rb +0 -108
- data/test/unit/core/shape/basic/test_internal.rb +0 -55
- data/test/unit/core/shape/image_block/test_interface.rb +0 -24
- data/test/unit/core/shape/image_block/test_internal.rb +0 -31
- data/test/unit/core/shape/list/test_format.rb +0 -111
- data/test/unit/core/shape/list/test_manager.rb +0 -67
- data/test/unit/core/shape/list/test_page.rb +0 -156
- data/test/unit/core/shape/list/test_page_state.rb +0 -31
- data/test/unit/core/shape/list/test_section_format.rb +0 -36
- data/test/unit/core/shape/list/test_section_interface.rb +0 -75
- data/test/unit/core/shape/list/test_section_internal.rb +0 -50
- data/test/unit/core/shape/manager/test_format.rb +0 -38
- data/test/unit/core/shape/manager/test_internal.rb +0 -132
- data/test/unit/core/shape/manager/test_target.rb +0 -140
- data/test/unit/core/shape/page_number/test_format.rb +0 -55
- data/test/unit/core/shape/page_number/test_interface.rb +0 -33
- data/test/unit/core/shape/page_number/test_internal.rb +0 -81
- data/test/unit/core/shape/styles/test_base.rb +0 -191
- data/test/unit/core/shape/styles/test_basic.rb +0 -24
- data/test/unit/core/shape/styles/test_graphic.rb +0 -50
- data/test/unit/core/shape/styles/test_text.rb +0 -97
- data/test/unit/core/shape/text/test_format.rb +0 -44
- data/test/unit/core/shape/text/test_internal.rb +0 -20
- data/test/unit/core/shape/text_block/formatter/test_basic.rb +0 -24
- data/test/unit/core/shape/text_block/formatter/test_datetime.rb +0 -49
- data/test/unit/core/shape/text_block/formatter/test_number.rb +0 -76
- data/test/unit/core/shape/text_block/formatter/test_padding.rb +0 -77
- data/test/unit/core/shape/text_block/test_format.rb +0 -169
- data/test/unit/core/shape/text_block/test_formatter.rb +0 -28
- data/test/unit/core/shape/text_block/test_interface.rb +0 -63
- data/test/unit/core/shape/text_block/test_internal.rb +0 -128
- data/test/unit/core/test_shape.rb +0 -52
- data/test/unit/core/test_utils.rb +0 -68
- data/test/unit/generator/pdf/document/graphics/test_attributes.rb +0 -135
- data/test/unit/generator/pdf/document/graphics/test_basic.rb +0 -46
- data/test/unit/generator/pdf/document/graphics/test_image.rb +0 -46
- data/test/unit/generator/pdf/document/graphics/test_text.rb +0 -171
- data/test/unit/generator/pdf/document/test_font.rb +0 -110
- data/test/unit/generator/pdf/document/test_graphics.rb +0 -42
- data/test/unit/generator/pdf/document/test_page.rb +0 -122
- data/test/unit/generator/pdf/document/test_parse_color.rb +0 -30
- data/test/unit/generator/pdf/prawn_ext/test_calc_image_dimensions.rb +0 -41
- data/test/unit/generator/pdf/prawn_ext/test_width_of.rb +0 -22
- data/test/unit/generator/pdf/test_document.rb +0 -22
- data/test/unit/generator/test_pdf.rb +0 -26
- data/test/unit/layout/test_base.rb +0 -41
- data/test/unit/layout/test_format.rb +0 -100
- data/test/unit/layout/test_legacy_schema.rb +0 -574
- data/test/unit/layout/test_version.rb +0 -26
- data/test/unit/report/test_base.rb +0 -248
- data/test/unit/report/test_internal.rb +0 -206
- data/test/unit/test_config.rb +0 -36
- data/test/unit/test_layout.rb +0 -12
- 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
|