thinreports 0.8.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -6,7 +6,7 @@ class Thinreports::Core::Shape::Base::TestInternal < Minitest::Test
6
6
  include Thinreports::TestHelper
7
7
 
8
8
  def setup
9
- @report = Thinreports::Report.new layout: data_file('layout_text1.tlf')
9
+ @report = Thinreports::Report.new layout: layout_file.path
10
10
  @report.start_new_page
11
11
  end
12
12
 
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+
3
+ require 'test_helper'
4
+
5
+ class Thinreports::Core::Shape::Basic::TestBlockFormat < Minitest::Test
6
+ include Thinreports::TestHelper
7
+
8
+ BLOCK_FORMAT = {
9
+ 'value' => 'default value',
10
+ 'x' => 100.0,
11
+ 'y' => 200.0,
12
+ 'width' => 300.0,
13
+ 'height' => 400.0
14
+ }
15
+
16
+ Basic = Thinreports::Core::Shape::Basic
17
+
18
+ def test_attribute_readers
19
+ format = Basic::BlockFormat.new(BLOCK_FORMAT)
20
+
21
+ assert_equal 'default value', format.value
22
+ end
23
+ end
@@ -8,7 +8,7 @@ class Thinreports::Core::Shape::Basic::TestBlockInterface < Minitest::Test
8
8
  Basic = Thinreports::Core::Shape::Basic
9
9
 
10
10
  def setup
11
- report = Thinreports::Report.new layout: data_file('layout_text1')
11
+ report = Thinreports::Report.new layout: layout_file.path
12
12
  parent = report.start_new_page
13
13
 
14
14
  format = Basic::BlockFormat.new({})
@@ -7,11 +7,6 @@ class Thinreports::Core::Shape::Basic::TestBlockInternal < Minitest::Test
7
7
 
8
8
  Basic = Thinreports::Core::Shape::Basic
9
9
 
10
- def test_box_should_return_value_of_format
11
- internal = init_internal('box' => 'box of format')
12
- assert_equal internal.box, 'box of format'
13
- end
14
-
15
10
  def test_read_value_should_return_value_from_format
16
11
  internal = init_internal('value' => 'default value')
17
12
  assert_equal internal.read_value, 'default value'
@@ -46,11 +41,13 @@ class Thinreports::Core::Shape::Basic::TestBlockInternal < Minitest::Test
46
41
  end
47
42
 
48
43
  def test_type_of_asker_should_return_false_otherwise
49
- assert_equal [:iblock, :tblock, :text, :list].all? {|t| !init_internal.type_of?(t)}, true
44
+ assert_equal %w( image-block text-block text list ).all? {|t| !init_internal.type_of?(t)}, true
50
45
  end
51
46
 
47
+ private
48
+
52
49
  def init_internal(format = {})
53
- report = Thinreports::Report.new layout: data_file('layout_text1')
50
+ report = Thinreports::Report.new layout: layout_file.path
54
51
  parent = report.start_new_page
55
52
 
56
53
  Basic::BlockInternal.new(parent, Basic::BlockFormat.new(format))
@@ -5,55 +5,33 @@ require 'test_helper'
5
5
  class Thinreports::Core::Shape::Basic::TestFormat < Minitest::Test
6
6
  include Thinreports::TestHelper
7
7
 
8
- TEST_BASIC_FORMAT = {
9
- "type" => "s-rect",
10
- "id" => "rect_1",
11
- "display" => "true",
12
- "svg" => {
13
- "tag" => "rect",
14
- "attrs" => {
15
- "stroke" => "#000000",
16
- "stroke-width" => "1",
17
- "fill" => "#ff0000",
18
- "fill-opacity" => "1",
19
- "stroke-dasharray" => "none",
20
- "rx" => "0",
21
- "ry" => "0",
22
- "width" => "196.1",
23
- "height" => "135.1",
24
- "x" => "85",
25
- "y" => "82"
26
- }
8
+ RECT_FORMAT = {
9
+ "id" => "",
10
+ "type" => "rect",
11
+ "x" => 100.0,
12
+ "y" => 200.0,
13
+ "width" => 300.0,
14
+ "height" => 400.0,
15
+ "description" => "Description for rect",
16
+ "display" => true,
17
+ "rx" => 1.0,
18
+ "ry" => 1.0,
19
+ "style" => {
20
+ "border-width" => 1,
21
+ "border-color" => "#000000",
22
+ "border-style" => "dashed",
23
+ "fill-color" => "#ff0000"
27
24
  }
28
25
  }
29
26
 
30
- # Alias
31
- Format = Thinreports::Core::Shape::Basic::Format
27
+ Basic = Thinreports::Core::Shape::Basic
32
28
 
33
- def test_build_basic_format
34
- build_basic_format
35
- rescue => e
36
- flunk exception_details(e, 'Building failed.')
37
- end
38
-
39
- def test_basic_config_readers
40
- format = Format.new(TEST_BASIC_FORMAT)
41
-
42
- assert_equal format.id, 'rect_1'
43
- assert_equal format.type, 's-rect'
44
- assert_equal format.svg_tag, 'rect'
45
- assert_equal format.display?, true
46
- assert_equal format.svg_attrs['stroke'], '#000000'
47
- assert_equal format.svg_attrs['stroke-dasharray'], 'none'
48
- end
49
-
50
- def test_display?
51
- format = Format.new('display' => 'false')
52
-
53
- assert_equal format.display?, false
54
- end
55
-
56
- def build_basic_format
57
- Format.build(TEST_BASIC_FORMAT)
29
+ def test_attribute_readers
30
+ format = Basic::Format.new(RECT_FORMAT)
31
+
32
+ assert_equal '', format.id
33
+ assert_equal 'rect', format.type
34
+ assert_equal RECT_FORMAT['style'], format.style
35
+ assert_equal true, format.display?
58
36
  end
59
- end
37
+ end
@@ -9,7 +9,7 @@ class Thinreports::Core::Shape::Basic::TestInterface < Minitest::Test
9
9
  Basic = Thinreports::Core::Shape::Basic
10
10
 
11
11
  def create_interface(format_config = {})
12
- report = Thinreports::Report.new layout: data_file('layout_text1')
12
+ report = Thinreports::Report.new layout: layout_file.path
13
13
  parent = report.start_new_page
14
14
 
15
15
  Basic::Interface.new parent, Basic::Format.new(format_config)
@@ -26,24 +26,24 @@ class Thinreports::Core::Shape::Basic::TestInterface < Minitest::Test
26
26
  end
27
27
 
28
28
  def test_type_should_operate_as_delegator_of_internal
29
- basic = create_interface('type' => 's-rect')
29
+ basic = create_interface('type' => 'rect')
30
30
  assert_same basic.type, basic.internal.type
31
31
  end
32
32
 
33
33
  def test_visible_asker_should_return_result_with_reference_to_style_of_internal
34
- basic = create_interface('display' => 'false')
34
+ basic = create_interface('display' => false)
35
35
  assert_equal basic.visible?, basic.internal.style.visible
36
36
  end
37
37
 
38
38
  def test_visible_should_properly_set_visibility_to_style_of_internal
39
- basic = create_interface('display' => 'false')
39
+ basic = create_interface('display' => false)
40
40
  basic.visible(true)
41
41
 
42
42
  assert_equal basic.internal.style.visible, true
43
43
  end
44
44
 
45
45
  def test_style_should_operate_as_reader_when_one_argument_is_given
46
- basic = create_interface('svg' => {'attrs' => {'fill' => '#ff0000'}})
46
+ basic = create_interface('style' => { 'fill-color' => '#ff0000' })
47
47
 
48
48
  assert_equal basic.style(:fill_color), '#ff0000'
49
49
  end
@@ -9,7 +9,7 @@ class Thinreports::Core::Shape::Basic::TestInternal < Minitest::Test
9
9
  Basic = Thinreports::Core::Shape::Basic
10
10
 
11
11
  def create_internal(format_config = {})
12
- report = Thinreports::Report.new layout: data_file('layout_text1')
12
+ report = Thinreports::Report.new layout: layout_file.path
13
13
 
14
14
  Basic::Internal.new report.page, Basic::Format.new(format_config)
15
15
  end
@@ -19,13 +19,8 @@ class Thinreports::Core::Shape::Basic::TestInternal < Minitest::Test
19
19
  assert_same basic.id, basic.format.id
20
20
  end
21
21
 
22
- def test_svg_tag_should_operate_as_delegator_of_format
23
- basic = create_internal('svg' => {'tag' => 'rect'})
24
- assert_same basic.svg_tag, basic.format.svg_tag
25
- end
26
-
27
22
  def test_type_should_operate_as_delegator_of_format
28
- basic = create_internal('type' => 's-ellipse')
23
+ basic = create_internal('type' => 'ellipse')
29
24
  assert_same basic.type, basic.format.type
30
25
  end
31
26
 
@@ -41,10 +36,10 @@ class Thinreports::Core::Shape::Basic::TestInternal < Minitest::Test
41
36
  def test_type_of_asker_should_return_true_when_the_specified_type_equal_self_type_name
42
37
  result = []
43
38
 
44
- result << create_internal('type' => 's-rect').type_of?(:rect)
45
- result << create_internal('type' => 's-ellipse').type_of?(:ellipse)
46
- result << create_internal('type' => 's-line').type_of?(:line)
47
- result << create_internal('type' => 's-image').type_of?(:image)
39
+ result << create_internal('type' => 'rect').type_of?('rect')
40
+ result << create_internal('type' => 'ellipse').type_of?('ellipse')
41
+ result << create_internal('type' => 'line').type_of?('line')
42
+ result << create_internal('type' => 'image').type_of?('image')
48
43
 
49
44
  assert_equal result.all?, true
50
45
  end
@@ -8,17 +8,17 @@ class Thinreports::Core::Shape::ImageBlock::TestInterface < Minitest::Test
8
8
  ImageBlock = Thinreports::Core::Shape::ImageBlock
9
9
 
10
10
  def setup
11
- @report = new_report 'layout_block.tlf'
11
+ @report = Thinreports::Report.new layout: layout_file.path
12
12
  @page = @report.start_new_page
13
13
  end
14
14
 
15
15
  def test_src
16
- @page.item(:image_block1).src('/path/to/image.png')
17
- assert_equal '/path/to/image.png', @page.item(:image_block1).src
16
+ @page.item(:image_block).src('/path/to/image.png')
17
+ assert_equal '/path/to/image.png', @page.item(:image_block).src
18
18
  end
19
19
 
20
20
  def test_src=
21
- @page.item(:image_block1).src = '/path/to/image.png'
22
- assert_equal '/path/to/image.png', @page.item(:image_block1).src
21
+ @page.item(:image_block).src = '/path/to/image.png'
22
+ assert_equal '/path/to/image.png', @page.item(:image_block).src
23
23
  end
24
24
  end
@@ -15,7 +15,7 @@ class Thinreports::Core::Shape::ImageBlock::TestInternal < Minitest::Test
15
15
  end
16
16
 
17
17
  def test_type_of_asker_should_return_true_when_iblock_value_is_given
18
- assert_equal create_internal.type_of?(:iblock), true
18
+ assert_equal create_internal.type_of?('image-block'), true
19
19
  end
20
20
 
21
21
  def test_type_of_asker_should_return_true_when_block_value_is_given
@@ -23,7 +23,7 @@ class Thinreports::Core::Shape::ImageBlock::TestInternal < Minitest::Test
23
23
  end
24
24
 
25
25
  def create_internal
26
- report = new_report 'layout_text1'
26
+ report = Thinreports::Report.new layout: layout_file.path
27
27
  parent = report.start_new_page
28
28
 
29
29
  ImageBlock::Internal.new parent, ImageBlock::Format.new({})
@@ -5,65 +5,107 @@ require 'test_helper'
5
5
  class Thinreports::Core::Shape::List::TestFormat < Minitest::Test
6
6
  include Thinreports::TestHelper
7
7
 
8
- TEST_LIST_FORMAT = {
9
- "type" => "s-list",
10
- "id" => "List",
11
- "display" => "true",
12
- "page-footer-enabled" => "true",
13
- "footer-enabled" => "true",
14
- "header-enabled" => "true",
15
- "page-break" => "true",
16
- "content-height" => 255,
17
- "detail" => {},
18
- "footer" => {},
19
- "page-footer" => {},
20
- "header" => {},
21
- "svg" => {
22
- "tag" => "g",
23
- "attrs" => {}
8
+ LIST_FORMAT = {
9
+ 'type' => 'list',
10
+ 'id' => 'list',
11
+ 'display' => true,
12
+ 'x' => 10.0,
13
+ 'y' => 20.0,
14
+ 'width' => 30.0,
15
+ 'height' => 40.0,
16
+ 'content-height' => 255,
17
+ 'auto-page-break' => true,
18
+ 'header' => {
19
+ 'enabled' => true,
20
+ 'height' => 10.0,
21
+ 'translate' => { 'x' => 210.0, 'y' => 310.0 },
22
+ 'items' => []
23
+ },
24
+ 'detail' => {
25
+ 'height' => 20.0,
26
+ 'translate' => { 'x' => 220.0, 'y' => 320.0 },
27
+ 'items' => []
28
+ },
29
+ 'page-footer' => {
30
+ 'enabled' => true,
31
+ 'height' => 30.0,
32
+ 'translate' => { 'x' => 230.0, 'y' => 330.0 },
33
+ 'items' => []
34
+ },
35
+ 'footer' => {
36
+ 'enabled' => false,
37
+ 'height' => 40.0,
38
+ 'translate' => { 'x' => 240.0, 'y' => 340.0 },
39
+ 'items' => []
24
40
  }
25
41
  }
26
42
 
27
43
  List = Thinreports::Core::Shape::List
28
44
 
29
- def test_build_when_all_sections_enabled
30
- List::SectionFormat.expects(:build).returns({}).times(4)
45
+ def test_has_section?
46
+ format = List::Format.new(LIST_FORMAT)
31
47
 
32
- begin
33
- format = build_format
34
- rescue => e
35
- flunk exception_details(e, 'Building failed.')
36
- end
48
+ assert_equal true, format.has_section?(:detail)
49
+ assert_equal true, format.has_section?(:page_footer)
50
+ assert_equal false, format.has_section?(:footer)
51
+ end
52
+
53
+ def test_section_height
54
+ format = List::Format.new(LIST_FORMAT)
55
+
56
+ assert_equal 10.0, format.section_height(:header)
57
+ end
58
+
59
+ def test_attribute_readers
60
+ format = List::Format.new(LIST_FORMAT)
37
61
 
38
- assert_equal format.sections.size, 4
39
- [:detail, :header, :footer, :page_footer].each do |sec|
40
- assert_includes format.sections.keys, sec
41
- end
62
+ assert_equal 255, format.height
63
+ assert_equal true, format.auto_page_break?
64
+ assert_equal true, format.has_header?
65
+ assert_equal true, format.has_page_footer?
66
+ assert_equal false, format.has_footer?
67
+ assert_equal 20.0, format.detail_height
68
+ assert_equal 30.0, format.page_footer_height
69
+ assert_equal 40.0, format.footer_height
70
+ assert_equal 10.0, format.header_height
42
71
  end
43
72
 
44
- def test_build_when_page_footer_and_footer_disabled
45
- List::SectionFormat.expects(:build).returns({}).times(2)
73
+ def test_section_base_position_top
74
+ page_footer_disabled = LIST_FORMAT
75
+
76
+ format = List::Format.new(page_footer_disabled)
77
+ assert_equal 310.0, format.section_base_position_top(:header)
78
+ assert_equal 320.0, format.section_base_position_top(:detail)
79
+ assert_equal 310.0, format.section_base_position_top(:page_footer)
80
+ assert_equal 0, format.section_base_position_top(:footer)
46
81
 
47
- format = build_format('page-footer-enabled' => 'false',
48
- 'footer-enabled' => 'false')
82
+ format_footer_enabled = format_section_enabled(true, 'footer', LIST_FORMAT)
49
83
 
50
- assert_equal format.sections.size, 2
51
- [:detail, :header].each do |sec|
52
- assert_includes format.sections.keys, sec
53
- end
84
+ format = List::Format.new(format_footer_enabled)
85
+ assert_equal 290.0, format.section_base_position_top(:footer)
86
+
87
+ format_footer_enabld_and_page_footer_disabled = format_section_enabled(false, 'page-footer', format_footer_enabled)
88
+
89
+ format = List::Format.new(format_footer_enabld_and_page_footer_disabled)
90
+ assert_equal 320.0, format.section_base_position_top(:footer)
54
91
  end
55
92
 
56
- def test_config_readers
57
- format = List::Format.new(TEST_LIST_FORMAT)
93
+ def test_initialize_sections
94
+ format = List::Format.new(LIST_FORMAT)
95
+
96
+ assert_instance_of List::SectionFormat, format.sections[:header]
97
+ assert_instance_of List::SectionFormat, format.sections[:detail]
98
+ assert_instance_of List::SectionFormat, format.sections[:page_footer]
58
99
 
59
- assert_equal format.height, 255
60
- assert_equal format.auto_page_break?, true
61
- assert_equal format.has_header?, true
62
- assert_equal format.has_footer?, true
63
- assert_equal format.has_page_footer?, true
100
+ assert_nil format.sections[:footer]
64
101
  end
65
102
 
66
- def build_format(data = {})
67
- List::Format.build(TEST_LIST_FORMAT.merge(data))
103
+ private
104
+
105
+ def format_section_enabled(enable, section, list_format)
106
+ section_format = list_format[section].dup
107
+ section_format['enabled'] = enable
108
+
109
+ list_format.merge(section => section_format)
68
110
  end
69
111
  end
@@ -9,16 +9,14 @@ class Thinreports::Core::Shape::List::TestManager < Minitest::Test
9
9
  List = Thinreports::Core::Shape::List
10
10
 
11
11
  def create_report(&block)
12
- new_report('layout_list.tlf', &block)
12
+ report = Thinreports::Report.new layout: layout_file.path
13
+ block.call(report) if block_given?
14
+ report
13
15
  end
14
16
 
15
17
  def list_manager
16
18
  report = create_report {|r| r.start_new_page }
17
- report.page.list(:list).manager
18
- end
19
-
20
- def test_config_should_return_the_instance_of_ListConfiguration
21
- assert_same list_manager.config.class, List::Configuration
19
+ report.page.list.manager
22
20
  end
23
21
 
24
22
  def test_current_page_should_return_the_instance_of_ListPage
@@ -31,7 +29,7 @@ class Thinreports::Core::Shape::List::TestManager < Minitest::Test
31
29
 
32
30
  def test_switch_current_should_replace_own_current_page_property_by_the_given_page
33
31
  report = create_report {|r| r.start_new_page }
34
- list = report.page.list(:list)
32
+ list = report.page.list
35
33
  new_page = List::Page.new(report.page, list.internal.format)
36
34
 
37
35
  list.manager.switch_current!(new_page)
@@ -41,7 +39,7 @@ class Thinreports::Core::Shape::List::TestManager < Minitest::Test
41
39
 
42
40
  def test_switch_current_should_replace_own_current_page_state_property_by_internal_property_of_the_given_page
43
41
  report = create_report {|r| r.start_new_page }
44
- list = report.page.list(:list)
42
+ list = report.page.list
45
43
  new_page = List::Page.new(report.page, list.internal.format)
46
44
 
47
45
  list.manager.switch_current!(new_page)
@@ -51,72 +49,19 @@ class Thinreports::Core::Shape::List::TestManager < Minitest::Test
51
49
 
52
50
  def test_switch_current_should_return_the_self
53
51
  report = create_report {|r| r.start_new_page }
54
- list = report.page.list(:list)
52
+ list = report.page.list
55
53
  new_page = List::Page.new(report.page, list.internal.format)
56
54
 
57
55
  assert_same list.manager.switch_current!(new_page), list.manager
58
56
  end
59
57
 
60
- def test_finalize_page_should_dispatch_page_finalize_event
61
- flag = false
62
-
63
- report = create_report do |r|
64
- r.layout.config.list(:list) do
65
- events.on :page_finalize do
66
- flag = true
67
- end
68
- end
69
- end
70
-
71
- report.start_new_page do |page|
72
- page.list(:list).manager.finalize_page
73
- end
74
-
75
- assert flag, 'The :page_finalize event was not dispatched.'
76
- end
77
-
78
- def test_page_property_which_dispatcher_of_finalize_page_event_should_return_the_current_page
79
- page_used_in_event = nil
80
-
81
- report = create_report do |r|
82
- r.layout.config.list(:list) do
83
- events.on :page_finalize do |e|
84
- page_used_in_event = e.page
85
- end
86
- end
87
- end
88
-
89
- current_page = report.start_new_page
90
- current_page.list(:list).manager.finalize_page
91
-
92
- assert_same page_used_in_event, current_page
93
- end
94
-
95
- def test_list_property_which_dispatcher_of_finalize_event_should_return_the_current_page_of_list
96
- list_used_in_event = nil
97
-
98
- report = create_report do |r|
99
- r.layout.config.list(:list) do
100
- events.on :page_finalize do |e|
101
- list_used_in_event = e.list
102
- end
103
- end
104
- end
105
-
106
- report.start_new_page
107
- current_list = report.page.list(:list)
108
- current_list.manager.finalize_page
109
-
110
- assert_same list_used_in_event, current_list
111
- end
112
-
113
58
  def test_page_count
114
59
  report = create_report
115
60
  assert_equal report.page_count, 0
116
61
 
117
- report.list(:list).page_break
118
- report.list(:list).page_break
62
+ report.list.page_break
63
+ report.list.page_break
119
64
 
120
- assert_equal report.list(:list).manager.page_count, 2
65
+ assert_equal report.list.manager.page_count, 2
121
66
  end
122
67
  end