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,112 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Core
5
- module Shape
6
- module Manager
7
- module Target
8
- include Utils
9
-
10
- attr_reader :manager
11
-
12
- # @example
13
- # item(:title).value('Title').style(:fill, 'red')
14
- #
15
- # item(:title) do
16
- # value('Title')
17
- # style(:fill, 'red')
18
- # end
19
- #
20
- # item(:title) do |t|
21
- # t.value('Title')
22
- # t.style(:fill, 'red')
23
- # end
24
- # item(:list) # => Error: UnknownItemId
25
- # item(:unknown_id) # => Error: UnknownItemId
26
- # @param [String, Symbol] id
27
- # @yield [item,]
28
- # @yieldparam [Thinreports::Core::Shape::Base::Interface] item
29
- # @raise [Thinreports::Errors::UnknownItemId]
30
- # @return [Thinreports::Core::Shape::Base::Interface]
31
- def item(id, &block)
32
- shape = find_item(id, except: Core::Shape::List::TYPE_NAME)
33
-
34
- raise Thinreports::Errors::UnknownItemId, id unless shape
35
-
36
- call_block_in(shape, &block)
37
- end
38
-
39
- # @example
40
- # page[:text_block].style(:bold, true)
41
- # page[:rect].style(:border_color, 'red')
42
- #
43
- # page[:list] # => Error: UnknownItemId
44
- # page[:unknown_id] # => Error: UnknownItemId
45
- # @param [String, Symbol] id
46
- # @return [Thinreports::Core::Shape::Base::Interface]
47
- def [](id)
48
- item(id)
49
- end
50
-
51
- # @example
52
- # page[:text_block] = 'Title'
53
- # page[:image_block] = '/path/to/image.png'
54
- # page[:list] = 'value' # => Error: UnknownItemId
55
- # page[:ellipse] = 'value' # => Error: NoMethodError #value
56
- # page[:unknown_id] = 'value' # => Error: UnknownItemId
57
- # @param [String, Symbol] id
58
- # @param [Object] value
59
- def []=(id, value)
60
- item(id).value = value
61
- end
62
-
63
- # @example
64
- # page.values text_block: 'value',
65
- # image_block: '/path/to/image.png'
66
- # @param [Hash] item_values
67
- def values(item_values)
68
- item_values.each { |id, val| item(id).value(val) }
69
- end
70
-
71
- # @param [Symbol, String] id
72
- # @return [Boolean]
73
- def item_exists?(id)
74
- !manager.find_format(id).nil?
75
- end
76
- alias exists? item_exists?
77
-
78
- # @example
79
- # report.list.add_row do |row|
80
- # row.item(:price).value(1000)
81
- # end
82
- #
83
- # report.list(:list_id) # => List
84
- # report.list(:text_block_id) # => raises UnknownItemId
85
- # @see #item
86
- def list(id = nil, &block)
87
- shape = find_item(id ||= :default, only: Core::Shape::List::TYPE_NAME)
88
-
89
- raise Thinreports::Errors::UnknownItemId.new(id, 'List') unless shape
90
-
91
- manager.lists[id.to_sym] ||= shape
92
- call_block_in(shape, &block)
93
- end
94
-
95
- private
96
-
97
- # @param format (see Thinreports::Core::Shape::Manager::Internal#initialize)
98
- # @yield [format] Handler for initialize item.
99
- # @yieldparam [Thinreports::Core::Shape::Basic::Format] format
100
- def initialize_manager(format, &block)
101
- @manager = Manager::Internal.new(format, block)
102
- end
103
-
104
- # @see Thinreports::Core::Shape::Manager::Internal#find_item
105
- def find_item(id, limit = {})
106
- manager.find_item(id, limit)
107
- end
108
- end
109
- end
110
- end
111
- end
112
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Core
5
- module Shape
6
- module PageNumber
7
- class Format < Basic::Format
8
- config_reader :target
9
- config_reader default_format: %w[format]
10
-
11
- # For saving compatible 0.8.x format API
12
- config_reader overflow: %w[style overflow]
13
-
14
- def id
15
- @id ||= blank_value?(read('id')) ? self.class.next_default_id : read('id')
16
- end
17
-
18
- def for_report?
19
- blank_value?(target)
20
- end
21
-
22
- def self.next_default_id
23
- @id_counter ||= 0
24
- "__pageno#{@id_counter += 1}"
25
- end
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Core
5
- module Shape
6
- module PageNumber
7
- class Interface < Basic::Interface
8
- internal_delegators :reset_format
9
-
10
- def format(*args)
11
- if args.empty?
12
- internal.read_format
13
- else
14
- internal.write_format(args.first)
15
- self
16
- end
17
- end
18
-
19
- private
20
-
21
- # @see Thinreports::Core::Shape::Base::Interface#init_internal
22
- def init_internal(parent, format)
23
- PageNumber::Internal.new(parent, format)
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Core
5
- module Shape
6
- module PageNumber
7
- class Internal < Basic::Internal
8
- format_delegators :box, :for_report?
9
-
10
- def read_format
11
- states.key?(:format) ? states[:format] : format.default_format.dup
12
- end
13
-
14
- def reset_format
15
- states.delete(:format)
16
- end
17
-
18
- def write_format(format)
19
- states[:format] = format.to_s
20
- end
21
-
22
- def build_format(page_no, page_count)
23
- return '' if blank_value?(read_format)
24
-
25
- if start_page_number > 1
26
- page_no += start_page_number - 1
27
- page_count += start_page_number - 1
28
- end
29
-
30
- read_format.dup.tap do |f|
31
- f.gsub! '{page}', page_no.to_s
32
- f.gsub! '{total}', page_count.to_s
33
- end
34
- end
35
-
36
- def style
37
- @style ||= PageNumber::Style.new(format)
38
- end
39
-
40
- def type_of?(type_name)
41
- type_name == PageNumber::TYPE_NAME
42
- end
43
-
44
- def start_page_number
45
- for_report? ? parent.report.start_page_number : 1
46
- end
47
- end
48
-
49
- class Style < Style::Text
50
- accessible_styles.delete :valign
51
- end
52
- end
53
- end
54
- end
55
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Core
5
- module Shape
6
- module StackView
7
- class Format < Basic::Format
8
- attr_reader :rows
9
-
10
- def initialize(*)
11
- super
12
- initialize_rows
13
- end
14
-
15
- private
16
-
17
- def initialize_rows
18
- @rows = []
19
- attributes['rows'].each do |row|
20
- @rows << StackView::RowFormat.new(row)
21
- end
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Core
5
- module Shape
6
- module StackView
7
- class Interface < Basic::Interface
8
- private
9
-
10
- def init_internal(parent, format)
11
- StackView::Internal.new(parent, format)
12
- end
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Core
5
- module Shape
6
- module StackView
7
- class Internal < Basic::Internal
8
- def initialize(parent, format)
9
- super
10
- @rows = []
11
- end
12
-
13
- attr_accessor :rows
14
-
15
- def type_of?(type_name)
16
- type_name == StackView::TYPE_NAME
17
- end
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Core
5
- module Shape
6
- module StackView
7
- class RowFormat < Core::Format::Base
8
- config_reader :id
9
- config_reader :height
10
- config_checker true, :display
11
- config_checker true, auto_stretch: 'auto-stretch'
12
-
13
- attr_reader :items
14
-
15
- def initialize(*)
16
- super
17
- @items = []
18
- @item_with_ids = {}
19
- initialize_items(attributes['items'])
20
- end
21
-
22
- def find_item(id)
23
- @item_with_ids[id.to_sym]
24
- end
25
-
26
- private
27
-
28
- def initialize_items(item_schemas)
29
- item_schemas.each do |item_schema|
30
- item = Core::Shape::Format(item_schema['type']).new(item_schema)
31
- @items << item
32
- @item_with_ids[item.id.to_sym] = item unless item.id.empty?
33
- end
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end
@@ -1,146 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Core
5
- module Shape
6
- module Style
7
- class Base
8
- include Utils
9
-
10
- class << self
11
- # @param [Symbol] style_method
12
- # @param [String] style
13
- # @return [void]
14
- def style_accessor(style_method, style)
15
- style_reader(style_method, style)
16
- style_writer(style_method, style)
17
- end
18
-
19
- # @see .style_accessor
20
- def style_reader(style_method, style)
21
- define_method(style_method) do
22
- read_internal_style(style)
23
- end
24
- end
25
-
26
- # @see .style_accessor
27
- def style_writer(style_method, style)
28
- define_method(:"#{style_method}=") do |value|
29
- write_internal_style(style, value)
30
- end
31
- end
32
-
33
- # @param [Array<Symbol>] style_methods
34
- def style_accessible(*style_methods)
35
- accessible_styles.concat(style_methods)
36
- end
37
-
38
- # @return [Array<Symbol>]
39
- def accessible_styles
40
- @accessible_styles ||= []
41
- end
42
-
43
- def inherited(s)
44
- s.accessible_styles.concat(accessible_styles.dup)
45
- end
46
- end
47
-
48
- # @return [Hash]
49
- attr_accessor :styles
50
- # @see .accessible_styles
51
- attr_reader :accessible_styles
52
-
53
- # @param [Thinreports::Core::Format::Base] format
54
- # @param [Hash] default_styles ({})
55
- def initialize(format, default_styles = {})
56
- @format = format
57
- @styles = default_styles
58
- @base_styles = format.style || {}
59
-
60
- @accessible_styles = self.class.accessible_styles.dup
61
- end
62
-
63
- # @param [Symbol] style_method
64
- # @return [Object]
65
- def [](style_method)
66
- verify_style_method(style_method)
67
- send(style_method.to_sym)
68
- end
69
-
70
- # @param [Symbol] style_method
71
- # @param [String, Number, Array<String, Number>] value
72
- def []=(style_method, value)
73
- verify_style_method(style_method)
74
- send(:"#{style_method}=", value)
75
- end
76
-
77
- # @return [String]
78
- def identifier
79
- create_identifier(@styles)
80
- end
81
-
82
- # @return [self]
83
- def copy
84
- self.class.new(@format, @styles.empty? ? {} : deep_copy(@styles))
85
- end
86
-
87
- # @param [String, Symbol] style
88
- # @return [Object]
89
- def read_internal_style(style)
90
- style = style.to_s
91
- @styles.key?(style) ? @styles[style] : @base_styles[style]
92
- end
93
-
94
- # @param [String, Symbol] style
95
- # @param [Object] value
96
- def write_internal_style(style, value)
97
- @styles[style.to_s] = value
98
- end
99
-
100
- # @param [Symbol] style_method
101
- # @return [Boolean]
102
- def has_style?(style_method)
103
- accessible_styles.include?(style_method)
104
- end
105
-
106
- # @return [Hash]
107
- def finalized_styles
108
- @finalized_styles ||=
109
- if @styles.empty?
110
- @base_styles.dup
111
- else
112
- @base_styles.merge(@styles)
113
- end
114
- end
115
-
116
- private
117
-
118
- # @param [Hash] s
119
- # @return [String]
120
- def create_identifier(s)
121
- s.empty? ? '' : s.hash.to_s
122
- end
123
-
124
- # @param [Symbol] style_method
125
- # @raise Thinreports::Errors::UnknownShapeStyleName
126
- def verify_style_method(style_method)
127
- return if has_style?(style_method)
128
-
129
- raise Thinreports::Errors::UnknownShapeStyleName.new(
130
- style_method,
131
- accessible_styles
132
- )
133
- end
134
-
135
- # @param [Object] value
136
- # @param [Array<Object>] allows
137
- # @param [String] msg (nil)
138
- # @raise ArgumentError
139
- def verify_style_value(value, allows, msg = nil)
140
- raise ArgumentError, msg unless allows.include?(value)
141
- end
142
- end
143
- end
144
- end
145
- end
146
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Core
5
- module Shape
6
- module Style
7
- class Basic < Style::Base
8
- style_accessible :visible, :offset_x, :offset_y
9
- attr_accessor :visible
10
-
11
- style_accessor :offset_x, 'offset-x'
12
- style_accessor :offset_y, 'offset-y'
13
-
14
- def initialize(*args)
15
- super
16
- @visible = @format.display?
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 Style
7
- class Graphic < Style::Basic
8
- style_accessible :border_color, :border_width, :fill_color, :border
9
-
10
- # @method border_color
11
- # @return [String]
12
- # @method border_color=(color)
13
- # @param [String] color
14
- style_accessor :border_color, 'border-color'
15
-
16
- # @method border_width
17
- # @return [Number]
18
- style_accessor :border_width, 'border-width'
19
-
20
- # @method fill_color
21
- # @return [String]
22
- # @method fill_color=(color)
23
- # @param [String] color
24
- style_accessor :fill_color, 'fill-color'
25
-
26
- # @return [Array<String, Number>]
27
- def border
28
- [border_width, border_color]
29
- end
30
-
31
- # @param [Array<String, Number>] width_and_color
32
- def border=(width_and_color)
33
- w, c = width_and_color
34
- self.border_width = w
35
- self.border_color = c
36
- end
37
- end
38
- end
39
- end
40
- end
41
- end
@@ -1,120 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Core
5
- module Shape
6
- module Style
7
- class Text < Style::Basic
8
- style_accessible :bold, :italic, :underline, :linethrough,
9
- :align, :valign, :color, :font_size
10
-
11
- # @method color
12
- # @return [String]
13
- # @method color=(v)
14
- # @param [String] v
15
- style_accessor :color, 'color'
16
-
17
- # @method font_size
18
- # @return [Numeric, String]
19
- # @method font_size=(v)
20
- # @param [Numeric, String] v
21
- style_accessor :font_size, 'font-size'
22
-
23
- def initialize(*)
24
- super
25
- initialize_font_style
26
- end
27
-
28
- # @return [Boolean]
29
- def bold
30
- read_internal_style('font-style').include?('bold')
31
- end
32
-
33
- # @param [Boolean] enable
34
- def bold=(enable)
35
- write_font_style('bold', enable)
36
- end
37
-
38
- # @return [Boolean]
39
- def italic
40
- read_internal_style('font-style').include?('italic')
41
- end
42
-
43
- # @param [Boolean] enable
44
- def italic=(enable)
45
- write_font_style('italic', enable)
46
- end
47
-
48
- # @return [Boolean]
49
- def underline
50
- read_internal_style('font-style').include?('underline')
51
- end
52
-
53
- # @param [Boolean] enable
54
- def underline=(enable)
55
- write_font_style('underline', enable)
56
- end
57
-
58
- # @return [Boolean]
59
- def linethrough
60
- read_internal_style('font-style').include?('linethrough')
61
- end
62
-
63
- # @param [Boolean] enable
64
- def linethrough=(enable)
65
- write_font_style('linethrough', enable)
66
- end
67
-
68
- # @return [:left, :center, :right]
69
- def align
70
- read_internal_style('text-align').to_sym
71
- end
72
-
73
- # @param [:left, :center, :right] align_name
74
- def align=(align_name)
75
- verify_style_value(align_name, %i[left center right],
76
- 'Only :left or :center, :right can be specified as align.')
77
- write_internal_style('text-align', align_name.to_s)
78
- end
79
-
80
- # @return [:top, :middle, :bottom]
81
- def valign
82
- vertical_align = read_internal_style('vertical-align')
83
- blank_value?(vertical_align) ? :top : vertical_align.to_sym
84
- end
85
-
86
- # @param [:top, :center, :middle, :bottom] valign_name
87
- def valign=(valign_name)
88
- if valign_name == :center
89
- warn '[DEPRECATION] :center value for valign style is deprecated' \
90
- ' and will be removed in thinreports-generator 1.0.' \
91
- ' Please use :middle instead of :center.'
92
- valign_name = :middle
93
- end
94
-
95
- verify_style_value(
96
- valign_name,
97
- %i[top middle bottom],
98
- 'Only :top or :middle (:center), :bottom can be specified as valign.'
99
- )
100
- write_internal_style('vertical-align', valign_name.to_s)
101
- end
102
-
103
- private
104
-
105
- def initialize_font_style
106
- styles['font-style'] ||= (@base_styles['font-style'] || []).dup
107
- end
108
-
109
- def write_font_style(style_name, enable)
110
- if enable
111
- styles['font-style'].push(style_name).uniq!
112
- else
113
- styles['font-style'].delete(style_name)
114
- end
115
- end
116
- end
117
- end
118
- end
119
- end
120
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Core
5
- module Shape
6
- module Text
7
- class Format < Basic::Format
8
- config_reader :texts
9
- config_reader valign: %w[style vertical-align]
10
- config_reader line_height: %w[style line-height]
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Thinreports
4
- module Core
5
- module Shape
6
- module Text
7
- class Interface < Basic::Interface
8
- private
9
-
10
- # @see Thinreports::Core::Shape::Base::Interface#init_internal
11
- def init_internal(parent, format)
12
- Text::Internal.new(parent, format)
13
- end
14
- end
15
- end
16
- end
17
- end
18
- end