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.
- checksums.yaml +5 -5
- data/.github/CONTRIBUTING.md +2 -2
- data/.github/workflows/test.yml +51 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +49 -0
- data/Dockerfile +12 -0
- data/Gemfile +2 -1
- data/README.md +46 -21
- data/Rakefile +13 -29
- 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.rb +5 -0
- data/lib/thinreports/core/shape.rb +4 -3
- data/lib/thinreports/core/shape/base/interface.rb +0 -1
- 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/list/manager.rb +1 -4
- data/lib/thinreports/core/shape/list/page.rb +2 -5
- data/lib/thinreports/core/shape/manager/internal.rb +0 -1
- data/lib/thinreports/core/shape/page_number.rb +1 -1
- data/lib/thinreports/core/shape/page_number/internal.rb +0 -1
- data/lib/thinreports/core/shape/stack_view.rb +17 -0
- 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/style/basic.rb +4 -1
- data/lib/thinreports/core/shape/text.rb +1 -1
- data/lib/thinreports/core/shape/text_block.rb +1 -1
- data/lib/thinreports/core/shape/text_block/formatter/number.rb +21 -9
- data/lib/thinreports/core/shape/text_block/internal.rb +0 -2
- data/lib/thinreports/core/utils.rb +6 -3
- data/lib/thinreports/generate.rb +11 -0
- data/lib/thinreports/generator/pdf/document/draw_shape.rb +31 -11
- data/lib/thinreports/generator/pdf/document/draw_template_items.rb +1 -2
- data/lib/thinreports/generator/pdf/document/font.rb +16 -10
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +0 -1
- data/lib/thinreports/generator/pdf/document/graphics/basic.rb +0 -1
- data/lib/thinreports/generator/pdf/document/graphics/image.rb +19 -1
- data/lib/thinreports/generator/pdf/document/graphics/text.rb +10 -8
- data/lib/thinreports/generator/pdf/document/page.rb +13 -4
- data/lib/thinreports/generator/pdf/drawer/list.rb +0 -1
- data/lib/thinreports/generator/pdf/prawn_ext/calc_image_dimensions.rb +1 -3
- data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +7 -7
- data/lib/thinreports/layout/base.rb +2 -4
- data/lib/thinreports/layout/format.rb +0 -1
- data/lib/thinreports/layout/legacy_schema.rb +2 -6
- data/lib/thinreports/layout/version.rb +1 -1
- data/lib/thinreports/report/internal.rb +4 -4
- data/lib/thinreports/report/page.rb +2 -7
- 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 +55 -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/headers_renderer.rb +24 -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/thinreports.gemspec +11 -11
- metadata +48 -164
- data/.rubocop.yml +0 -41
- data/.travis.yml +0 -17
- 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 -82
- 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 -84
- 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,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
|