thinreports 0.10.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class Thinreports::Core::Shape::Style::TestBasic < Minitest::Test
|
6
|
-
include Thinreports::TestHelper
|
7
|
-
|
8
|
-
def create_basic_style(format_config = {})
|
9
|
-
format = Thinreports::Core::Shape::Basic::Format.new(format_config)
|
10
|
-
Thinreports::Core::Shape::Style::Basic.new(format)
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_visible_should_return_visibility_of_format_as_default
|
14
|
-
style = create_basic_style('display' => false)
|
15
|
-
assert_equal style.visible, false
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_visible_should_properly_set_visibility
|
19
|
-
style = create_basic_style('display' => false)
|
20
|
-
style.visible = true
|
21
|
-
|
22
|
-
assert_equal style.visible, true
|
23
|
-
end
|
24
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class Thinreports::Core::Shape::Style::TestGraphic < Minitest::Test
|
6
|
-
include Thinreports::TestHelper
|
7
|
-
|
8
|
-
def test_border_color
|
9
|
-
style = create_graphic_style('border-color' => 'red')
|
10
|
-
assert_equal 'red', style.border_color
|
11
|
-
|
12
|
-
style.border_color = '#ff0000'
|
13
|
-
assert_equal '#ff0000', style.styles['border-color']
|
14
|
-
assert_equal '#ff0000', style.border_color
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_border_width
|
18
|
-
style = create_graphic_style('border-width' => 2.0)
|
19
|
-
assert_equal 2.0, style.border_width
|
20
|
-
|
21
|
-
style.border_width = 10.9
|
22
|
-
assert_equal 10.9, style.styles['border-width']
|
23
|
-
assert_equal 10.9, style.border_width
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_fill_color
|
27
|
-
style = create_graphic_style('fill-color' => '#0000ff')
|
28
|
-
assert_equal '#0000ff', style.fill_color
|
29
|
-
|
30
|
-
style.fill_color = 'blue'
|
31
|
-
assert_equal 'blue', style.styles['fill-color']
|
32
|
-
assert_equal 'blue', style.fill_color
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_border
|
36
|
-
style = create_graphic_style('border-color' => 'red', 'border-width' => 1)
|
37
|
-
assert_equal [1, 'red'], style.border
|
38
|
-
|
39
|
-
style.border = [2.0, '#ff0000']
|
40
|
-
assert_equal 2.0, style.styles['border-width']
|
41
|
-
assert_equal '#ff0000', style.styles['border-color']
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def create_graphic_style(default_style = {})
|
47
|
-
format = Thinreports::Core::Shape::Basic::Format.new('style' => default_style)
|
48
|
-
Thinreports::Core::Shape::Style::Graphic.new(format)
|
49
|
-
end
|
50
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class Thinreports::Core::Shape::Style::TestText < Minitest::Test
|
6
|
-
include Thinreports::TestHelper
|
7
|
-
|
8
|
-
def test_color
|
9
|
-
style = create_text_style('color' => 'red')
|
10
|
-
assert_equal 'red', style.color
|
11
|
-
|
12
|
-
style.color = 'blue'
|
13
|
-
assert_equal 'blue', style.styles['color']
|
14
|
-
assert_equal 'blue', style.color
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_font_size
|
18
|
-
style = create_text_style('font-size' => 18.0)
|
19
|
-
assert_equal 18.0, style.font_size
|
20
|
-
|
21
|
-
style.font_size = 19
|
22
|
-
assert_equal 19, style.styles['font-size']
|
23
|
-
assert_equal 19, style.font_size
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_initialize_font_style
|
27
|
-
default_font_style = ['bold', 'italic']
|
28
|
-
style = create_text_style('font-style' => default_font_style)
|
29
|
-
|
30
|
-
refute_same default_font_style, style.styles['font-style']
|
31
|
-
assert_equal default_font_style, style.styles['font-style']
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_bold
|
35
|
-
style = create_text_style('font-style' => ['bold'])
|
36
|
-
assert_equal true, style.bold
|
37
|
-
|
38
|
-
style.bold = false
|
39
|
-
assert_equal [], style.styles['font-style']
|
40
|
-
assert_equal false, style.bold
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_italic
|
44
|
-
style = create_text_style('font-style' => ['italic'])
|
45
|
-
assert_equal true, style.italic
|
46
|
-
|
47
|
-
style.italic = false
|
48
|
-
assert_equal [], style.styles['font-style']
|
49
|
-
assert_equal false, style.italic
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_underline
|
53
|
-
style = create_text_style('font-style' => ['underline'])
|
54
|
-
assert_equal true, style.underline
|
55
|
-
|
56
|
-
style.underline = false
|
57
|
-
assert_equal [], style.styles['font-style']
|
58
|
-
assert_equal false, style.underline
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_linethrough
|
62
|
-
style = create_text_style('font-style' => ['linethrough'])
|
63
|
-
assert_equal true, style.linethrough
|
64
|
-
|
65
|
-
style.linethrough = false
|
66
|
-
assert_equal [], style.styles['font-style']
|
67
|
-
assert_equal false, style.linethrough
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_align
|
71
|
-
style = create_text_style('text-align' => 'center')
|
72
|
-
assert_equal :center, style.align
|
73
|
-
|
74
|
-
style.align = :right
|
75
|
-
assert_equal 'right', style.styles['text-align']
|
76
|
-
assert_equal :right, style.align
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_valign
|
80
|
-
style = create_text_style('vertical-align' => '')
|
81
|
-
assert_equal :top, style.valign
|
82
|
-
|
83
|
-
style.valign = :middle
|
84
|
-
assert_equal 'middle', style.styles['vertical-align']
|
85
|
-
assert_equal :middle, style.valign
|
86
|
-
|
87
|
-
assert_deprecated { style.valign = :center }
|
88
|
-
assert_equal :middle, style.valign
|
89
|
-
end
|
90
|
-
|
91
|
-
private
|
92
|
-
|
93
|
-
def create_text_style(default_style = {})
|
94
|
-
format = Thinreports::Core::Shape::Text::Format.new('style' => default_style)
|
95
|
-
Thinreports::Core::Shape::Style::Text.new(format)
|
96
|
-
end
|
97
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class Thinreports::Core::Shape::Text::TestFormat < Minitest::Test
|
6
|
-
include Thinreports::TestHelper
|
7
|
-
|
8
|
-
TEXT_FORMAT = {
|
9
|
-
'id' => 'text_1',
|
10
|
-
'type' => 'text',
|
11
|
-
'x' => 100.0,
|
12
|
-
'y' => 200.0,
|
13
|
-
'width' => 300.0,
|
14
|
-
'height' => 400.0,
|
15
|
-
'description' => 'Description for item',
|
16
|
-
'display' => true,
|
17
|
-
'texts' => [
|
18
|
-
'1st text line',
|
19
|
-
'2nd text line'
|
20
|
-
],
|
21
|
-
'valign' => 'top',
|
22
|
-
'style' => {
|
23
|
-
'font-family' => ['Arial'],
|
24
|
-
'font-size' => 12,
|
25
|
-
'color' => '#000000',
|
26
|
-
'font-style' => ['bold', 'italic', 'linethrough', 'underline'],
|
27
|
-
'text-align' => 'left',
|
28
|
-
'vertical-align' => 'top',
|
29
|
-
'line-height' => 60,
|
30
|
-
'line-height-ratio' => 1.5,
|
31
|
-
'letter-spacing' => 'normal'
|
32
|
-
}
|
33
|
-
}
|
34
|
-
|
35
|
-
Text = Thinreports::Core::Shape::Text
|
36
|
-
|
37
|
-
def test_attribute_readers
|
38
|
-
format = Text::Format.new(TEXT_FORMAT)
|
39
|
-
|
40
|
-
assert_equal TEXT_FORMAT['texts'], format.texts
|
41
|
-
assert_equal 'top', format.valign
|
42
|
-
assert_equal 60, format.line_height
|
43
|
-
end
|
44
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class Thinreports::Core::Shape::Text::TestInternal < Minitest::Test
|
6
|
-
include Thinreports::TestHelper
|
7
|
-
|
8
|
-
Text = Thinreports::Core::Shape::Text
|
9
|
-
|
10
|
-
def create_internal(format_config = {})
|
11
|
-
report = Thinreports::Report.new layout: layout_file.path
|
12
|
-
Text::Internal.new(report.start_new_page, Text::Format.new(format_config))
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_type_of?
|
16
|
-
assert create_internal.type_of?('text'), true
|
17
|
-
refute create_internal.type_of?(:basic), false
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class Thinreports::Core::Shape::TextBlock::Formatter::TestBasic < Minitest::Test
|
6
|
-
include Thinreports::TestHelper
|
7
|
-
|
8
|
-
# Alias
|
9
|
-
Formatter = Thinreports::Core::Shape::TextBlock::Formatter::Basic
|
10
|
-
|
11
|
-
def test_apply_simple_format
|
12
|
-
format = stub(format_base: 'Hello {value}!')
|
13
|
-
|
14
|
-
assert_equal Formatter.new(format).apply('Thinreports'),
|
15
|
-
'Hello Thinreports!'
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_apply_multiple_format
|
19
|
-
format = stub(format_base: 'Hello {value}! And good bye {value}.')
|
20
|
-
|
21
|
-
assert_equal Formatter.new(format).apply('Thinreports'),
|
22
|
-
'Hello Thinreports! And good bye Thinreports.'
|
23
|
-
end
|
24
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class Thinreports::Core::Shape::TextBlock::Formatter::TestDatetime < Minitest::Test
|
6
|
-
include Thinreports::TestHelper
|
7
|
-
|
8
|
-
# Aliases
|
9
|
-
TextBlock = Thinreports::Core::Shape::TextBlock
|
10
|
-
Formatter = TextBlock::Formatter::Datetime
|
11
|
-
|
12
|
-
def setup
|
13
|
-
@datetime_format = '%Y/%m/%d %H:%M:%S'
|
14
|
-
@time = Time.now
|
15
|
-
end
|
16
|
-
|
17
|
-
def text_block_format(format = {})
|
18
|
-
default = {'base' => '', 'datetime' => {'format' => '%Y/%m/%d %H:%M:%S'}}
|
19
|
-
TextBlock::Format.new('format' => default.merge(format))
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_apply_datetime_format_without_basic_format
|
23
|
-
formatter = Formatter.new(text_block_format)
|
24
|
-
|
25
|
-
assert_equal @time.strftime(@datetime_format),
|
26
|
-
formatter.apply(@time)
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_apply_datetime_format_with_basic_format
|
30
|
-
formatter = Formatter.new(text_block_format('base' => 'Now: {value}'))
|
31
|
-
|
32
|
-
assert_equal "Now: #{@time.strftime(@datetime_format)}",
|
33
|
-
formatter.apply(@time)
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_not_apply_datetime_format_and_return_raw_value
|
38
|
-
# When value is invalid
|
39
|
-
formatter = Formatter.new(text_block_format)
|
40
|
-
|
41
|
-
assert_same formatter.apply(val = 'invalid value'), val
|
42
|
-
assert_same formatter.apply(val = 123456), val
|
43
|
-
|
44
|
-
# When format is empty
|
45
|
-
formatter = Formatter.new(text_block_format('datetime' => {'format' => ''}))
|
46
|
-
|
47
|
-
assert_same formatter.apply(@time), @time
|
48
|
-
end
|
49
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class Thinreports::Core::Shape::TextBlock::Formatter::TestNumber < Minitest::Test
|
6
|
-
include Thinreports::TestHelper
|
7
|
-
|
8
|
-
# Alias
|
9
|
-
Formatter = Thinreports::Core::Shape::TextBlock::Formatter::Number
|
10
|
-
|
11
|
-
def init_formatter(expect_formats)
|
12
|
-
format = stub({ format_base: '',
|
13
|
-
format_number_precision: nil,
|
14
|
-
format_number_delimiter: nil }.merge(expect_formats))
|
15
|
-
Formatter.new(format)
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_apply_precision_formats
|
19
|
-
# When precision is 2
|
20
|
-
formatter = init_formatter(format_number_precision: 2)
|
21
|
-
|
22
|
-
assert_equal formatter.apply(1.005), '1.01'
|
23
|
-
assert_equal formatter.apply(1.004), '1.00'
|
24
|
-
assert_equal formatter.apply(1), '1.00'
|
25
|
-
# With String value
|
26
|
-
assert_equal formatter.apply('999.999'), '1000.00'
|
27
|
-
assert_equal formatter.apply('-999.999'), '-1000.00'
|
28
|
-
assert_equal formatter.apply('9'), '9.00'
|
29
|
-
# Cannot apply, Return the raw value
|
30
|
-
assert_equal formatter.apply('invalid value'), 'invalid value'
|
31
|
-
|
32
|
-
# When precision is 0
|
33
|
-
formatter = init_formatter(format_number_precision: 0)
|
34
|
-
|
35
|
-
assert_equal formatter.apply(1.5), '2'
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_apply_precision_format_with_basic_format
|
39
|
-
formatter = init_formatter(format_base: '$ {value}',
|
40
|
-
format_number_precision: 0)
|
41
|
-
|
42
|
-
assert_equal formatter.apply(199.5), '$ 200'
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_apply_delimiter_formats
|
46
|
-
# When delimiter is ','
|
47
|
-
formatter = init_formatter(format_number_delimiter: ',')
|
48
|
-
|
49
|
-
assert_equal formatter.apply(1000000), '1,000,000'
|
50
|
-
assert_equal formatter.apply(-1000000), '-1,000,000'
|
51
|
-
assert_equal formatter.apply('1000.0'), '1,000.0'
|
52
|
-
assert_equal formatter.apply('-1000.0'), '-1,000.0'
|
53
|
-
# Cannot apply, Return the raw value
|
54
|
-
assert_equal formatter.apply('invalid value'), 'invalid value'
|
55
|
-
|
56
|
-
# When delimiter is whitespace
|
57
|
-
formatter = init_formatter(format_number_delimiter: ' ')
|
58
|
-
|
59
|
-
assert_equal formatter.apply(99999), '99 999'
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_apply_delimiter_format_with_basic_format
|
63
|
-
formatter = init_formatter(format_base: '¥{value}',
|
64
|
-
format_number_delimiter: ',')
|
65
|
-
|
66
|
-
assert_equal formatter.apply(199800), '¥199,800'
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_apply_all_format
|
70
|
-
formatter = init_formatter(format_base: '-- {value} --',
|
71
|
-
format_number_delimiter: ',',
|
72
|
-
format_number_precision: 2)
|
73
|
-
|
74
|
-
assert_equal formatter.apply(95618.88567), '-- 95,618.89 --'
|
75
|
-
end
|
76
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class Thinreports::Core::Shape::TextBlock::Formatter::TestPadding < Minitest::Test
|
6
|
-
include Thinreports::TestHelper
|
7
|
-
|
8
|
-
# Alias
|
9
|
-
Formatter = Thinreports::Core::Shape::TextBlock::Formatter::Padding
|
10
|
-
|
11
|
-
def init_formatter(expect_formats)
|
12
|
-
format = stub({ format_base: nil,
|
13
|
-
format_padding_length: 0,
|
14
|
-
format_padding_char: nil,
|
15
|
-
format_padding_rdir?: false }.merge(expect_formats))
|
16
|
-
Formatter.new(format)
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_apply_padding_formats_with_left_direction
|
20
|
-
formatter = init_formatter(format_padding_length: 5,
|
21
|
-
format_padding_char: '0')
|
22
|
-
|
23
|
-
assert_equal formatter.apply(1), '00001'
|
24
|
-
assert_equal formatter.apply('日本語'), '00日本語'
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_apply_padding_formats_should_not_apply_when_character_length_is_short
|
28
|
-
formatter = init_formatter(format_padding_length: 5,
|
29
|
-
format_padding_char: '0')
|
30
|
-
|
31
|
-
assert_equal formatter.apply('1234567'), '1234567'
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_apply_padding_formats_with_right_direction
|
35
|
-
formatter = init_formatter(format_padding_length: 5,
|
36
|
-
format_padding_char: '0',
|
37
|
-
:format_padding_rdir? => true)
|
38
|
-
|
39
|
-
assert_equal formatter.apply(123), '12300'
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_apply_padding_format_with_basic_format
|
43
|
-
formatter = init_formatter(format_base: '[{value}]',
|
44
|
-
format_padding_length: 10,
|
45
|
-
format_padding_char: ' ')
|
46
|
-
|
47
|
-
assert_equal formatter.apply('ABC'), '[ ABC]'
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_return_raw_value_when_length_is_0
|
51
|
-
formatter = init_formatter(format_padding_length: 0,
|
52
|
-
format_padding_char: '0')
|
53
|
-
|
54
|
-
assert_same formatter.apply(v = 123), v
|
55
|
-
|
56
|
-
# But apply only basic format if have basic-format.
|
57
|
-
formatter = init_formatter(format_base: '<{value}>',
|
58
|
-
format_padding_length: 0,
|
59
|
-
format_padding_char: '0')
|
60
|
-
|
61
|
-
assert_equal formatter.apply(123), '<123>'
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_return_raw_value_when_char_is_empty
|
65
|
-
formatter = init_formatter(format_padding_length: 10,
|
66
|
-
format_padding_char: '')
|
67
|
-
|
68
|
-
assert_same formatter.apply(v = '1'), v
|
69
|
-
|
70
|
-
# But apply only basic format if have basic-format.
|
71
|
-
formatter = init_formatter(format_base: '<{value}>',
|
72
|
-
format_padding_length: 0,
|
73
|
-
format_padding_char: '0')
|
74
|
-
|
75
|
-
assert_equal formatter.apply('1'), '<1>'
|
76
|
-
end
|
77
|
-
end
|