thinreports 0.9.1 → 0.11.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/workflows/test.yml +39 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +59 -2
- data/Dockerfile +12 -0
- data/Gemfile +7 -4
- data/README.md +44 -22
- data/Rakefile +14 -31
- data/lib/thinreports.rb +16 -15
- data/lib/thinreports/config.rb +2 -24
- data/lib/thinreports/core/errors.rb +6 -17
- data/lib/thinreports/core/format/base.rb +62 -61
- data/lib/thinreports/core/shape.rb +10 -12
- data/lib/thinreports/core/shape/base.rb +3 -12
- data/lib/thinreports/core/shape/base/interface.rb +34 -32
- data/lib/thinreports/core/shape/base/internal.rb +45 -43
- data/lib/thinreports/core/shape/basic.rb +12 -12
- data/lib/thinreports/core/shape/basic/block_format.rb +8 -6
- data/lib/thinreports/core/shape/basic/block_interface.rb +24 -22
- data/lib/thinreports/core/shape/basic/block_internal.rb +28 -26
- data/lib/thinreports/core/shape/basic/format.rb +11 -9
- data/lib/thinreports/core/shape/basic/interface.rb +79 -77
- data/lib/thinreports/core/shape/basic/internal.rb +17 -14
- data/lib/thinreports/core/shape/image_block.rb +9 -9
- data/lib/thinreports/core/shape/image_block/format.rb +7 -5
- data/lib/thinreports/core/shape/image_block/interface.rb +15 -13
- data/lib/thinreports/core/shape/image_block/internal.rb +10 -8
- data/lib/thinreports/core/shape/list.rb +13 -13
- data/lib/thinreports/core/shape/list/format.rb +83 -77
- data/lib/thinreports/core/shape/list/manager.rb +179 -176
- data/lib/thinreports/core/shape/list/page.rb +91 -93
- data/lib/thinreports/core/shape/list/page_state.rb +42 -40
- data/lib/thinreports/core/shape/list/section_format.rb +28 -26
- data/lib/thinreports/core/shape/list/section_interface.rb +42 -40
- data/lib/thinreports/core/shape/list/section_internal.rb +21 -19
- data/lib/thinreports/core/shape/manager.rb +4 -13
- data/lib/thinreports/core/shape/manager/format.rb +21 -19
- data/lib/thinreports/core/shape/manager/internal.rb +87 -84
- data/lib/thinreports/core/shape/manager/target.rb +93 -95
- data/lib/thinreports/core/shape/page_number.rb +9 -9
- data/lib/thinreports/core/shape/page_number/format.rb +20 -18
- data/lib/thinreports/core/shape/page_number/interface.rb +20 -18
- data/lib/thinreports/core/shape/page_number/internal.rb +46 -44
- data/lib/thinreports/core/shape/style.rb +5 -14
- data/lib/thinreports/core/shape/style/base.rb +121 -120
- data/lib/thinreports/core/shape/style/basic.rb +12 -10
- data/lib/thinreports/core/shape/style/graphic.rb +35 -33
- data/lib/thinreports/core/shape/style/text.rb +113 -107
- data/lib/thinreports/core/shape/text.rb +9 -9
- data/lib/thinreports/core/shape/text/format.rb +10 -9
- data/lib/thinreports/core/shape/text/interface.rb +13 -11
- data/lib/thinreports/core/shape/text/internal.rb +14 -12
- data/lib/thinreports/core/shape/text_block.rb +10 -10
- data/lib/thinreports/core/shape/text_block/format.rb +35 -33
- data/lib/thinreports/core/shape/text_block/formatter.rb +26 -24
- data/lib/thinreports/core/shape/text_block/formatter/basic.rb +25 -25
- data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +15 -12
- data/lib/thinreports/core/shape/text_block/formatter/number.rb +52 -34
- data/lib/thinreports/core/shape/text_block/formatter/padding.rb +17 -14
- data/lib/thinreports/core/shape/text_block/interface.rb +25 -23
- data/lib/thinreports/core/shape/text_block/internal.rb +66 -68
- data/lib/thinreports/core/utils.rb +7 -3
- data/lib/thinreports/generator/pdf.rb +24 -25
- data/lib/thinreports/generator/pdf/document.rb +109 -110
- data/lib/thinreports/generator/pdf/document/draw_shape.rb +57 -51
- data/lib/thinreports/generator/pdf/document/draw_template_items.rb +50 -47
- data/lib/thinreports/generator/pdf/document/font.rb +67 -58
- data/lib/thinreports/generator/pdf/document/graphics.rb +32 -33
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +121 -121
- data/lib/thinreports/generator/pdf/document/graphics/basic.rb +112 -114
- data/lib/thinreports/generator/pdf/document/graphics/image.rb +58 -150
- data/lib/thinreports/generator/pdf/document/graphics/text.rb +149 -137
- data/lib/thinreports/generator/pdf/document/page.rb +60 -64
- data/lib/thinreports/generator/pdf/document/parse_color.rb +37 -37
- data/lib/thinreports/generator/pdf/drawer/base.rb +41 -41
- data/lib/thinreports/generator/pdf/drawer/list.rb +56 -54
- data/lib/thinreports/generator/pdf/drawer/list_section.rb +42 -40
- data/lib/thinreports/generator/pdf/drawer/page.rb +101 -96
- data/lib/thinreports/generator/pdf/prawn_ext.rb +4 -30
- data/lib/thinreports/generator/pdf/prawn_ext/calc_image_dimensions.rb +32 -0
- data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +35 -0
- data/lib/thinreports/layout.rb +5 -7
- data/lib/thinreports/layout/base.rb +5 -9
- data/lib/thinreports/layout/format.rb +17 -13
- data/lib/thinreports/layout/legacy_schema.rb +17 -13
- data/lib/thinreports/layout/version.rb +22 -25
- data/lib/thinreports/report.rb +4 -6
- data/lib/thinreports/report/base.rb +24 -51
- data/lib/thinreports/report/internal.rb +13 -15
- data/lib/thinreports/report/page.rb +5 -11
- data/lib/thinreports/version.rb +2 -2
- data/thinreports.gemspec +10 -19
- metadata +13 -288
- data/.travis.yml +0 -19
- 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 -11
- 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/lib/thinreports/generator.rb +0 -29
- data/lib/thinreports/generator/base.rb +0 -40
- data/lib/thinreports/generator/configuration.rb +0 -31
- data/lib/thinreports/report/events.rb +0 -32
- 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 -121
- data/test/test_helper.rb +0 -42
- 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 -45
- data/test/unit/generator/pdf/document/graphics/test_image.rb +0 -150
- 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/test_document.rb +0 -20
- data/test/unit/generator/test_base.rb +0 -40
- data/test/unit/generator/test_configuration.rb +0 -21
- data/test/unit/generator/test_pdf.rb +0 -24
- 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 -95
- data/test/unit/report/test_base.rb +0 -262
- data/test/unit/report/test_internal.rb +0 -206
- data/test/unit/test_config.rb +0 -51
- data/test/unit/test_layout.rb +0 -12
- data/test/unit/test_report.rb +0 -18
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
# coding: utf-8
|
|
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
|
-
# coding: utf-8
|
|
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
|
-
# coding: utf-8
|
|
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
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
# coding: utf-8
|
|
2
|
-
|
|
3
|
-
require 'test_helper'
|
|
4
|
-
|
|
5
|
-
class Thinreports::Core::Shape::TextBlock::TestFormat < Minitest::Test
|
|
6
|
-
include Thinreports::TestHelper
|
|
7
|
-
|
|
8
|
-
TEXT_BLOCK_FORMAT = {
|
|
9
|
-
'id' => 'text_block',
|
|
10
|
-
'reference-id' => 'referenced_text_block',
|
|
11
|
-
'type' => 'text-block',
|
|
12
|
-
'display' => true,
|
|
13
|
-
'multiple-line' => false,
|
|
14
|
-
'x' => 100.0,
|
|
15
|
-
'y' => 200.0,
|
|
16
|
-
'width' => 300.0,
|
|
17
|
-
'height' => 400.0,
|
|
18
|
-
'value' => 'default value',
|
|
19
|
-
'format' => {
|
|
20
|
-
'base' => 'Price: {value}',
|
|
21
|
-
'type' => 'number',
|
|
22
|
-
'number' => {
|
|
23
|
-
'delimiter' => ',',
|
|
24
|
-
'precision' => 1
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
'description' => 'Description for item',
|
|
28
|
-
'style' => {
|
|
29
|
-
'word-wrap' => 'break-word',
|
|
30
|
-
'overflow' => 'truncate',
|
|
31
|
-
'text-align' => 'right',
|
|
32
|
-
'vertical-align' => 'middle',
|
|
33
|
-
'color' => '#000000',
|
|
34
|
-
'font-size' => 12,
|
|
35
|
-
'font-family' => ['Helvetica'],
|
|
36
|
-
'font-style' => ['bold', 'italic', 'linethrough', 'underline'],
|
|
37
|
-
'letter-spacing' => 'normal',
|
|
38
|
-
'line-height' => 30,
|
|
39
|
-
'line-height-ratio' => 1.5
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
TextBlock = Thinreports::Core::Shape::TextBlock
|
|
44
|
-
|
|
45
|
-
def test_attribute_readers
|
|
46
|
-
format = TextBlock::Format.new(TEXT_BLOCK_FORMAT)
|
|
47
|
-
|
|
48
|
-
assert_equal 'referenced_text_block', format.ref_id
|
|
49
|
-
assert_equal 'middle', format.valign
|
|
50
|
-
assert_equal 'truncate', format.overflow
|
|
51
|
-
assert_equal 30, format.line_height
|
|
52
|
-
assert_equal false, format.multiple?
|
|
53
|
-
assert_equal 'Price: {value}', format.format_base
|
|
54
|
-
assert_equal 'number', format.format_type
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def test_has_reference?
|
|
58
|
-
format_has_reference = TextBlock::Format.new(TEXT_BLOCK_FORMAT.merge('reference-id' => 'other'))
|
|
59
|
-
assert_equal true, format_has_reference.has_reference?
|
|
60
|
-
|
|
61
|
-
format_has_no_reference = TextBlock::Format.new(TEXT_BLOCK_FORMAT.merge('reference-id' => ''))
|
|
62
|
-
assert_equal false, format_has_no_reference.has_reference?
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def test_has_format?
|
|
66
|
-
format_has_text_format = TextBlock::Format.new(TEXT_BLOCK_FORMAT.merge(
|
|
67
|
-
'format' => { 'type' => 'datetime' }
|
|
68
|
-
))
|
|
69
|
-
assert_equal true, format_has_text_format.has_format?
|
|
70
|
-
|
|
71
|
-
format_has_no_text_format = TextBlock::Format.new(TEXT_BLOCK_FORMAT.merge(
|
|
72
|
-
'format' => { 'type' => '' }
|
|
73
|
-
))
|
|
74
|
-
assert_equal false, format_has_no_text_format.has_format?
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def test_number_format_attribute_readers
|
|
78
|
-
format = TextBlock::Format.new(TEXT_BLOCK_FORMAT.merge(
|
|
79
|
-
'format' => {
|
|
80
|
-
'type' => 'number',
|
|
81
|
-
'number' => {
|
|
82
|
-
'delimiter' => ',',
|
|
83
|
-
'precision' => 1
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
))
|
|
87
|
-
assert_equal ',', format.format_number_delimiter
|
|
88
|
-
assert_equal 1, format.format_number_precision
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
def test_datetime_format_attribute_readers
|
|
92
|
-
format = TextBlock::Format.new(TEXT_BLOCK_FORMAT.merge(
|
|
93
|
-
'format' => {
|
|
94
|
-
'type' => 'datetime',
|
|
95
|
-
'datetime' => {
|
|
96
|
-
'format' => '%Y-%m-%d'
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
))
|
|
100
|
-
assert_equal '%Y-%m-%d', format.format_datetime_format
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def test_padding_format_attribute_readers
|
|
104
|
-
format = TextBlock::Format.new(TEXT_BLOCK_FORMAT.merge(
|
|
105
|
-
'format' => {
|
|
106
|
-
'type' => 'padding',
|
|
107
|
-
'padding' => {
|
|
108
|
-
'char' => '0',
|
|
109
|
-
'length' => 10,
|
|
110
|
-
'direction' => 'L'
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
))
|
|
114
|
-
assert_equal '0', format.format_padding_char
|
|
115
|
-
assert_equal 'L', format.format_padding_dir
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
def test_format_padding_length
|
|
119
|
-
format = TextBlock::Format.new(TEXT_BLOCK_FORMAT.merge(
|
|
120
|
-
'format' => {
|
|
121
|
-
'type' => 'padding',
|
|
122
|
-
'padding' => {
|
|
123
|
-
'char' => '0',
|
|
124
|
-
'length' => 10,
|
|
125
|
-
'direction' => 'L'
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
))
|
|
129
|
-
assert_equal 10, format.format_padding_length
|
|
130
|
-
|
|
131
|
-
format = TextBlock::Format.new(TEXT_BLOCK_FORMAT.merge(
|
|
132
|
-
'format' => {
|
|
133
|
-
'type' => 'padding',
|
|
134
|
-
'padding' => {
|
|
135
|
-
'char' => '0',
|
|
136
|
-
'length' => '',
|
|
137
|
-
'direction' => 'L'
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
))
|
|
141
|
-
assert_equal 0, format.format_padding_length
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
def test_format_padding_rdir?
|
|
145
|
-
format_direction_left = TextBlock::Format.new(TEXT_BLOCK_FORMAT.merge(
|
|
146
|
-
'format' => {
|
|
147
|
-
'type' => 'padding',
|
|
148
|
-
'padding' => {
|
|
149
|
-
'char' => '0',
|
|
150
|
-
'length' => 10,
|
|
151
|
-
'direction' => 'L'
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
))
|
|
155
|
-
assert_equal false, format_direction_left.format_padding_rdir?
|
|
156
|
-
|
|
157
|
-
format_direction_right = TextBlock::Format.new(TEXT_BLOCK_FORMAT.merge(
|
|
158
|
-
'format' => {
|
|
159
|
-
'type' => 'padding',
|
|
160
|
-
'padding' => {
|
|
161
|
-
'char' => '0',
|
|
162
|
-
'length' => 10,
|
|
163
|
-
'direction' => 'R'
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
))
|
|
167
|
-
assert_equal true, format_direction_right.format_padding_rdir?
|
|
168
|
-
end
|
|
169
|
-
end
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# coding: utf-8
|
|
2
|
-
|
|
3
|
-
require 'test_helper'
|
|
4
|
-
|
|
5
|
-
class Thinreports::Core::Shape::TextBlock::TestFormatter < Minitest::Test
|
|
6
|
-
include Thinreports::TestHelper
|
|
7
|
-
|
|
8
|
-
# Alias
|
|
9
|
-
Formatter = Thinreports::Core::Shape::TextBlock::Formatter
|
|
10
|
-
|
|
11
|
-
def test_initialize_formatter_by_type
|
|
12
|
-
assert_instance_of Formatter::Basic,
|
|
13
|
-
Formatter.setup( stub(format_type: '') )
|
|
14
|
-
|
|
15
|
-
assert_instance_of Formatter::Number,
|
|
16
|
-
Formatter.setup( stub(format_type: 'number') )
|
|
17
|
-
|
|
18
|
-
assert_instance_of Formatter::Datetime,
|
|
19
|
-
Formatter.setup( stub(format_type: 'datetime') )
|
|
20
|
-
|
|
21
|
-
assert_instance_of Formatter::Padding,
|
|
22
|
-
Formatter.setup( stub(format_type: 'padding') )
|
|
23
|
-
|
|
24
|
-
assert_raises Thinreports::Errors::UnknownFormatterType do
|
|
25
|
-
Formatter.setup( stub(format_type: 'unknown') )
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
# coding: utf-8
|
|
2
|
-
|
|
3
|
-
require 'test_helper'
|
|
4
|
-
|
|
5
|
-
class Thinreports::Core::Shape::TextBlock::TestInterface < Minitest::Test
|
|
6
|
-
include Thinreports::TestHelper
|
|
7
|
-
|
|
8
|
-
# Alias
|
|
9
|
-
TextBlock = Thinreports::Core::Shape::TextBlock
|
|
10
|
-
|
|
11
|
-
def create_interface(format_config = {})
|
|
12
|
-
report = Thinreports::Report.new layout: layout_file.path
|
|
13
|
-
parent = report.start_new_page
|
|
14
|
-
|
|
15
|
-
TextBlock::Interface.new parent, TextBlock::Format.new(format_config)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def test_format_enabled_asker_should_operate_as_delegator_of_internal
|
|
19
|
-
tblock = create_interface('format' => {'type' => 'datetime'})
|
|
20
|
-
assert_equal tblock.format_enabled?, tblock.internal.format_enabled?
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def test_format_enabled_should_properly_set_value_to_internal
|
|
24
|
-
tblock = create_interface('format' => {'type' => 'number'})
|
|
25
|
-
tblock.format_enabled(false)
|
|
26
|
-
|
|
27
|
-
assert_equal tblock.internal.format_enabled?, false
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def test_set_should_properly_set_a_value
|
|
31
|
-
tblock = create_interface
|
|
32
|
-
tblock.set(1000, visible: false)
|
|
33
|
-
|
|
34
|
-
assert_equal tblock.value, 1000
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def test_set_should_properly_set_styles
|
|
38
|
-
tblock = create_interface
|
|
39
|
-
tblock.set(1000, color: '#ff0000',
|
|
40
|
-
bold: true,
|
|
41
|
-
italic: true)
|
|
42
|
-
|
|
43
|
-
assert_equal [tblock.style(:color),
|
|
44
|
-
tblock.style(:bold),
|
|
45
|
-
tblock.style(:italic)],
|
|
46
|
-
['#ff0000', true, true]
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def test_value=
|
|
50
|
-
report = Thinreports::Report.new layout: layout_file.path
|
|
51
|
-
page = report.start_new_page
|
|
52
|
-
|
|
53
|
-
page.item(:text_block).value = 'foo'
|
|
54
|
-
assert_equal 'foo', page.item(:text_block).value
|
|
55
|
-
|
|
56
|
-
page.item(:text_block).value += 'bar'
|
|
57
|
-
assert_equal 'foobar', page.item(:text_block).value
|
|
58
|
-
|
|
59
|
-
page.item(:text_block).value = 1000
|
|
60
|
-
page.item(:text_block).value += 999
|
|
61
|
-
assert_equal 1999, page.item(:text_block).value
|
|
62
|
-
end
|
|
63
|
-
end
|