thinreports 0.10.2 → 0.12.1
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 +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,191 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'test_helper'
|
|
4
|
-
|
|
5
|
-
class Thinreports::Core::Shape::Style::TestBase < Minitest::Test
|
|
6
|
-
include Thinreports::TestHelper
|
|
7
|
-
|
|
8
|
-
# Alias
|
|
9
|
-
Style = Thinreports::Core::Shape::Style::Base
|
|
10
|
-
|
|
11
|
-
def create_basic_format(base_style = {})
|
|
12
|
-
Thinreports::Core::Shape::Basic::Format.new('style' => base_style)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def create_style(base_style = {})
|
|
16
|
-
Style.new(create_basic_format(base_style))
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def create_new_style(base_style = {}, &block)
|
|
20
|
-
klass = ::Class.new(Style, &block)
|
|
21
|
-
klass.new(create_basic_format(base_style))
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def test_self_style_reader_should_properly_define_a_reading_method
|
|
25
|
-
style = create_new_style {
|
|
26
|
-
style_reader :hoge, 'foo'
|
|
27
|
-
}
|
|
28
|
-
assert_respond_to style, :hoge
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def test_self_style_writer_should_properly_define_a_writing_method
|
|
32
|
-
style = create_new_style {
|
|
33
|
-
style_writer :hoge, 'foo'
|
|
34
|
-
}
|
|
35
|
-
assert_respond_to style, :hoge=
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def test_self_style_accessor_should_properly_defines_reading_and_writing_methods
|
|
39
|
-
style = create_new_style {
|
|
40
|
-
style_accessor :hoge, 'foo'
|
|
41
|
-
}
|
|
42
|
-
assert_respond_to style, :hoge
|
|
43
|
-
assert_respond_to style, :hoge=
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def test_self_style_accessible_should_add_specified_styles_to_the_accessible_styles_variable
|
|
47
|
-
style = create_new_style {
|
|
48
|
-
style_accessible :hoge
|
|
49
|
-
style_accessible :foo, :bar
|
|
50
|
-
}
|
|
51
|
-
assert_equal style.class.accessible_styles, [:hoge, :foo, :bar]
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def test_self_accessible_styles_variable_should_not_be_shared_each_SubClasses
|
|
55
|
-
style1 = create_new_style {
|
|
56
|
-
style_accessible :hoge, :foo
|
|
57
|
-
}
|
|
58
|
-
assert_equal style1.class.accessible_styles, [:hoge, :foo]
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def test_self_accessible_styles_variable_should_be_inherited_to_SubClass
|
|
62
|
-
super_klass = ::Class.new(Style) {
|
|
63
|
-
style_accessible :hoge, :foo
|
|
64
|
-
}
|
|
65
|
-
sub_klass = ::Class.new(super_klass)
|
|
66
|
-
|
|
67
|
-
assert_equal sub_klass.accessible_styles, super_klass.accessible_styles
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def test_self_accessible_styles_variables_of_SubClass_should_not_interfere_mutually
|
|
71
|
-
super_klass = ::Class.new(Style) {
|
|
72
|
-
style_accessible :foo, :bar
|
|
73
|
-
}
|
|
74
|
-
sub_klass1 = ::Class.new(super_klass)
|
|
75
|
-
sub_klass2 = ::Class.new(super_klass)
|
|
76
|
-
|
|
77
|
-
refute_same sub_klass1.accessible_styles, sub_klass2.accessible_styles
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def test_read_internal_style_should_return_style_of_styles_when_style_is_found_in_styles
|
|
81
|
-
style = create_style('hoge' => 'base_style')
|
|
82
|
-
style.write_internal_style('hoge', 'new_style')
|
|
83
|
-
|
|
84
|
-
assert_equal style.read_internal_style('hoge'), 'new_style'
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
def test_read_internal_style_should_return_style_of_base_when_style_is_not_found_in_styles
|
|
88
|
-
style = create_style('hoge' => 'base_style')
|
|
89
|
-
assert_equal style.read_internal_style('hoge'), 'base_style'
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def test_write_internal_style_should_properly_set_style_to_the_styles
|
|
93
|
-
style = create_style({})
|
|
94
|
-
style.write_internal_style('hoge', 'hoge_style')
|
|
95
|
-
|
|
96
|
-
assert_equal style.styles['hoge'], 'hoge_style'
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
def test_has_style_asker_should_return_true_when_specified_style_method_is_accessible
|
|
100
|
-
style = create_new_style {
|
|
101
|
-
style_accessible :hoge, :foo
|
|
102
|
-
}
|
|
103
|
-
assert_equal style.has_style?(:foo), true
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
def test_has_style_asker_should_return_false_when_specified_style_method_is_not_accessible
|
|
107
|
-
style = create_new_style {
|
|
108
|
-
style_accessible :foo
|
|
109
|
-
}
|
|
110
|
-
assert_equal style.has_style?(:hoge), false
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
def test_verify_style_value_should_raise_when_value_is_not_included_in_list
|
|
114
|
-
assert_raises ArgumentError do
|
|
115
|
-
create_style.send(:verify_style_value, :invalid, [:hoge, :foo, :bar])
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def test_verify_style_value_should_not_raise_when_value_is_found_in_list
|
|
120
|
-
create_style.send(:verify_style_value, :valid, [:hoge, :valid, :foo])
|
|
121
|
-
rescue ArgumentError
|
|
122
|
-
flunk
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
def test_reader_method_caller_should_properly_delegate_to_real_method
|
|
126
|
-
style = create_new_style('hoge_style' => 'hoge_style_value') {
|
|
127
|
-
style_accessible :hoge
|
|
128
|
-
style_reader :hoge, 'hoge_style'
|
|
129
|
-
}
|
|
130
|
-
assert_equal style[:hoge], 'hoge_style_value'
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
def test_writer_method_caller_should_properly_delegate_to_real_method
|
|
134
|
-
style = create_new_style {
|
|
135
|
-
style_accessible :hoge
|
|
136
|
-
style_accessor :hoge, 'hoge_style'
|
|
137
|
-
}
|
|
138
|
-
style[:hoge] = 'hoge_style_value'
|
|
139
|
-
assert_equal style.hoge, 'hoge_style_value'
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
def test_reader_method_caller_should_raise_when_style_is_not_accessible
|
|
143
|
-
assert_raises Thinreports::Errors::UnknownShapeStyleName do
|
|
144
|
-
create_new_style[:unknown]
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
def test_writer_method_caller_should_raise_when_style_is_not_accessible
|
|
149
|
-
assert_raises Thinreports::Errors::UnknownShapeStyleName do
|
|
150
|
-
create_new_style[:unknown] = 'value'
|
|
151
|
-
end
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
def test_copy_should_return_the_instance_of_the_same_class_as_itself
|
|
155
|
-
style = create_style
|
|
156
|
-
assert_instance_of Style, style.copy
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
def test_styles_of_copied_style_should_not_same_the_styles_of_original
|
|
160
|
-
style = create_style
|
|
161
|
-
refute_same style.styles, style.copy.styles
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
def test_styles_of_copied_style_should_equal_the_style_of_original
|
|
165
|
-
style = create_style
|
|
166
|
-
style.write_internal_style('foo', 'foo_value')
|
|
167
|
-
assert_equal style.styles['foo'], style.copy.styles['foo']
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
def test_identifier_should_return_empty_string_when_the_style_is_not_set
|
|
171
|
-
style = create_style
|
|
172
|
-
assert_equal style.identifier, ''
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
def test_identifier_should_return_the_same_as_hash_value_of_styles_when_style_is_set_something
|
|
176
|
-
style = create_style
|
|
177
|
-
style.write_internal_style('foo', 'foo_value')
|
|
178
|
-
|
|
179
|
-
assert_equal style.identifier, style.styles.hash.to_s
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
def test_finalized_styles
|
|
183
|
-
base_styles = { 'foo' => 'default foo', 'bar' => 'default bar' }
|
|
184
|
-
|
|
185
|
-
style = create_style(base_styles)
|
|
186
|
-
style.write_internal_style('foo', 'new foo')
|
|
187
|
-
|
|
188
|
-
assert_equal({ 'foo' => 'new foo', 'bar' => 'default bar' }, style.finalized_styles)
|
|
189
|
-
assert_same style.finalized_styles, style.finalized_styles
|
|
190
|
-
end
|
|
191
|
-
end
|
|
@@ -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
|