thinreports 0.8.2 → 0.9.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.
Files changed (170) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CONTRIBUTING.md +2 -0
  3. data/.travis.yml +3 -3
  4. data/CHANGELOG.md +98 -1
  5. data/README.md +0 -9
  6. data/Rakefile +1 -2
  7. data/examples/character_spacing/character_spacing.tlf +293 -1
  8. data/examples/dynamic_image/dynamic_image.tlf +661 -1
  9. data/examples/dynamic_style/dynamic_style.rb +4 -4
  10. data/examples/dynamic_style/dynamic_style.tlf +1835 -1
  11. data/examples/dynamic_style/dynamic_style_in_list.tlf +344 -1
  12. data/examples/eudc/eudc.tlf +180 -1
  13. data/examples/hidden_shapes/hidden_shapes.tlf +449 -1
  14. data/examples/list_events/list_events.rb +1 -28
  15. data/examples/list_events/list_events.tlf +361 -0
  16. data/examples/list_manual_generation/list_manual_generation.tlf +132 -1
  17. data/examples/list_page_number/list_page_number.tlf +254 -1
  18. data/examples/page_number/page_number.tlf +215 -1
  19. data/examples/palleted_png/palleted_png.rb +2 -0
  20. data/examples/palleted_png/palleted_png.tlf +47 -1
  21. data/examples/password_setting/password_setting.tlf +45 -1
  22. data/examples/report_callbacks/report_callbacks.rb +1 -18
  23. data/examples/report_callbacks/report_callbacks.tlf +147 -1
  24. data/examples/single_line_tblock/single_line_tblock.tlf +170 -1
  25. data/examples/tblock_overflow/tblock_overflow.tlf +538 -1
  26. data/examples/tblock_styles/font_size.tlf +383 -1
  27. data/examples/tblock_styles/tblock_styles.tlf +889 -1
  28. data/examples/text_align/text_align.tlf +241 -1
  29. data/examples/typeB_page_size/B4_ISO.tlf +45 -1
  30. data/examples/typeB_page_size/B4_JIS.tlf +45 -1
  31. data/examples/word_wrap/word_wrap.tlf +297 -1
  32. data/lib/thinreports.rb +0 -1
  33. data/lib/thinreports/config.rb +3 -0
  34. data/lib/thinreports/core/errors.rb +0 -3
  35. data/lib/thinreports/core/format/base.rb +4 -4
  36. data/lib/thinreports/core/shape.rb +1 -9
  37. data/lib/thinreports/core/shape/basic.rb +3 -3
  38. data/lib/thinreports/core/shape/basic/block_format.rb +1 -1
  39. data/lib/thinreports/core/shape/basic/format.rb +2 -14
  40. data/lib/thinreports/core/shape/basic/internal.rb +2 -2
  41. data/lib/thinreports/core/shape/image_block.rb +3 -3
  42. data/lib/thinreports/core/shape/image_block/format.rb +0 -2
  43. data/lib/thinreports/core/shape/image_block/internal.rb +1 -1
  44. data/lib/thinreports/core/shape/list.rb +3 -7
  45. data/lib/thinreports/core/shape/list/format.rb +37 -24
  46. data/lib/thinreports/core/shape/list/manager.rb +1 -36
  47. data/lib/thinreports/core/shape/list/page.rb +0 -15
  48. data/lib/thinreports/core/shape/list/page_state.rb +1 -1
  49. data/lib/thinreports/core/shape/list/section_format.rb +14 -12
  50. data/lib/thinreports/core/shape/list/section_internal.rb +4 -7
  51. data/lib/thinreports/core/shape/manager/format.rb +0 -2
  52. data/lib/thinreports/core/shape/manager/internal.rb +1 -1
  53. data/lib/thinreports/core/shape/page_number.rb +1 -1
  54. data/lib/thinreports/core/shape/page_number/format.rb +9 -6
  55. data/lib/thinreports/core/shape/page_number/interface.rb +1 -1
  56. data/lib/thinreports/core/shape/page_number/internal.rb +2 -6
  57. data/lib/thinreports/core/shape/style/base.rb +11 -13
  58. data/lib/thinreports/core/shape/style/basic.rb +4 -4
  59. data/lib/thinreports/core/shape/style/graphic.rb +4 -10
  60. data/lib/thinreports/core/shape/style/text.rb +36 -69
  61. data/lib/thinreports/core/shape/text.rb +3 -3
  62. data/lib/thinreports/core/shape/text/format.rb +3 -13
  63. data/lib/thinreports/core/shape/text/internal.rb +2 -2
  64. data/lib/thinreports/core/shape/text_block.rb +3 -3
  65. data/lib/thinreports/core/shape/text_block/format.rb +9 -6
  66. data/lib/thinreports/core/shape/text_block/interface.rb +7 -7
  67. data/lib/thinreports/core/shape/text_block/internal.rb +1 -1
  68. data/lib/thinreports/generator/pdf.rb +0 -1
  69. data/lib/thinreports/generator/pdf/document.rb +2 -2
  70. data/lib/thinreports/generator/pdf/document/draw_shape.rb +25 -51
  71. data/lib/thinreports/generator/pdf/document/draw_template_items.rb +66 -0
  72. data/lib/thinreports/generator/pdf/document/font.rb +3 -8
  73. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +97 -77
  74. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +18 -13
  75. data/lib/thinreports/generator/pdf/document/graphics/image.rb +17 -12
  76. data/lib/thinreports/generator/pdf/document/page.rb +1 -1
  77. data/lib/thinreports/generator/pdf/drawer/list.rb +5 -1
  78. data/lib/thinreports/generator/pdf/drawer/list_section.rb +1 -4
  79. data/lib/thinreports/generator/pdf/drawer/page.rb +9 -9
  80. data/lib/thinreports/layout.rb +3 -3
  81. data/lib/thinreports/layout/base.rb +0 -16
  82. data/lib/thinreports/layout/format.rb +38 -57
  83. data/lib/thinreports/layout/legacy_schema.rb +354 -0
  84. data/lib/thinreports/layout/version.rb +1 -1
  85. data/lib/thinreports/report.rb +0 -1
  86. data/lib/thinreports/report/base.rb +3 -17
  87. data/lib/thinreports/report/internal.rb +13 -55
  88. data/lib/thinreports/report/page.rb +1 -1
  89. data/lib/thinreports/version.rb +1 -1
  90. data/test/data/legacy_layout/all-items.tlf +1 -0
  91. data/test/schema_helper.rb +121 -0
  92. data/test/test_helper.rb +13 -50
  93. data/test/unit/core/format/test_base.rb +35 -31
  94. data/test/unit/core/shape/base/test_internal.rb +1 -1
  95. data/test/unit/core/shape/basic/test_block_format.rb +23 -0
  96. data/test/unit/core/shape/basic/{test_basic_interface.rb → test_block_interface.rb} +1 -1
  97. data/test/unit/core/shape/basic/{test_basic_internal.rb → test_block_internal.rb} +4 -7
  98. data/test/unit/core/shape/basic/test_format.rb +25 -47
  99. data/test/unit/core/shape/basic/test_interface.rb +5 -5
  100. data/test/unit/core/shape/basic/test_internal.rb +6 -11
  101. data/test/unit/core/shape/image_block/test_interface.rb +5 -5
  102. data/test/unit/core/shape/image_block/test_internal.rb +2 -2
  103. data/test/unit/core/shape/list/test_format.rb +86 -44
  104. data/test/unit/core/shape/list/test_manager.rb +10 -65
  105. data/test/unit/core/shape/list/test_page.rb +10 -61
  106. data/test/unit/core/shape/list/test_page_state.rb +1 -1
  107. data/test/unit/core/shape/list/test_section_format.rb +19 -28
  108. data/test/unit/core/shape/list/test_section_interface.rb +14 -6
  109. data/test/unit/core/shape/list/test_section_internal.rb +17 -23
  110. data/test/unit/core/shape/manager/test_format.rb +1 -1
  111. data/test/unit/core/shape/manager/test_internal.rb +59 -98
  112. data/test/unit/core/shape/manager/test_target.rb +21 -30
  113. data/test/unit/core/shape/page_number/test_format.rb +34 -52
  114. data/test/unit/core/shape/page_number/test_interface.rb +1 -1
  115. data/test/unit/core/shape/page_number/test_internal.rb +2 -2
  116. data/test/unit/core/shape/styles/test_base.rb +16 -41
  117. data/test/unit/core/shape/styles/test_basic.rb +7 -7
  118. data/test/unit/core/shape/styles/test_graphic.rb +27 -32
  119. data/test/unit/core/shape/styles/test_text.rb +68 -311
  120. data/test/unit/core/shape/text/test_format.rb +30 -59
  121. data/test/unit/core/shape/text/test_internal.rb +5 -5
  122. data/test/unit/core/shape/text_block/formatter/test_datetime.rb +13 -13
  123. data/test/unit/core/shape/text_block/test_format.rb +145 -146
  124. data/test/unit/core/shape/text_block/test_interface.rb +9 -9
  125. data/test/unit/core/shape/text_block/test_internal.rb +9 -9
  126. data/test/unit/core/test_shape.rb +19 -31
  127. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +112 -122
  128. data/test/unit/generator/pdf/document/graphics/test_basic.rb +45 -0
  129. data/test/unit/generator/pdf/document/graphics/test_image.rb +5 -5
  130. data/test/unit/generator/pdf/document/test_font.rb +4 -10
  131. data/test/unit/generator/pdf/document/test_page.rb +13 -11
  132. data/test/unit/generator/pdf/document/test_parse_color.rb +5 -5
  133. data/test/unit/generator/test_base.rb +5 -5
  134. data/test/unit/generator/test_configuration.rb +4 -8
  135. data/test/unit/generator/test_pdf.rb +3 -2
  136. data/test/unit/layout/test_base.rb +16 -22
  137. data/test/unit/layout/test_format.rb +66 -86
  138. data/test/unit/layout/test_legacy_schema.rb +587 -0
  139. data/test/unit/layout/test_version.rb +20 -20
  140. data/test/unit/report/test_base.rb +32 -45
  141. data/test/unit/report/test_internal.rb +43 -99
  142. data/test/unit/test_config.rb +4 -2
  143. data/test/unit/test_layout.rb +1 -1
  144. metadata +20 -48
  145. data/examples/list_events/list_events_0_7_7.tlf +0 -1
  146. data/examples/list_events/list_events_0_8.tlf +0 -1
  147. data/lib/thinreports/core/events.rb +0 -69
  148. data/lib/thinreports/core/format/builder.rb +0 -62
  149. data/lib/thinreports/core/shape/list/configuration.rb +0 -54
  150. data/lib/thinreports/core/shape/list/events.rb +0 -47
  151. data/lib/thinreports/core/shape/list/store.rb +0 -33
  152. data/lib/thinreports/generator/pdf/configuration.rb +0 -33
  153. data/lib/thinreports/generator/pdf/document/parse_svg.rb +0 -104
  154. data/lib/thinreports/layout/configuration.rb +0 -29
  155. data/test/data/layout_block.tlf +0 -1
  156. data/test/data/layout_list.tlf +0 -1
  157. data/test/data/layout_list_noheader.tlf +0 -1
  158. data/test/data/layout_text1.tlf +0 -1
  159. data/test/data/layout_text2.tlf +0 -1
  160. data/test/unit/core/format/test_builder.rb +0 -109
  161. data/test/unit/core/shape/basic/test_basic_format.rb +0 -30
  162. data/test/unit/core/shape/image_block/test_format.rb +0 -58
  163. data/test/unit/core/shape/list/test_configuration.rb +0 -69
  164. data/test/unit/core/shape/list/test_events.rb +0 -36
  165. data/test/unit/core/shape/list/test_store.rb +0 -41
  166. data/test/unit/core/test_events.rb +0 -93
  167. data/test/unit/generator/pdf/document/test_draw_shape.rb +0 -44
  168. data/test/unit/generator/pdf/test_configuration.rb +0 -31
  169. data/test/unit/layout/test_configuration.rb +0 -21
  170. data/test/unit/report/test_events.rb +0 -22
@@ -28,51 +28,42 @@ class Thinreports::Core::Shape::Manager::TestTarget < Minitest::Test
28
28
  end
29
29
 
30
30
  def create_manager
31
- report = new_report('layout_text1.tlf')
31
+ report = Thinreports::Report.new layout: layout_file.path
32
32
  layout = report.layout
33
33
 
34
- layout.format.shapes[:text_block1] = create_shape_format('s-tblock', 'text_block1')
35
- layout.format.shapes[:text_block2] = create_shape_format('s-tblock', 'text_block2')
36
- layout.format.shapes[:image_block] = create_shape_format('s-iblock', 'image_block')
37
- layout.format.shapes[:rectangle] = create_shape_format('s-rect', 'rectangle')
38
- layout.format.shapes[:line] = create_shape_format('s-line', 'line')
39
- layout.format.shapes[:list1] = create_shape_format('s-list', 'list1')
40
- layout.format.shapes[:list2] = create_shape_format('s-list', 'list2')
41
- layout.format.shapes[:default] = create_shape_format('s-list', 'default')
42
-
43
34
  TestManager.new(report, layout)
44
35
  end
45
36
 
46
37
  def test_shorthand_for_finding_item
47
38
  manager = create_manager
48
39
 
49
- text_block1 = manager[:text_block1]
40
+ text_block1 = manager[:text_block]
50
41
  text_block1.value = 'block1'
51
42
 
52
- assert_instance_of Shape::TextBlock::Interface, manager[:text_block1]
43
+ assert_instance_of Shape::TextBlock::Interface, manager[:text_block]
53
44
  assert_instance_of Shape::ImageBlock::Interface, manager[:image_block]
54
- assert_instance_of Shape::Basic::Interface, manager[:rectangle]
45
+ assert_instance_of Shape::Basic::Interface, manager[:rect_with_id]
55
46
 
56
47
  assert_raises Thinreports::Errors::UnknownItemId do
57
48
  manager[:unknown_id]
58
49
  end
59
50
 
60
51
  assert_raises Thinreports::Errors::UnknownItemId do
61
- manager[:list1]
52
+ manager[:default]
62
53
  end
63
54
  end
64
55
 
65
56
  def test_shorthand_for_setting_value_to_block
66
57
  manager = create_manager
67
58
 
68
- manager[:text_block1] = 'value of text block1'
69
- assert_equal 'value of text block1', manager.item(:text_block1).value
59
+ manager[:text_block] = 'value of text block1'
60
+ assert_equal 'value of text block1', manager.item(:text_block).value
70
61
 
71
62
  manager[:image_block] = '/path/to/image.png'
72
63
  assert_equal '/path/to/image.png', manager.item(:image_block).src
73
64
 
74
- assert_raises(NoMethodError) { manager[:rectangle] = 'value' }
75
- assert_raises(Thinreports::Errors::UnknownItemId) { manager[:list1] = 'value' }
65
+ assert_raises(NoMethodError) { manager[:rect_with_id] = 'value' }
66
+ assert_raises(Thinreports::Errors::UnknownItemId) { manager[:default] = 'value' }
76
67
  end
77
68
 
78
69
  def test_manager_should_return_instance_of_ManagerInternal
@@ -80,11 +71,11 @@ class Thinreports::Core::Shape::Manager::TestTarget < Minitest::Test
80
71
  end
81
72
 
82
73
  def test_item_should_properly_return_shape_with_the_specified_Symbol_id
83
- assert_equal create_manager.item(:text_block1).id, 'text_block1'
74
+ assert_equal create_manager.item(:text_block).id, 'text_block'
84
75
  end
85
76
 
86
77
  def test_item_should_properly_return_shape_with_the_specified_String_id
87
- assert_equal create_manager.item('text_block2').id, 'text_block2'
78
+ assert_equal create_manager.item('text_block').id, 'text_block'
88
79
  end
89
80
 
90
81
  def test_item_should_raise_when_the_shape_with_the_specified_id_is_not_found
@@ -95,27 +86,27 @@ class Thinreports::Core::Shape::Manager::TestTarget < Minitest::Test
95
86
 
96
87
  def test_item_should_set_an_shape_as_argument_when_a_block_is_given
97
88
  id = nil
98
- create_manager.item(:text_block1) {|s| id = s.id }
99
- assert_equal id, 'text_block1'
89
+ create_manager.item(:text_block) {|s| id = s.id }
90
+ assert_equal id, 'text_block'
100
91
  end
101
92
 
102
93
  def test_item_should_raise_when_type_of_shape_with_the_specified_id_is_list
103
94
  assert_raises Thinreports::Errors::UnknownItemId do
104
- create_manager.item(:list1)
95
+ create_manager.item(:default)
105
96
  end
106
97
  end
107
98
 
108
99
  def test_list_should_properly_return_list_with_the_specified_Symbol_id
109
- assert_equal create_manager.list(:list1).id, 'list1'
100
+ assert_equal create_manager.list(:default).id, 'default'
110
101
  end
111
102
 
112
103
  def test_list_should_properly_return_list_with_the_specified_String_id
113
- assert_equal create_manager.list('list1').id, 'list1'
104
+ assert_equal create_manager.list('default').id, 'default'
114
105
  end
115
106
 
116
107
  def test_list_should_raise_when_type_of_shape_with_the_specified_id_is_not_list
117
108
  assert_raises Thinreports::Errors::UnknownItemId do
118
- create_manager.list(:text_block1)
109
+ create_manager.list(:text_block)
119
110
  end
120
111
  end
121
112
 
@@ -125,17 +116,17 @@ class Thinreports::Core::Shape::Manager::TestTarget < Minitest::Test
125
116
 
126
117
  def test_values_should_properly_set_values_to_shapes_with_specified_id
127
118
  manager = create_manager
128
- manager.values(text_block1: 1000, 'text_block2' => 'value')
119
+ manager.values(text_block: 1000)
129
120
 
130
- assert_equal [manager.item(:text_block1).value, manager.item(:text_block2).value], [1000, 'value']
121
+ assert_equal manager.item(:text_block).value, 1000
131
122
  end
132
123
 
133
124
  def test_item_exists_asker_should_return_true_when_shape_with_specified_Symbol_id_is_found
134
- assert_equal create_manager.item_exists?(:text_block1), true
125
+ assert_equal create_manager.item_exists?(:text_block), true
135
126
  end
136
127
 
137
128
  def test_item_exists_asker_should_return_true_when_shape_with_specified_String_id_is_found
138
- assert_equal create_manager.item_exists?('text_block2'), true
129
+ assert_equal create_manager.item_exists?('text_block'), true
139
130
  end
140
131
 
141
132
  def test_item_exists_asker_should_return_false_when_shape_with_specified_id_not_found
@@ -5,69 +5,51 @@ require 'test_helper'
5
5
  class Thinreports::Core::Shape::PageNumber::TestFormat < Minitest::Test
6
6
  include Thinreports::TestHelper
7
7
 
8
- TEST_PAGENO_FORMAT = {
9
- "type" => "s-pageno",
10
- "id" => "",
11
- "display" => "true",
12
- "box" => {
13
- "x" => 100.0,
14
- "y" => 100.0,
15
- "width" => 100.0,
16
- "height" => 100.0
17
- },
18
- "format" => "{page} / {total}",
19
- "overflow" => "truncate",
20
- "target" => "",
21
- "svg" => {
22
- "tag" => "text",
23
- "attrs" => {
24
- "x" => 308.2,
25
- "y" => 239,
26
- "kerning" => "auto",
27
- "id" => "goog_939685354",
28
- "fill" => "#000000",
29
- "fill-opacity" => "1",
30
- "font-size" => "18",
31
- "font-family" => "Helvetica",
32
- "font-weight" => "normal",
33
- "font-style" => "normal",
34
- "text-anchor" => "middle",
35
- "text-decoration" => "none"
36
- }
8
+ PAGE_NUMBER_FORMAT = {
9
+ 'id' => '',
10
+ 'type' => 'page-number',
11
+ 'display' => true,
12
+ 'x' => 100.0,
13
+ 'y' => 200.0,
14
+ 'width' => 300.0,
15
+ 'height' => 400.0,
16
+ 'format' => '{page} / {total}',
17
+ 'target' => '',
18
+ 'style' => {
19
+ 'overflow' => 'truncate',
20
+ 'letter-spacing' => 'normal',
21
+ 'color' => '#000000',
22
+ 'font-size' => 18,
23
+ 'font-family' => ['Helvetica'],
24
+ 'line-height' => 60,
25
+ 'line-height-ratio' => 1.5,
26
+ 'text-align' => 'left'
37
27
  }
38
28
  }
39
29
 
40
- Format = Thinreports::Core::Shape::PageNumber::Format
30
+ PageNumber = Thinreports::Core::Shape::PageNumber
41
31
 
42
- def format(raw_format = nil)
43
- Format.new(raw_format || TEST_PAGENO_FORMAT)
44
- end
32
+ def test_attribute_readers
33
+ format = PageNumber::Format.new(PAGE_NUMBER_FORMAT)
45
34
 
46
- def test_build
47
- Format.build(TEST_PAGENO_FORMAT)
48
- rescue => e
49
- flunk exception_details(e, 'Failed to build')
35
+ assert_equal 'truncate', format.overflow
36
+ assert_equal '', format.target
37
+ assert_equal '{page} / {total}', format.default_format
50
38
  end
51
39
 
52
40
  def test_id
53
- pageno = format('id' => 'pageno_id')
54
- assert_equal pageno.id, 'pageno_id'
55
-
56
- pageno = format('id' => '')
57
- assert_equal pageno.id, '__pageno1'
58
- assert_same pageno.id, pageno.id
59
- end
41
+ format = PageNumber::Format.new(PAGE_NUMBER_FORMAT)
42
+ assert_match(/^__pageno\d+$/, format.id)
60
43
 
61
- def test_overflow
62
- assert_equal format.overflow, 'truncate'
44
+ format = PageNumber::Format.new(PAGE_NUMBER_FORMAT.merge('id' => 'foo'))
45
+ assert_equal 'foo', format.id
63
46
  end
64
47
 
65
- def test_target
66
- assert_equal format.target, ''
67
- assert_equal format("target" => "list-id").target, 'list-id'
68
- end
48
+ def test_for_report?
49
+ format_for_report = PageNumber::Format.new(PAGE_NUMBER_FORMAT)
50
+ assert_equal true, format_for_report.for_report?
69
51
 
70
- def test_default_format
71
- assert_equal format.default_format, '{page} / {total}'
52
+ format_for_list = PageNumber::Format.new(PAGE_NUMBER_FORMAT.merge('target' => 'target_list_id'))
53
+ assert_equal false, format_for_list.for_report?
72
54
  end
73
55
  end
@@ -8,7 +8,7 @@ class Thinreports::Core::Shape::PageNumber::TestInterface < Minitest::Test
8
8
  PageNumber = Thinreports::Core::Shape::PageNumber
9
9
 
10
10
  def create_pageno(format = {})
11
- report = new_report 'layout_text1'
11
+ report = Thinreports::Report.new layout: layout_file.path
12
12
  parent = report.start_new_page
13
13
 
14
14
  PageNumber::Interface.new parent, PageNumber::Format.new(format)
@@ -8,7 +8,7 @@ class Thinreports::Core::Shape::PageNumber::TestInternal < Minitest::Test
8
8
  PageNumber = Thinreports::Core::Shape::PageNumber
9
9
 
10
10
  def setup
11
- @report = new_report('layout_text1.tlf')
11
+ @report = Thinreports::Report.new layout: layout_file.path
12
12
  @report.start_new_page
13
13
  end
14
14
 
@@ -56,7 +56,7 @@ class Thinreports::Core::Shape::PageNumber::TestInternal < Minitest::Test
56
56
 
57
57
  def test_type_of
58
58
  pageno = init_pageno
59
- assert pageno.type_of?(:pageno)
59
+ assert pageno.type_of?('page-number')
60
60
  end
61
61
 
62
62
  def test_style
@@ -8,17 +8,17 @@ class Thinreports::Core::Shape::Style::TestBase < Minitest::Test
8
8
  # Alias
9
9
  Style = Thinreports::Core::Shape::Style::Base
10
10
 
11
- def create_basic_format(attrs = {})
12
- Thinreports::Core::Shape::Basic::Format.new('svg' => {'attrs' => attrs})
11
+ def create_basic_format(base_style = {})
12
+ Thinreports::Core::Shape::Basic::Format.new('style' => base_style)
13
13
  end
14
14
 
15
- def create_style(base = {})
16
- Style.new(create_basic_format(base))
15
+ def create_style(base_style = {})
16
+ Style.new(create_basic_format(base_style))
17
17
  end
18
18
 
19
- def create_new_style(base = {}, &block)
19
+ def create_new_style(base_style = {}, &block)
20
20
  klass = ::Class.new(Style, &block)
21
- klass.new(create_basic_format(base))
21
+ klass.new(create_basic_format(base_style))
22
22
  end
23
23
 
24
24
  def test_self_style_reader_should_properly_define_a_reading_method
@@ -96,41 +96,6 @@ class Thinreports::Core::Shape::Style::TestBase < Minitest::Test
96
96
  assert_equal style.styles['hoge'], 'hoge_style'
97
97
  end
98
98
 
99
- def test_finalized_svg_attributes_should_return_the_Hash_of_having_combined_styles_and_base
100
- style = create_style('hoge' => 'base_hoge_style',
101
- 'foo' => 'base_foo_style')
102
- style.write_internal_style('hoge', 'modified_hoge_style')
103
-
104
- assert_equal style.finalized_svg_attributes.values_at('hoge', 'foo'),
105
- ['modified_hoge_style', 'base_foo_style']
106
- end
107
-
108
- def test_finalized_svg_attributes_should_return_a_base_when_styles_is_empty
109
- style = create_style
110
- assert_equal style.finalized_svg_attributes, style.instance_variable_get(:@base_styles)
111
- end
112
-
113
- def test_finalized_svg_attributes_should_return_a_cloned_base_when_styles_is_empty
114
- style = create_style
115
- refute_same style.finalized_svg_attributes, style.instance_variable_get(:@base_styles)
116
- end
117
-
118
- def test_finalized_svg_attributes_should_return_same_value_constantly
119
- style = create_style('hoge' => 'hoge_style')
120
- style.write_internal_style('foo', 'foo_style')
121
-
122
- assert_same style.finalized_svg_attributes,
123
- style.finalized_svg_attributes
124
- end
125
-
126
- def test_svg_attrs_should_operate_like_a_finalized_svg_attributes
127
- style = create_style('hoge' => 'hoge_style',
128
- 'foo' => 'foo_style')
129
- style.write_internal_style('foo', 'overwrite_foo_style')
130
-
131
- assert_same style.finalized_svg_attributes, style.svg_attrs
132
- end
133
-
134
99
  def test_has_style_asker_should_return_true_when_specified_style_method_is_accessible
135
100
  style = create_new_style {
136
101
  style_accessible :hoge, :foo
@@ -213,4 +178,14 @@ class Thinreports::Core::Shape::Style::TestBase < Minitest::Test
213
178
 
214
179
  assert_equal style.identifier, style.styles.hash.to_s
215
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
216
191
  end
@@ -4,21 +4,21 @@ require 'test_helper'
4
4
 
5
5
  class Thinreports::Core::Shape::Style::TestBasic < Minitest::Test
6
6
  include Thinreports::TestHelper
7
-
7
+
8
8
  def create_basic_style(format_config = {})
9
9
  format = Thinreports::Core::Shape::Basic::Format.new(format_config)
10
10
  Thinreports::Core::Shape::Style::Basic.new(format)
11
11
  end
12
-
12
+
13
13
  def test_visible_should_return_visibility_of_format_as_default
14
- style = create_basic_style('display' => 'false')
14
+ style = create_basic_style('display' => false)
15
15
  assert_equal style.visible, false
16
16
  end
17
-
17
+
18
18
  def test_visible_should_properly_set_visibility
19
- style = create_basic_style('display' => 'false')
19
+ style = create_basic_style('display' => false)
20
20
  style.visible = true
21
-
21
+
22
22
  assert_equal style.visible, true
23
23
  end
24
- end
24
+ end
@@ -5,51 +5,46 @@ require 'test_helper'
5
5
  class Thinreports::Core::Shape::Style::TestGraphic < Minitest::Test
6
6
  include Thinreports::TestHelper
7
7
 
8
- def create_graphic_style
9
- format = Thinreports::Core::Shape::Basic::Format.new({})
10
- Thinreports::Core::Shape::Style::Graphic.new(format)
11
- end
8
+ def test_border_color
9
+ style = create_graphic_style('border-color' => 'red')
10
+ assert_equal 'red', style.border_color
12
11
 
13
- def test_border_color_should_properly_set_to_internal_styles_as_stroke_style
14
- style = create_graphic_style
15
12
  style.border_color = '#ff0000'
16
-
17
- assert_equal style.styles['stroke'], '#ff0000'
18
- end
19
-
20
- def test_border_width_should_properly_set_to_internal_styles_as_stroke_width_style
21
- style = create_graphic_style
22
- style.border_width = 1
23
-
24
- assert_equal style.styles['stroke-width'], 1
13
+ assert_equal '#ff0000', style.styles['border-color']
14
+ assert_equal '#ff0000', style.border_color
25
15
  end
26
16
 
27
- def test_border_width_should_set_stroke_opacity_to_1_when_width_is_not_zero
28
- style = create_graphic_style
29
- style.border_width = 5
17
+ def test_border_width
18
+ style = create_graphic_style('border-width' => 2.0)
19
+ assert_equal 2.0, style.border_width
30
20
 
31
- assert_equal style.styles['stroke-opacity'], '1'
21
+ style.border_width = 10.9
22
+ assert_equal 10.9, style.styles['border-width']
23
+ assert_equal 10.9, style.border_width
32
24
  end
33
25
 
34
- def test_fill_color_should_properly_set_to_internal_styles_as_fill_style
35
- style = create_graphic_style
36
- style.fill_color = '#0000ff'
26
+ def test_fill_color
27
+ style = create_graphic_style('fill-color' => '#0000ff')
28
+ assert_equal '#0000ff', style.fill_color
37
29
 
38
- assert_equal style.styles['fill'], '#0000ff'
30
+ style.fill_color = 'blue'
31
+ assert_equal 'blue', style.styles['fill-color']
32
+ assert_equal 'blue', style.fill_color
39
33
  end
40
34
 
41
- def test_border_should_return_an_Array_included_border_width_and_border_color
42
- style = create_graphic_style
43
- style.border_width = 1
44
- style.border_color = '#ff0000'
35
+ def test_border
36
+ style = create_graphic_style('border-color' => 'red', 'border-width' => 1)
37
+ assert_equal [1, 'red'], style.border
45
38
 
46
- assert_equal style.border, [style.border_width, style.border_color]
39
+ style.border = [2.0, '#ff0000']
40
+ assert_equal 2.0, style.styles['border-width']
41
+ assert_equal '#ff0000', style.styles['border-color']
47
42
  end
48
43
 
49
- def test_border_should_properly_set_both_border_width_and_border_color_from_the_specified_array_argument
50
- style = create_graphic_style
51
- style.border = [5, '#000000']
44
+ private
52
45
 
53
- assert_equal style.border, [5, '#000000']
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)
54
49
  end
55
50
  end