thinreports 0.12.1 → 0.13.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 (177) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +3 -3
  3. data/.github/workflows/test.yml +28 -36
  4. data/.gitignore +1 -1
  5. data/CHANGELOG.md +19 -1
  6. data/Gemfile +11 -0
  7. data/README.md +12 -17
  8. data/Rakefile +17 -11
  9. data/lib/thinreports/basic_report/core/errors.rb +62 -0
  10. data/lib/thinreports/basic_report/core/format/base.rb +91 -0
  11. data/lib/thinreports/basic_report/core/shape/base/interface.rb +42 -0
  12. data/lib/thinreports/basic_report/core/shape/base/internal.rb +53 -0
  13. data/lib/thinreports/basic_report/core/shape/basic/block_format.rb +15 -0
  14. data/lib/thinreports/basic_report/core/shape/basic/block_interface.rb +34 -0
  15. data/lib/thinreports/basic_report/core/shape/basic/block_internal.rb +36 -0
  16. data/lib/thinreports/basic_report/core/shape/basic/format.rb +24 -0
  17. data/lib/thinreports/basic_report/core/shape/basic/interface.rb +87 -0
  18. data/lib/thinreports/basic_report/core/shape/basic/internal.rb +28 -0
  19. data/lib/thinreports/{core → basic_report/core}/shape/basic.rb +6 -4
  20. data/lib/thinreports/basic_report/core/shape/image_block/format.rb +14 -0
  21. data/lib/thinreports/basic_report/core/shape/image_block/interface.rb +25 -0
  22. data/lib/thinreports/basic_report/core/shape/image_block/internal.rb +19 -0
  23. data/lib/thinreports/{core → basic_report/core}/shape/image_block.rb +6 -4
  24. data/lib/thinreports/basic_report/core/shape/list/format.rb +92 -0
  25. data/lib/thinreports/basic_report/core/shape/list/manager.rb +231 -0
  26. data/lib/thinreports/basic_report/core/shape/list/page.rb +112 -0
  27. data/lib/thinreports/basic_report/core/shape/list/page_state.rb +50 -0
  28. data/lib/thinreports/basic_report/core/shape/list/section_format.rb +37 -0
  29. data/lib/thinreports/basic_report/core/shape/list/section_interface.rb +51 -0
  30. data/lib/thinreports/basic_report/core/shape/list/section_internal.rb +33 -0
  31. data/lib/thinreports/{core → basic_report/core}/shape/list.rb +6 -4
  32. data/lib/thinreports/basic_report/core/shape/manager/format.rb +33 -0
  33. data/lib/thinreports/basic_report/core/shape/manager/internal.rb +109 -0
  34. data/lib/thinreports/basic_report/core/shape/manager/target.rb +114 -0
  35. data/lib/thinreports/basic_report/core/shape/page_number/format.rb +32 -0
  36. data/lib/thinreports/basic_report/core/shape/page_number/interface.rb +31 -0
  37. data/lib/thinreports/basic_report/core/shape/page_number/internal.rb +57 -0
  38. data/lib/thinreports/{core → basic_report/core}/shape/page_number.rb +6 -4
  39. data/lib/thinreports/basic_report/core/shape/stack_view/format.rb +29 -0
  40. data/lib/thinreports/basic_report/core/shape/stack_view/interface.rb +19 -0
  41. data/lib/thinreports/basic_report/core/shape/stack_view/internal.rb +24 -0
  42. data/lib/thinreports/basic_report/core/shape/stack_view/row_format.rb +41 -0
  43. data/lib/thinreports/{core → basic_report/core}/shape/stack_view.rb +6 -4
  44. data/lib/thinreports/basic_report/core/shape/style/base.rb +149 -0
  45. data/lib/thinreports/basic_report/core/shape/style/basic.rb +24 -0
  46. data/lib/thinreports/basic_report/core/shape/style/graphic.rb +43 -0
  47. data/lib/thinreports/basic_report/core/shape/style/text.rb +122 -0
  48. data/lib/thinreports/basic_report/core/shape/text/format.rb +17 -0
  49. data/lib/thinreports/basic_report/core/shape/text/interface.rb +20 -0
  50. data/lib/thinreports/basic_report/core/shape/text/internal.rb +24 -0
  51. data/lib/thinreports/{core → basic_report/core}/shape/text.rb +6 -4
  52. data/lib/thinreports/basic_report/core/shape/text_block/format.rb +43 -0
  53. data/lib/thinreports/basic_report/core/shape/text_block/formatter/basic.rb +41 -0
  54. data/lib/thinreports/basic_report/core/shape/text_block/formatter/datetime.rb +25 -0
  55. data/lib/thinreports/basic_report/core/shape/text_block/formatter/number.rb +69 -0
  56. data/lib/thinreports/basic_report/core/shape/text_block/formatter/padding.rb +27 -0
  57. data/lib/thinreports/basic_report/core/shape/text_block/formatter.rb +38 -0
  58. data/lib/thinreports/basic_report/core/shape/text_block/interface.rb +37 -0
  59. data/lib/thinreports/basic_report/core/shape/text_block/internal.rb +75 -0
  60. data/lib/thinreports/{core → basic_report/core}/shape/text_block.rb +6 -4
  61. data/lib/thinreports/basic_report/core/shape.rb +44 -0
  62. data/lib/thinreports/basic_report/core/utils.rb +47 -0
  63. data/lib/thinreports/basic_report/generator/pdf/document/draw_shape.rb +108 -0
  64. data/lib/thinreports/basic_report/generator/pdf/document/draw_template_items.rb +71 -0
  65. data/lib/thinreports/basic_report/generator/pdf/document/font.rb +90 -0
  66. data/lib/thinreports/basic_report/generator/pdf/document/graphics/attributes.rb +149 -0
  67. data/lib/thinreports/basic_report/generator/pdf/document/graphics/basic.rb +137 -0
  68. data/lib/thinreports/basic_report/generator/pdf/document/graphics/image.rb +99 -0
  69. data/lib/thinreports/basic_report/generator/pdf/document/graphics/text.rb +180 -0
  70. data/lib/thinreports/basic_report/generator/pdf/document/graphics.rb +42 -0
  71. data/lib/thinreports/basic_report/generator/pdf/document/page.rb +96 -0
  72. data/lib/thinreports/basic_report/generator/pdf/document/parse_color.rb +51 -0
  73. data/lib/thinreports/basic_report/generator/pdf/document.rb +132 -0
  74. data/lib/thinreports/basic_report/generator/pdf/drawer/base.rb +50 -0
  75. data/lib/thinreports/basic_report/generator/pdf/drawer/list.rb +65 -0
  76. data/lib/thinreports/basic_report/generator/pdf/drawer/list_section.rb +51 -0
  77. data/lib/thinreports/basic_report/generator/pdf/drawer/page.rb +127 -0
  78. data/lib/thinreports/basic_report/generator/pdf/prawn_ext/calc_image_dimensions.rb +34 -0
  79. data/lib/thinreports/basic_report/generator/pdf/prawn_ext/width_of.rb +31 -0
  80. data/lib/thinreports/basic_report/generator/pdf.rb +66 -0
  81. data/lib/thinreports/basic_report/layout/base.rb +48 -0
  82. data/lib/thinreports/basic_report/layout/format.rb +67 -0
  83. data/lib/thinreports/basic_report/layout/legacy_schema.rb +383 -0
  84. data/lib/thinreports/basic_report/layout/version.rb +41 -0
  85. data/lib/thinreports/{layout.rb → basic_report/layout.rb} +6 -4
  86. data/lib/thinreports/basic_report/report/base.rb +173 -0
  87. data/lib/thinreports/basic_report/report/internal.rb +107 -0
  88. data/lib/thinreports/basic_report/report/page.rb +97 -0
  89. data/lib/thinreports/basic_report/report.rb +26 -0
  90. data/lib/thinreports/basic_report.rb +15 -0
  91. data/lib/thinreports/config.rb +1 -1
  92. data/lib/thinreports/section_report.rb +12 -0
  93. data/lib/thinreports/version.rb +1 -1
  94. data/lib/thinreports.rb +2 -13
  95. data/thinreports.gemspec +3 -7
  96. metadata +97 -154
  97. data/gemfiles/prawn-2.2.gemfile +0 -5
  98. data/gemfiles/prawn-2.3.gemfile +0 -5
  99. data/gemfiles/prawn-2.4.gemfile +0 -5
  100. data/lib/thinreports/core/errors.rb +0 -60
  101. data/lib/thinreports/core/format/base.rb +0 -89
  102. data/lib/thinreports/core/shape/base/interface.rb +0 -40
  103. data/lib/thinreports/core/shape/base/internal.rb +0 -51
  104. data/lib/thinreports/core/shape/basic/block_format.rb +0 -13
  105. data/lib/thinreports/core/shape/basic/block_interface.rb +0 -32
  106. data/lib/thinreports/core/shape/basic/block_internal.rb +0 -34
  107. data/lib/thinreports/core/shape/basic/format.rb +0 -22
  108. data/lib/thinreports/core/shape/basic/interface.rb +0 -85
  109. data/lib/thinreports/core/shape/basic/internal.rb +0 -26
  110. data/lib/thinreports/core/shape/image_block/format.rb +0 -12
  111. data/lib/thinreports/core/shape/image_block/interface.rb +0 -23
  112. data/lib/thinreports/core/shape/image_block/internal.rb +0 -17
  113. data/lib/thinreports/core/shape/list/format.rb +0 -90
  114. data/lib/thinreports/core/shape/list/manager.rb +0 -229
  115. data/lib/thinreports/core/shape/list/page.rb +0 -110
  116. data/lib/thinreports/core/shape/list/page_state.rb +0 -48
  117. data/lib/thinreports/core/shape/list/section_format.rb +0 -35
  118. data/lib/thinreports/core/shape/list/section_interface.rb +0 -49
  119. data/lib/thinreports/core/shape/list/section_internal.rb +0 -31
  120. data/lib/thinreports/core/shape/manager/format.rb +0 -31
  121. data/lib/thinreports/core/shape/manager/internal.rb +0 -107
  122. data/lib/thinreports/core/shape/manager/target.rb +0 -112
  123. data/lib/thinreports/core/shape/page_number/format.rb +0 -30
  124. data/lib/thinreports/core/shape/page_number/interface.rb +0 -29
  125. data/lib/thinreports/core/shape/page_number/internal.rb +0 -55
  126. data/lib/thinreports/core/shape/stack_view/format.rb +0 -27
  127. data/lib/thinreports/core/shape/stack_view/interface.rb +0 -17
  128. data/lib/thinreports/core/shape/stack_view/internal.rb +0 -22
  129. data/lib/thinreports/core/shape/stack_view/row_format.rb +0 -39
  130. data/lib/thinreports/core/shape/style/base.rb +0 -146
  131. data/lib/thinreports/core/shape/style/basic.rb +0 -22
  132. data/lib/thinreports/core/shape/style/graphic.rb +0 -41
  133. data/lib/thinreports/core/shape/style/text.rb +0 -120
  134. data/lib/thinreports/core/shape/text/format.rb +0 -15
  135. data/lib/thinreports/core/shape/text/interface.rb +0 -18
  136. data/lib/thinreports/core/shape/text/internal.rb +0 -22
  137. data/lib/thinreports/core/shape/text_block/format.rb +0 -41
  138. data/lib/thinreports/core/shape/text_block/formatter/basic.rb +0 -39
  139. data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +0 -23
  140. data/lib/thinreports/core/shape/text_block/formatter/number.rb +0 -67
  141. data/lib/thinreports/core/shape/text_block/formatter/padding.rb +0 -25
  142. data/lib/thinreports/core/shape/text_block/formatter.rb +0 -34
  143. data/lib/thinreports/core/shape/text_block/interface.rb +0 -35
  144. data/lib/thinreports/core/shape/text_block/internal.rb +0 -73
  145. data/lib/thinreports/core/shape.rb +0 -42
  146. data/lib/thinreports/core/utils.rb +0 -45
  147. data/lib/thinreports/generate.rb +0 -11
  148. data/lib/thinreports/generator/pdf/document/draw_shape.rb +0 -106
  149. data/lib/thinreports/generator/pdf/document/draw_template_items.rb +0 -69
  150. data/lib/thinreports/generator/pdf/document/font.rb +0 -88
  151. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +0 -147
  152. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +0 -135
  153. data/lib/thinreports/generator/pdf/document/graphics/image.rb +0 -98
  154. data/lib/thinreports/generator/pdf/document/graphics/text.rb +0 -178
  155. data/lib/thinreports/generator/pdf/document/graphics.rb +0 -40
  156. data/lib/thinreports/generator/pdf/document/page.rb +0 -94
  157. data/lib/thinreports/generator/pdf/document/parse_color.rb +0 -49
  158. data/lib/thinreports/generator/pdf/document.rb +0 -130
  159. data/lib/thinreports/generator/pdf/drawer/base.rb +0 -48
  160. data/lib/thinreports/generator/pdf/drawer/list.rb +0 -63
  161. data/lib/thinreports/generator/pdf/drawer/list_section.rb +0 -49
  162. data/lib/thinreports/generator/pdf/drawer/page.rb +0 -125
  163. data/lib/thinreports/generator/pdf/prawn_ext/calc_image_dimensions.rb +0 -32
  164. data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +0 -29
  165. data/lib/thinreports/generator/pdf.rb +0 -63
  166. data/lib/thinreports/layout/base.rb +0 -46
  167. data/lib/thinreports/layout/format.rb +0 -65
  168. data/lib/thinreports/layout/legacy_schema.rb +0 -381
  169. data/lib/thinreports/layout/version.rb +0 -39
  170. data/lib/thinreports/report/base.rb +0 -169
  171. data/lib/thinreports/report/internal.rb +0 -105
  172. data/lib/thinreports/report/page.rb +0 -95
  173. data/lib/thinreports/report.rb +0 -24
  174. /data/lib/thinreports/{core → basic_report/core}/shape/base.rb +0 -0
  175. /data/lib/thinreports/{core → basic_report/core}/shape/manager.rb +0 -0
  176. /data/lib/thinreports/{core → basic_report/core}/shape/style.rb +0 -0
  177. /data/lib/thinreports/{generator → basic_report/generator}/pdf/prawn_ext.rb +0 -0
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Core
5
- module Shape
6
- module Text
7
- class Internal < Basic::Internal
8
- # Delegate to Format's methods
9
- format_delegators :texts, :box
10
-
11
- def style
12
- @style ||= Style::Text.new(format)
13
- end
14
-
15
- def type_of?(type_name)
16
- type_name == Text::TYPE_NAME
17
- end
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Core
5
- module Shape
6
- module TextBlock
7
- class Format < Basic::BlockFormat
8
- # For saving compatible 0.8.x format API
9
- config_reader ref_id: %w[reference-id]
10
- config_reader valign: %w[style vertical-align]
11
- config_reader overflow: %w[style overflow]
12
- config_reader line_height: %w[style line-height]
13
-
14
- config_reader format_base: %w[format base],
15
- format_type: %w[format type],
16
- format_datetime_format: %w[format datetime format],
17
- format_number_delimiter: %w[format number delimiter],
18
- format_number_precision: %w[format number precision],
19
- format_padding_char: %w[format padding char],
20
- format_padding_dir: %w[format padding direction]
21
-
22
- config_checker true, multiple: %w[multiple-line]
23
- config_checker 'R', format_padding_rdir: %w[format padding direction]
24
-
25
- config_reader format_padding_length: %w[format padding length] do |len|
26
- blank_value?(len) ? 0 : len.to_i
27
- end
28
-
29
- config_reader has_format?: %w[format type] do |type|
30
- %w[datetime number padding].include?(type)
31
- end
32
-
33
- # For saving compatible 0.8.x format API
34
- def has_reference?
35
- !blank_value?(ref_id)
36
- end
37
- end
38
- end
39
- end
40
- end
41
- end
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Core
5
- module Shape
6
- module TextBlock
7
- module Formatter
8
- class Basic
9
- include Utils
10
-
11
- attr_reader :format
12
-
13
- def initialize(format)
14
- @format = format
15
- end
16
-
17
- def apply(value)
18
- value = apply_format_to(value) if applicable?(value)
19
-
20
- return value if blank_value?(format.format_base)
21
-
22
- format.format_base.gsub(/\{value\}/, value.to_s)
23
- end
24
-
25
- private
26
-
27
- def apply_format_to(value)
28
- value
29
- end
30
-
31
- def applicable?(_value)
32
- true
33
- end
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Core
5
- module Shape
6
- module TextBlock
7
- module Formatter
8
- class Datetime < Formatter::Basic
9
- private
10
-
11
- def apply_format_to(value)
12
- value.strftime(format.format_datetime_format)
13
- end
14
-
15
- def applicable?(value)
16
- !blank_value?(format.format_datetime_format) && value.respond_to?(:strftime)
17
- end
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,67 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bigdecimal'
4
-
5
- module Thinreports
6
- module Core
7
- module Shape
8
- module TextBlock
9
- module Formatter
10
- class Number < Formatter::Basic
11
- private
12
-
13
- def apply_format_to(value)
14
- precision = format.format_number_precision
15
- delimiter = format.format_number_delimiter
16
-
17
- if_applicable value do |val|
18
- val = number_with_precision(val, precision) unless blank_value?(precision)
19
- val = number_with_delimiter(val, delimiter) unless blank_value?(delimiter)
20
- val
21
- end
22
- end
23
-
24
- def if_applicable(value, &block)
25
- normalized_value = normalize(value)
26
- normalized_value.nil? ? value : block.call(normalized_value)
27
- end
28
-
29
- def normalize(value)
30
- if value.is_a?(String)
31
- convert_to_integer(value) || convert_to_float(value)
32
- else
33
- value
34
- end
35
- end
36
-
37
- def number_with_delimiter(value, delimiter = ',')
38
- value_int, value_float = value.to_s.split('.')
39
-
40
- [
41
- value_int.gsub(/(\d)(?=(\d{3})+(?!\d))/) { "#{$1}#{delimiter}" },
42
- value_float
43
- ].compact.join('.')
44
- end
45
-
46
- def number_with_precision(value, precision = 3)
47
- value = BigDecimal(value.to_s).round(precision)
48
- sprintf("%.#{precision}f", value)
49
- end
50
-
51
- def convert_to_integer(value)
52
- Integer(value)
53
- rescue ArgumentError
54
- nil
55
- end
56
-
57
- def convert_to_float(value)
58
- Float(value)
59
- rescue ArgumentError
60
- nil
61
- end
62
- end
63
- end
64
- end
65
- end
66
- end
67
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Core
5
- module Shape
6
- module TextBlock
7
- module Formatter
8
- class Padding < Formatter::Basic
9
- private
10
-
11
- def apply_format_to(value)
12
- value.to_s.send(format.format_padding_rdir? ? :ljust : :rjust,
13
- format.format_padding_length,
14
- format.format_padding_char)
15
- end
16
-
17
- def applicable?(_value)
18
- !blank_value?(format.format_padding_char) && format.format_padding_length > 0
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Core
5
- module Shape
6
- module TextBlock
7
- module Formatter
8
- # @param [Thinreports::Core::Shape::TextBlock::Format] format
9
- # @return [Thinreports::Core::Shape::TextBlock::Formatter::Base]
10
- def self.setup(format)
11
- klass =
12
- if Thinreports.blank_value?(format.format_type)
13
- Basic
14
- else
15
- case format.format_type
16
- when 'number' then Number
17
- when 'datetime' then Datetime
18
- when 'padding' then Padding
19
- else
20
- raise Thinreports::Errors::UnknownFormatterType
21
- end
22
- end
23
- klass.new(format)
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end
30
-
31
- require_relative 'formatter/basic'
32
- require_relative 'formatter/datetime'
33
- require_relative 'formatter/padding'
34
- require_relative 'formatter/number'
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Core
5
- module Shape
6
- module TextBlock
7
- class Interface < Basic::BlockInterface
8
- internal_delegators :format_enabled?
9
-
10
- # @param [Boolean] enabled
11
- # @return [self]
12
- def format_enabled(enabled)
13
- internal.format_enabled(enabled)
14
- self
15
- end
16
-
17
- # @param [Object] val
18
- # @param [Hash<Symbol, Object>] style_settings
19
- # @return [self]
20
- def set(val, style_settings = {})
21
- value(val)
22
- styles(style_settings) #=> self
23
- end
24
-
25
- private
26
-
27
- # @see Thinreports::Core::Shape::Base::Interface#init_internal
28
- def init_internal(parent, format)
29
- TextBlock::Internal.new(parent, format)
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end
@@ -1,73 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Core
5
- module Shape
6
- module TextBlock
7
- class Internal < Basic::BlockInternal
8
- format_delegators :multiple?
9
-
10
- attr_reader :style
11
-
12
- def initialize(*args)
13
- super(*args)
14
-
15
- @reference = nil
16
- @formatter = nil
17
-
18
- @style = Style::Text.new(format)
19
- @style.accessible_styles.delete(:valign) unless multiple?
20
- end
21
-
22
- def read_value
23
- if format.has_reference?
24
- @reference ||= parent.item(format.ref_id)
25
- @reference.value
26
- else
27
- super
28
- end
29
- end
30
-
31
- def write_value(val)
32
- if format.has_reference?
33
- warn 'The set value was not saved, ' \
34
- "Because '#{format.id}' has reference to '#{format.ref_id}'."
35
- else
36
- super
37
- end
38
- end
39
-
40
- def real_value
41
- if format_enabled?
42
- formatter.apply(read_value)
43
- else
44
- super
45
- end
46
- end
47
-
48
- def format_enabled(enabled)
49
- states[:format_enabled] = enabled
50
- end
51
-
52
- def format_enabled?
53
- if states.key?(:format_enabled)
54
- states[:format_enabled]
55
- else
56
- !blank_value?(format.format_base) || format.has_format?
57
- end
58
- end
59
-
60
- def type_of?(type_name)
61
- type_name == TextBlock::TYPE_NAME || super
62
- end
63
-
64
- private
65
-
66
- def formatter
67
- @formatter ||= TextBlock::Formatter.setup(format)
68
- end
69
- end
70
- end
71
- end
72
- end
73
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Core
5
- module Shape
6
- def Interface(parent, format)
7
- find_by_type(format.type)::Interface.new(parent, format)
8
- end
9
-
10
- def Format(type)
11
- find_by_type(type)::Format
12
- end
13
-
14
- module_function :Interface, :Format
15
-
16
- def self.find_by_type(type)
17
- case type
18
- when TextBlock::TYPE_NAME then TextBlock
19
- when ImageBlock::TYPE_NAME then ImageBlock
20
- when List::TYPE_NAME then List
21
- when StackView::TYPE_NAME then StackView
22
- when Text::TYPE_NAME then Text
23
- when PageNumber::TYPE_NAME then PageNumber
24
- when *Basic::TYPE_NAMES then Basic
25
- else
26
- raise Thinreports::Errors::UnknownShapeType
27
- end
28
- end
29
- end
30
- end
31
- end
32
-
33
- require_relative 'shape/style'
34
- require_relative 'shape/manager'
35
- require_relative 'shape/base'
36
- require_relative 'shape/basic'
37
- require_relative 'shape/text'
38
- require_relative 'shape/text_block'
39
- require_relative 'shape/image_block'
40
- require_relative 'shape/list'
41
- require_relative 'shape/stack_view'
42
- require_relative 'shape/page_number'
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Utils
5
- def self.included(klass)
6
- klass.extend self
7
- end
8
-
9
- def deep_copy(src)
10
- case src
11
- when Hash
12
- src.each_with_object({}) do |(k, v), h|
13
- h[k] = v.dup rescue v
14
- end
15
- when Array
16
- src.map do |a|
17
- a.dup rescue a
18
- end
19
- else
20
- raise ArgumentError
21
- end
22
- end
23
-
24
- def blank_value?(value)
25
- case value
26
- when String then value.empty?
27
- when NilClass then true
28
- else false
29
- end
30
- end
31
-
32
- def call_block_in(scope, &block)
33
- return scope unless block_given?
34
-
35
- if block.arity == 1
36
- block.call(scope)
37
- else
38
- scope.instance_eval(&block)
39
- end
40
- scope
41
- end
42
- end
43
-
44
- extend Utils
45
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'section_report/generate'
4
-
5
- module Thinreports
6
- class Generate
7
- def call(report_params, filename: nil)
8
- SectionReport::Generate.new.call(report_params, filename: filename)
9
- end
10
- end
11
- end
@@ -1,106 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Generator
5
- class PDF
6
- module DrawShape
7
- # @param [Thinreports::Core::Shape::TextBlock::Internal] shape
8
- # @param [Numeric] height (nil) It will be used as rendering height if present.
9
- # Otherwise, the rendering height is the height of schema.
10
- # @param [:truncate, :shrink_to_fit, :expand] overflow (nil) It will be set the overflow attribute if present.
11
- def draw_shape_tblock(shape, height: nil, overflow: nil, &block)
12
- x, y, w = shape.format.attributes.values_at('x', 'y', 'width')
13
-
14
- h = height || shape.format.attributes['height']
15
-
16
- content = shape.real_value.to_s
17
- return if content.empty?
18
-
19
- attrs = build_text_attributes(shape.style.finalized_styles)
20
- attrs[:overflow] = overflow if overflow
21
-
22
- unless shape.multiple?
23
- content = content.tr("\n", ' ')
24
- attrs[:single] = true
25
- end
26
-
27
- text_box(content, x, y, w, h, attrs, &block)
28
- end
29
-
30
- def draw_shape_pageno(shape, page_no, page_count)
31
- x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
32
-
33
- attrs = build_text_attributes(shape.style.finalized_styles)
34
- text_box(shape.build_format(page_no, page_count), x, y, w, h, attrs)
35
- end
36
-
37
- # @param [Thinreports::Core::Shape::Basic::Internal] shape
38
- def draw_shape_image(shape)
39
- x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
40
-
41
- image_data = shape.format.attributes['data']
42
- base64image(image_data['base64'], x, y, w, h)
43
- end
44
-
45
- # @param [Thinreports::Core::Shape::ImageBlock::Internal] shape
46
- def draw_shape_iblock(shape)
47
- return if blank_value?(shape.src)
48
-
49
- x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
50
- style = shape.style.finalized_styles
51
-
52
- image_box(
53
- shape.src, x, y, w, h,
54
- position_x: image_position_x(style['position-x']),
55
- position_y: image_position_y(style['position-y']),
56
- offset_x: style['offset-x'],
57
- offset_y: style['offset-y']
58
- )
59
- end
60
-
61
- def shape_iblock_dimenions(shape)
62
- return nil if blank_value?(shape.src)
63
-
64
- x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
65
- style = shape.style.finalized_styles
66
-
67
- image_dimensions(
68
- shape.src, x, y, w, h,
69
- position_x: image_position_x(style['position-x']),
70
- position_y: image_position_y(style['position-y'])
71
- )
72
- end
73
-
74
- # @param [Thinreports::Core::Shape::Text::Internal] shape
75
- def draw_shape_text(shape, dheight = 0)
76
- x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
77
- text(
78
- shape.texts.join("\n"), x, y, w, h + dheight,
79
- build_text_attributes(shape.style.finalized_styles)
80
- )
81
- end
82
-
83
- # @param [Thinreports::Core::Shape::Basic::Internal] shape
84
- def draw_shape_ellipse(shape)
85
- cx, cy, rx, ry = shape.format.attributes.values_at('cx', 'cy', 'rx', 'ry')
86
- ellipse(cx, cy, rx, ry, build_graphic_attributes(shape.style.finalized_styles))
87
- end
88
-
89
- # @param [Thinreports::Core::Shape::Basic::Internal] shape
90
- def draw_shape_line(shape, dy1 = 0, dy2 = 0)
91
- x1, y1, x2, y2 = shape.format.attributes.values_at('x1', 'y1', 'x2', 'y2')
92
- line(x1, y1 + dy1, x2, y2 + dy2, build_graphic_attributes(shape.style.finalized_styles))
93
- end
94
-
95
- # @param [Thinreports::Core::Shape::Basic::Internal] shape
96
- def draw_shape_rect(shape, dheight = 0)
97
- x, y, w, h = shape.format.attributes.values_at('x', 'y', 'width', 'height')
98
- rect_attributes = build_graphic_attributes(shape.style.finalized_styles) do |attrs|
99
- attrs[:radius] = shape.format.attributes['border-radius']
100
- end
101
- rect(x, y, w, h + dheight, rect_attributes)
102
- end
103
- end
104
- end
105
- end
106
- end
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Generator
5
- class PDF
6
- module DrawTemplateItems
7
- # @param [Array<Hash>] items
8
- def draw_template_items(items)
9
- items.each do |item_attributes|
10
- next unless drawable?(item_attributes)
11
-
12
- case item_attributes['type']
13
- when 'text' then draw_text(item_attributes)
14
- when 'image' then draw_image(item_attributes)
15
- when 'rect' then draw_rect(item_attributes)
16
- when 'ellipse' then draw_ellipse(item_attributes)
17
- when 'line' then draw_line(item_attributes)
18
- end
19
- end
20
- end
21
-
22
- private
23
-
24
- # @param [Hash] item_attributes
25
- def draw_rect(item_attributes)
26
- x, y, w, h = item_attributes.values_at('x', 'y', 'width', 'height')
27
- graphic_attributes = build_graphic_attributes(item_attributes['style']) do |attrs|
28
- attrs[:radius] = item_attributes['border-radius']
29
- end
30
-
31
- rect(x, y, w, h, graphic_attributes)
32
- end
33
-
34
- # @see #draw_rect
35
- def draw_ellipse(item_attributes)
36
- x, y, rx, ry = item_attributes.values_at('cx', 'cy', 'rx', 'ry')
37
- ellipse(x, y, rx, ry, build_graphic_attributes(item_attributes['style']))
38
- end
39
-
40
- # @see #draw_rect
41
- def draw_line(item_attributes)
42
- x1, y1, x2, y2 = item_attributes.values_at('x1', 'y1', 'x2', 'y2')
43
- line(x1, y1, x2, y2, build_graphic_attributes(item_attributes['style']))
44
- end
45
-
46
- # @see #draw_rect
47
- def draw_text(item_attributes)
48
- x, y, w, h = item_attributes.values_at('x', 'y', 'width', 'height')
49
- text(
50
- item_attributes['texts'].join("\n"), x, y, w, h,
51
- build_text_attributes(item_attributes['style'])
52
- )
53
- end
54
-
55
- # @see #draw_rect
56
- def draw_image(item_attributes)
57
- x, y, w, h = item_attributes.values_at('x', 'y', 'width', 'height')
58
- image_data = item_attributes['data']
59
-
60
- base64image(image_data['base64'], x, y, w, h)
61
- end
62
-
63
- def drawable?(item_attributes)
64
- item_attributes['id'].empty? && item_attributes['display']
65
- end
66
- end
67
- end
68
- end
69
- end