thinreports 0.9.1 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yml +39 -0
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +59 -2
  5. data/Dockerfile +12 -0
  6. data/Gemfile +7 -4
  7. data/README.md +44 -22
  8. data/Rakefile +14 -31
  9. data/lib/thinreports.rb +16 -15
  10. data/lib/thinreports/config.rb +2 -24
  11. data/lib/thinreports/core/errors.rb +6 -17
  12. data/lib/thinreports/core/format/base.rb +62 -61
  13. data/lib/thinreports/core/shape.rb +10 -12
  14. data/lib/thinreports/core/shape/base.rb +3 -12
  15. data/lib/thinreports/core/shape/base/interface.rb +34 -32
  16. data/lib/thinreports/core/shape/base/internal.rb +45 -43
  17. data/lib/thinreports/core/shape/basic.rb +12 -12
  18. data/lib/thinreports/core/shape/basic/block_format.rb +8 -6
  19. data/lib/thinreports/core/shape/basic/block_interface.rb +24 -22
  20. data/lib/thinreports/core/shape/basic/block_internal.rb +28 -26
  21. data/lib/thinreports/core/shape/basic/format.rb +11 -9
  22. data/lib/thinreports/core/shape/basic/interface.rb +79 -77
  23. data/lib/thinreports/core/shape/basic/internal.rb +17 -14
  24. data/lib/thinreports/core/shape/image_block.rb +9 -9
  25. data/lib/thinreports/core/shape/image_block/format.rb +7 -5
  26. data/lib/thinreports/core/shape/image_block/interface.rb +15 -13
  27. data/lib/thinreports/core/shape/image_block/internal.rb +10 -8
  28. data/lib/thinreports/core/shape/list.rb +13 -13
  29. data/lib/thinreports/core/shape/list/format.rb +83 -77
  30. data/lib/thinreports/core/shape/list/manager.rb +179 -176
  31. data/lib/thinreports/core/shape/list/page.rb +91 -93
  32. data/lib/thinreports/core/shape/list/page_state.rb +42 -40
  33. data/lib/thinreports/core/shape/list/section_format.rb +28 -26
  34. data/lib/thinreports/core/shape/list/section_interface.rb +42 -40
  35. data/lib/thinreports/core/shape/list/section_internal.rb +21 -19
  36. data/lib/thinreports/core/shape/manager.rb +4 -13
  37. data/lib/thinreports/core/shape/manager/format.rb +21 -19
  38. data/lib/thinreports/core/shape/manager/internal.rb +87 -84
  39. data/lib/thinreports/core/shape/manager/target.rb +93 -95
  40. data/lib/thinreports/core/shape/page_number.rb +9 -9
  41. data/lib/thinreports/core/shape/page_number/format.rb +20 -18
  42. data/lib/thinreports/core/shape/page_number/interface.rb +20 -18
  43. data/lib/thinreports/core/shape/page_number/internal.rb +46 -44
  44. data/lib/thinreports/core/shape/style.rb +5 -14
  45. data/lib/thinreports/core/shape/style/base.rb +121 -120
  46. data/lib/thinreports/core/shape/style/basic.rb +12 -10
  47. data/lib/thinreports/core/shape/style/graphic.rb +35 -33
  48. data/lib/thinreports/core/shape/style/text.rb +113 -107
  49. data/lib/thinreports/core/shape/text.rb +9 -9
  50. data/lib/thinreports/core/shape/text/format.rb +10 -9
  51. data/lib/thinreports/core/shape/text/interface.rb +13 -11
  52. data/lib/thinreports/core/shape/text/internal.rb +14 -12
  53. data/lib/thinreports/core/shape/text_block.rb +10 -10
  54. data/lib/thinreports/core/shape/text_block/format.rb +35 -33
  55. data/lib/thinreports/core/shape/text_block/formatter.rb +26 -24
  56. data/lib/thinreports/core/shape/text_block/formatter/basic.rb +25 -25
  57. data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +15 -12
  58. data/lib/thinreports/core/shape/text_block/formatter/number.rb +52 -34
  59. data/lib/thinreports/core/shape/text_block/formatter/padding.rb +17 -14
  60. data/lib/thinreports/core/shape/text_block/interface.rb +25 -23
  61. data/lib/thinreports/core/shape/text_block/internal.rb +66 -68
  62. data/lib/thinreports/core/utils.rb +7 -3
  63. data/lib/thinreports/generator/pdf.rb +24 -25
  64. data/lib/thinreports/generator/pdf/document.rb +109 -110
  65. data/lib/thinreports/generator/pdf/document/draw_shape.rb +57 -51
  66. data/lib/thinreports/generator/pdf/document/draw_template_items.rb +50 -47
  67. data/lib/thinreports/generator/pdf/document/font.rb +67 -58
  68. data/lib/thinreports/generator/pdf/document/graphics.rb +32 -33
  69. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +121 -121
  70. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +112 -114
  71. data/lib/thinreports/generator/pdf/document/graphics/image.rb +58 -150
  72. data/lib/thinreports/generator/pdf/document/graphics/text.rb +149 -137
  73. data/lib/thinreports/generator/pdf/document/page.rb +60 -64
  74. data/lib/thinreports/generator/pdf/document/parse_color.rb +37 -37
  75. data/lib/thinreports/generator/pdf/drawer/base.rb +41 -41
  76. data/lib/thinreports/generator/pdf/drawer/list.rb +56 -54
  77. data/lib/thinreports/generator/pdf/drawer/list_section.rb +42 -40
  78. data/lib/thinreports/generator/pdf/drawer/page.rb +101 -96
  79. data/lib/thinreports/generator/pdf/prawn_ext.rb +4 -30
  80. data/lib/thinreports/generator/pdf/prawn_ext/calc_image_dimensions.rb +32 -0
  81. data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +35 -0
  82. data/lib/thinreports/layout.rb +5 -7
  83. data/lib/thinreports/layout/base.rb +5 -9
  84. data/lib/thinreports/layout/format.rb +17 -13
  85. data/lib/thinreports/layout/legacy_schema.rb +17 -13
  86. data/lib/thinreports/layout/version.rb +22 -25
  87. data/lib/thinreports/report.rb +4 -6
  88. data/lib/thinreports/report/base.rb +24 -51
  89. data/lib/thinreports/report/internal.rb +13 -15
  90. data/lib/thinreports/report/page.rb +5 -11
  91. data/lib/thinreports/version.rb +2 -2
  92. data/thinreports.gemspec +10 -19
  93. metadata +13 -288
  94. data/.travis.yml +0 -19
  95. data/examples/character_spacing/character_spacing.rb +0 -8
  96. data/examples/character_spacing/character_spacing.tlf +0 -293
  97. data/examples/dynamic_image/dynamic_image.rb +0 -31
  98. data/examples/dynamic_image/dynamic_image.tlf +0 -661
  99. data/examples/dynamic_image/img200x100.png +0 -0
  100. data/examples/dynamic_image/img50x50.png +0 -0
  101. data/examples/dynamic_style/dynamic_style.rb +0 -150
  102. data/examples/dynamic_style/dynamic_style.tlf +0 -1835
  103. data/examples/dynamic_style/dynamic_style_in_list.tlf +0 -344
  104. data/examples/dynamic_style/image.png +0 -0
  105. data/examples/eudc/eudc.rb +0 -20
  106. data/examples/eudc/eudc.tlf +0 -180
  107. data/examples/eudc/eudc.ttf +0 -0
  108. data/examples/helper.rb +0 -50
  109. data/examples/hidden_shapes/hidden_shapes.rb +0 -9
  110. data/examples/hidden_shapes/hidden_shapes.tlf +0 -449
  111. data/examples/list_events/list_events.rb +0 -32
  112. data/examples/list_events/list_events.tlf +0 -361
  113. data/examples/list_manual_generation/list_manual_generation.rb +0 -22
  114. data/examples/list_manual_generation/list_manual_generation.tlf +0 -132
  115. data/examples/list_page_number/list_page_number.rb +0 -17
  116. data/examples/list_page_number/list_page_number.tlf +0 -254
  117. data/examples/page_number/page_number.rb +0 -33
  118. data/examples/page_number/page_number.tlf +0 -215
  119. data/examples/palleted_png/palleted_png.png +0 -0
  120. data/examples/palleted_png/palleted_png.rb +0 -11
  121. data/examples/palleted_png/palleted_png.tlf +0 -47
  122. data/examples/password_setting/password_setting.rb +0 -10
  123. data/examples/password_setting/password_setting.tlf +0 -45
  124. data/examples/report_callbacks/report_callbacks.rb +0 -14
  125. data/examples/report_callbacks/report_callbacks.tlf +0 -147
  126. data/examples/single_line_tblock/single_line_tblock.rb +0 -13
  127. data/examples/single_line_tblock/single_line_tblock.tlf +0 -170
  128. data/examples/tblock_overflow/tblock_overflow.rb +0 -20
  129. data/examples/tblock_overflow/tblock_overflow.tlf +0 -538
  130. data/examples/tblock_styles/font_size.tlf +0 -383
  131. data/examples/tblock_styles/tblock_styles.rb +0 -43
  132. data/examples/tblock_styles/tblock_styles.tlf +0 -889
  133. data/examples/text_align/text_align.rb +0 -8
  134. data/examples/text_align/text_align.tlf +0 -241
  135. data/examples/typeB_page_size/B4_ISO.tlf +0 -45
  136. data/examples/typeB_page_size/B4_JIS.tlf +0 -45
  137. data/examples/typeB_page_size/typeB_page_size.rb +0 -17
  138. data/examples/word_wrap/word_wrap.rb +0 -26
  139. data/examples/word_wrap/word_wrap.tlf +0 -297
  140. data/lib/thinreports/generator.rb +0 -29
  141. data/lib/thinreports/generator/base.rb +0 -40
  142. data/lib/thinreports/generator/configuration.rb +0 -31
  143. data/lib/thinreports/report/events.rb +0 -32
  144. data/test/data/font.ttf +0 -0
  145. data/test/data/image_normal.jpg +0 -0
  146. data/test/data/image_normal.png +0 -0
  147. data/test/data/image_normal_jpg_noext +0 -0
  148. data/test/data/image_normal_png_noext +0 -0
  149. data/test/data/image_pallete_based.png +0 -0
  150. data/test/data/legacy_layout/all-items.tlf +0 -1
  151. data/test/schema_helper.rb +0 -121
  152. data/test/test_helper.rb +0 -42
  153. data/test/tmp/.gitkeep +0 -0
  154. data/test/unit/core/format/test_base.rb +0 -152
  155. data/test/unit/core/shape/base/test_internal.rb +0 -87
  156. data/test/unit/core/shape/basic/test_block_format.rb +0 -23
  157. data/test/unit/core/shape/basic/test_block_interface.rb +0 -29
  158. data/test/unit/core/shape/basic/test_block_internal.rb +0 -55
  159. data/test/unit/core/shape/basic/test_format.rb +0 -37
  160. data/test/unit/core/shape/basic/test_interface.rb +0 -108
  161. data/test/unit/core/shape/basic/test_internal.rb +0 -55
  162. data/test/unit/core/shape/image_block/test_interface.rb +0 -24
  163. data/test/unit/core/shape/image_block/test_internal.rb +0 -31
  164. data/test/unit/core/shape/list/test_format.rb +0 -111
  165. data/test/unit/core/shape/list/test_manager.rb +0 -67
  166. data/test/unit/core/shape/list/test_page.rb +0 -82
  167. data/test/unit/core/shape/list/test_page_state.rb +0 -31
  168. data/test/unit/core/shape/list/test_section_format.rb +0 -36
  169. data/test/unit/core/shape/list/test_section_interface.rb +0 -75
  170. data/test/unit/core/shape/list/test_section_internal.rb +0 -50
  171. data/test/unit/core/shape/manager/test_format.rb +0 -38
  172. data/test/unit/core/shape/manager/test_internal.rb +0 -132
  173. data/test/unit/core/shape/manager/test_target.rb +0 -140
  174. data/test/unit/core/shape/page_number/test_format.rb +0 -55
  175. data/test/unit/core/shape/page_number/test_interface.rb +0 -33
  176. data/test/unit/core/shape/page_number/test_internal.rb +0 -81
  177. data/test/unit/core/shape/styles/test_base.rb +0 -191
  178. data/test/unit/core/shape/styles/test_basic.rb +0 -24
  179. data/test/unit/core/shape/styles/test_graphic.rb +0 -50
  180. data/test/unit/core/shape/styles/test_text.rb +0 -97
  181. data/test/unit/core/shape/text/test_format.rb +0 -44
  182. data/test/unit/core/shape/text/test_internal.rb +0 -20
  183. data/test/unit/core/shape/text_block/formatter/test_basic.rb +0 -24
  184. data/test/unit/core/shape/text_block/formatter/test_datetime.rb +0 -49
  185. data/test/unit/core/shape/text_block/formatter/test_number.rb +0 -76
  186. data/test/unit/core/shape/text_block/formatter/test_padding.rb +0 -77
  187. data/test/unit/core/shape/text_block/test_format.rb +0 -169
  188. data/test/unit/core/shape/text_block/test_formatter.rb +0 -28
  189. data/test/unit/core/shape/text_block/test_interface.rb +0 -63
  190. data/test/unit/core/shape/text_block/test_internal.rb +0 -128
  191. data/test/unit/core/test_shape.rb +0 -52
  192. data/test/unit/core/test_utils.rb +0 -68
  193. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +0 -135
  194. data/test/unit/generator/pdf/document/graphics/test_basic.rb +0 -45
  195. data/test/unit/generator/pdf/document/graphics/test_image.rb +0 -150
  196. data/test/unit/generator/pdf/document/graphics/test_text.rb +0 -171
  197. data/test/unit/generator/pdf/document/test_font.rb +0 -84
  198. data/test/unit/generator/pdf/document/test_graphics.rb +0 -42
  199. data/test/unit/generator/pdf/document/test_page.rb +0 -122
  200. data/test/unit/generator/pdf/document/test_parse_color.rb +0 -30
  201. data/test/unit/generator/pdf/test_document.rb +0 -20
  202. data/test/unit/generator/test_base.rb +0 -40
  203. data/test/unit/generator/test_configuration.rb +0 -21
  204. data/test/unit/generator/test_pdf.rb +0 -24
  205. data/test/unit/layout/test_base.rb +0 -41
  206. data/test/unit/layout/test_format.rb +0 -100
  207. data/test/unit/layout/test_legacy_schema.rb +0 -574
  208. data/test/unit/layout/test_version.rb +0 -95
  209. data/test/unit/report/test_base.rb +0 -262
  210. data/test/unit/report/test_internal.rb +0 -206
  211. data/test/unit/test_config.rb +0 -51
  212. data/test/unit/test_layout.rb +0 -12
  213. data/test/unit/test_report.rb +0 -18
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'json'
4
4
  require 'rexml/document'
@@ -13,7 +13,7 @@ module Thinreports
13
13
  @legacy_svg = legacy_schema['svg'].dup
14
14
  @legacy_item_schemas = extract_legacy_item_schemas(legacy_svg)
15
15
 
16
- normalize_svg!(@legacy_svg)
16
+ @legacy_svg = cleanup_svg(@legacy_svg)
17
17
  end
18
18
 
19
19
  def upgrade
@@ -28,7 +28,12 @@ module Thinreports
28
28
  'width' => page_config['width'].to_f,
29
29
  'height' => page_config['height'].to_f,
30
30
  'orientation' => page_config['orientation'],
31
- 'margin' => page_config.values_at('margin-top', 'margin-right', 'margin-bottom', 'margin-left').map(&:to_f)
31
+ 'margin' => page_config.values_at(
32
+ 'margin-top',
33
+ 'margin-right',
34
+ 'margin-bottom',
35
+ 'margin-left'
36
+ ).map(&:to_f)
32
37
  },
33
38
  'items' => item_schemas
34
39
  }
@@ -78,7 +83,7 @@ module Thinreports
78
83
  'display' => display(attributes['x-display']),
79
84
  'texts' => texts,
80
85
  'style' => {
81
- 'font-family' => [ attributes['font-family'] ],
86
+ 'font-family' => [attributes['font-family']],
82
87
  'font-size' => attributes['font-size'].to_f,
83
88
  'color' => attributes['fill'],
84
89
  'font-style' => font_style(attributes),
@@ -99,6 +104,7 @@ module Thinreports
99
104
  'width' => attributes['width'].to_f,
100
105
  'height' => attributes['height'].to_f,
101
106
  'display' => display(attributes['x-display']),
107
+ 'border-radius' => attributes['rx'].to_i,
102
108
  'style' => {
103
109
  'border-width' => attributes['stroke-width'].to_f,
104
110
  'border-color' => attributes['stroke'],
@@ -144,7 +150,7 @@ module Thinreports
144
150
  end
145
151
 
146
152
  def image_item_schema(attributes)
147
- _, image_type, image_data = attributes['xlink:href'].match(%r|^data:(image/[a-z]+?);base64,(.+)|).to_a
153
+ _, image_type, image_data = attributes['xlink:href'].match(%r{^data:(image/[a-z]+?);base64,(.+)}).to_a
148
154
 
149
155
  {
150
156
  'id' => attributes['x-id'],
@@ -173,7 +179,7 @@ module Thinreports
173
179
  'target' => attributes['x-target'],
174
180
  'display' => display(attributes['x-display']),
175
181
  'style' => {
176
- 'font-family' => [ attributes['font-family'] ],
182
+ 'font-family' => [attributes['font-family']],
177
183
  'font-size' => attributes['font-size'].to_f,
178
184
  'color' => attributes['fill'],
179
185
  'font-style' => font_style(attributes),
@@ -235,7 +241,7 @@ module Thinreports
235
241
  'format' => text_format,
236
242
  'reference-id' => attributes['x-ref-id'],
237
243
  'style' => {
238
- 'font-family' => [ attributes['font-family'] ],
244
+ 'font-family' => [attributes['font-family']],
239
245
  'font-size' => attributes['font-size'].to_f,
240
246
  'color' => attributes['fill'],
241
247
  'font-style' => font_style(attributes),
@@ -269,9 +275,7 @@ module Thinreports
269
275
  'footer' => footer
270
276
  }
271
277
 
272
- if page_footer['enabled']
273
- page_footer['translate']['y'] += detail['height']
274
- end
278
+ page_footer['translate']['y'] += detail['height'] if page_footer['enabled']
275
279
 
276
280
  if footer['enabled']
277
281
  footer['translate']['y'] += detail['height']
@@ -368,9 +372,9 @@ module Thinreports
368
372
  items
369
373
  end
370
374
 
371
- def normalize_svg!(svg)
372
- svg.gsub!(/<!--SHAPE.*?SHAPE-->/, '')
373
- svg.gsub!(/<!--LAYOUT(.*?)LAYOUT-->/) { $1 }
375
+ def cleanup_svg(svg)
376
+ cleaned_svg = svg.gsub(/<!--SHAPE.*?SHAPE-->/, '')
377
+ cleaned_svg.gsub(/<!--LAYOUT(.*?)LAYOUT-->/) { $1 }
374
378
  end
375
379
  end
376
380
  end
@@ -1,42 +1,39 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Thinreports
4
4
  module Layout
5
+ class Version
6
+ COMPATIBLE_RULES = ['>= 0.8.0', '< 1.0.0'].freeze
7
+ NEW_SCHEMA_FROM = '0.9.0'
5
8
 
6
- module Version
7
- REQUIRED_RULES = ['>= 0.8.0', '< 1.0.0']
9
+ class << self
10
+ def compatible_rules
11
+ COMPATIBLE_RULES
12
+ end
13
+ end
8
14
 
9
- # @param [String] version
10
- # @return [Boolean]
11
- def self.compatible?(version)
12
- compare(version, *REQUIRED_RULES)
15
+ def initialize(schema_version)
16
+ @schema_version = normalize_version(schema_version)
13
17
  end
14
18
 
15
- # @param [String] base
16
- # @param [Array<String>] rules
17
- # @return [Boolean]
18
- def self.compare(base, *rules)
19
- rules.all? do |rule|
19
+ def compatible?
20
+ self.class.compatible_rules.all? do |rule|
20
21
  op, ver = rule.split(' ')
21
- comparable_version(base).send(op.to_sym, comparable_version(ver))
22
+ schema_version.send(op.to_sym, normalize_version(ver))
22
23
  end
23
24
  end
24
25
 
25
- # @return [String]
26
- def self.inspect_required_rules
27
- '(' + REQUIRED_RULES.join(' and ') + ')'
26
+ def legacy?
27
+ @schema_version < normalize_version(NEW_SCHEMA_FROM)
28
28
  end
29
29
 
30
- # @param [String] version
31
- # @return [String]
32
- def self.comparable_version(version)
33
- if version =~ /pre/
34
- version.sub(/pre(\d*)$/) { $1 == '' ? '1' : $1 }
35
- else
36
- "#{version}.99"
37
- end
30
+ private
31
+
32
+ attr_reader :schema_version
33
+
34
+ def normalize_version(version)
35
+ Gem::Version.create(version)
38
36
  end
39
37
  end
40
-
41
38
  end
42
39
  end
@@ -1,7 +1,6 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Thinreports
4
-
5
4
  module Report
6
5
  # @see Thinreports::Report::Base#initialize
7
6
  def self.new(*args)
@@ -18,9 +17,8 @@ module Thinreports
18
17
  Base.generate(*args, &block)
19
18
  end
20
19
  end
21
-
22
20
  end
23
21
 
24
- require 'thinreports/report/base'
25
- require 'thinreports/report/internal'
26
- require 'thinreports/report/page'
22
+ require_relative 'report/base'
23
+ require_relative 'report/internal'
24
+ require_relative 'report/page'
@@ -1,8 +1,7 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Thinreports
4
4
  module Report
5
-
6
5
  class Base
7
6
  extend Forwardable
8
7
  include Utils
@@ -14,9 +13,8 @@ module Thinreports
14
13
  # @yieldparam [Thinreports::Report::Base] report
15
14
  # @return [Thinreports::Report::Base]
16
15
  def create(options = {}, &block)
17
- unless block_given?
18
- raise ArgumentError, '#create requires a block'
19
- end
16
+ raise ArgumentError, '#create requires a block' unless block_given?
17
+
20
18
  report = new(options)
21
19
  call_block_in(report, &block)
22
20
  report.finalize
@@ -24,43 +22,28 @@ module Thinreports
24
22
  report
25
23
  end
26
24
 
27
- # @overload generate(type, options = {}, &block)
28
- # @param [Symbol] type
29
- # @param [Hash] options
30
- # @option options [Hash] :report ({}) Options for Report.
31
- # @option options [Hash] :generator ({}) Options for Generator.
32
- # @overload generate(options = {}, &block)
33
- # @param [Hash] options
34
- # @option options [Hash] :report ({}) Options for Report.
35
- # @option options [Hash] :generator ({}) Options for Generator.
25
+ # @param layout (see #initialize)
26
+ # @param filename (see #generate)
27
+ # @param security (see #generate)
28
+ # @param [Hash] report ({}) DEPRECATED. Options for Report.
29
+ # @param [Hash] generator ({}) DEPRECATED. Options for Generator.
36
30
  # @yield (see .create)
37
31
  # @yieldparam (see .create)
38
32
  # @return [String]
39
- def generate(*args, &block)
33
+ def generate(layout: nil, filename: nil, security: nil, report: {}, generator: {}, &block)
40
34
  raise ArgumentError, '#generate requires a block' unless block_given?
41
35
 
42
- report_opts, generator_opts = extract_options!(args)
36
+ if report.any? || generator.any?
37
+ warn '[DEPRECATION] :report and :generator argument has been deprecated. ' \
38
+ 'Use :layout and :filename, :security argument instead.'
39
+ end
43
40
 
44
- report = create(report_opts, &block)
45
- report.generate(*args.push(generator_opts))
46
- end
41
+ layout ||= report[:layout]
42
+ filename ||= generator[:filename]
43
+ security ||= generator[:security]
47
44
 
48
- # @param [Array] args
49
- # @return [Array<Hash>]
50
- def extract_options!(args)
51
- if args.last.is_a?(::Hash)
52
- options = args.pop
53
-
54
- generator = options.delete(:generator) || {}
55
- report = options.delete(:report) || {}
56
-
57
- if options.key?(:layout)
58
- report[:layout] = options.delete(:layout)
59
- end
60
- [report, generator.merge(options)]
61
- else
62
- [{}, {}]
63
- end
45
+ report = create(layout: layout, &block)
46
+ report.generate(filename: filename, security: security)
64
47
  end
65
48
  end
66
49
 
@@ -150,7 +133,7 @@ module Thinreports
150
133
  def add_blank_page(options = {})
151
134
  internal.add_page(Report::BlankPage.new(options[:count]))
152
135
  end
153
- alias_method :blank_page, :add_blank_page
136
+ alias blank_page add_blank_page
154
137
 
155
138
  # @param [Symbol, nil] id
156
139
  # @return [Thinreports::Layout::Base]
@@ -163,24 +146,15 @@ module Thinreports
163
146
  end
164
147
  end
165
148
 
166
- # @overload generate(options = {})
167
- # @param [Hash] options ({})
168
- # @return [String]
169
- # @overload generate(type, options = {})
170
- # This way has been DEPRECATED. Use instead #generate(options = {}).
171
- # @param [Symbol] type
172
- # @return [String]
149
+ # @param [String] filename
150
+ # @param [Hash] security (see http://prawnpdf.org/api-docs/2.0/Prawn/Document/Security.html#encrypt_document-instance_method)
151
+ # @return [String]
173
152
  # @example Generate PDF data
174
153
  # report.generate # => "%PDF-1.4...."
175
154
  # @example Create a PDF file
176
155
  # report.generate(filename: 'foo.pdf')
177
- def generate(*args)
178
- options = args.last.is_a?(::Hash) ? args.pop : {}
179
- type = args.first || Thinreports.config.generator.default
180
- filename = options.delete(:filename)
181
- generator = Thinreports::Generator.new(type, self, options)
182
-
183
- generator.generate(filename)
156
+ def generate(filename: nil, security: nil)
157
+ Thinreports::Generator::PDF.new(self, security: security).generate(filename)
184
158
  end
185
159
 
186
160
  # @see Thinreports::Core::Shape::Manager::Target#list
@@ -191,6 +165,5 @@ module Thinreports
191
165
 
192
166
  def_delegators :internal, :finalize, :finalized?
193
167
  end
194
-
195
168
  end
196
169
  end
@@ -1,8 +1,7 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Thinreports
4
4
  module Report
5
-
6
5
  class Internal
7
6
  attr_reader :pages
8
7
  attr_reader :page
@@ -19,9 +18,9 @@ module Thinreports
19
18
  @default_layout = options[:layout] ? init_layout(options[:layout]) : nil
20
19
 
21
20
  @layout_registry = {}
22
- @finalized = false
23
- @pages = []
24
- @page = nil
21
+ @finalized = false
22
+ @pages = []
23
+ @page = nil
25
24
  @page_count = 0
26
25
 
27
26
  @page_create_handler = nil
@@ -34,9 +33,7 @@ module Thinreports
34
33
  else
35
34
  id = options[:id].to_sym
36
35
 
37
- if layout_registry.key?(id)
38
- raise ArgumentError, "Id :#{id} is already in use."
39
- end
36
+ raise ArgumentError, "Id :#{id} is already in use." if layout_registry.key?(id)
40
37
  layout_registry[id] = init_layout(layout, id)
41
38
  end
42
39
  end
@@ -52,10 +49,10 @@ module Thinreports
52
49
  end
53
50
 
54
51
  def finalize
55
- unless finalized?
56
- finalize_current_page
57
- @finalized = true
58
- end
52
+ return if finalized?
53
+
54
+ finalize_current_page
55
+ @finalized = true
59
56
  end
60
57
 
61
58
  def finalized?
@@ -75,11 +72,11 @@ module Thinreports
75
72
  raise ArgumentError, 'Invalid argument for layout.'
76
73
  end
77
74
 
78
- @default_layout = layout unless @default_layout
75
+ @default_layout ||= layout
79
76
  layout
80
77
  end
81
78
 
82
- private
79
+ private
83
80
 
84
81
  def insert_page(new_page)
85
82
  @pages << new_page
@@ -99,9 +96,10 @@ module Thinreports
99
96
  end
100
97
 
101
98
  def init_layout(filename, id = nil)
99
+ filename = filename.to_path if filename.is_a?(Pathname)
100
+
102
101
  Thinreports::Layout.new(filename, id: id)
103
102
  end
104
103
  end
105
-
106
104
  end
107
105
  end
@@ -1,8 +1,7 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Thinreports
4
4
  module Report
5
-
6
5
  class BlankPage
7
6
  # @example
8
7
  # 3.times do
@@ -51,8 +50,8 @@ module Thinreports
51
50
  def initialize(report, layout, options = {})
52
51
  super(options.key?(:count) ? options[:count] : true)
53
52
 
54
- @report = report
55
- @layout = layout
53
+ @report = report
54
+ @layout = layout
56
55
  @finalized = false
57
56
 
58
57
  initialize_manager(layout.format) do |f|
@@ -72,9 +71,7 @@ module Thinreports
72
71
  new_shape = shape.copy(new_page)
73
72
  new_page.manager.shapes[id] = new_shape
74
73
 
75
- if new_shape.internal.type_of?(Core::Shape::List::TYPE_NAME)
76
- new_page.manager.lists[id] = new_shape
77
- end
74
+ new_page.manager.lists[id] = new_shape if new_shape.internal.type_of?(Core::Shape::List::TYPE_NAME)
78
75
  end
79
76
  new_page
80
77
  end
@@ -85,9 +82,7 @@ module Thinreports
85
82
  at = options[:at] || :create
86
83
 
87
84
  # For list shapes.
88
- if at == :create
89
- manager.lists.values.each {|list| list.manager.finalize }
90
- end
85
+ manager.lists.each_value { |list| list.manager.finalize } if at == :create
91
86
 
92
87
  @finalized = true
93
88
  end
@@ -96,6 +91,5 @@ module Thinreports
96
91
  @finalized
97
92
  end
98
93
  end
99
-
100
94
  end
101
95
  end
@@ -1,5 +1,5 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Thinreports
4
- VERSION = '0.9.1'
4
+ VERSION = '0.11.0'
5
5
  end
@@ -1,7 +1,8 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- $LOAD_PATH.unshift(File.expand_path('../lib/', __FILE__))
4
- require 'thinreports/version'
3
+ rootdir = File.expand_path(File.dirname(__FILE__))
4
+
5
+ require "#{rootdir}/lib/thinreports/version"
5
6
 
6
7
  Gem::Specification.new do |s|
7
8
  s.name = 'thinreports'
@@ -11,24 +12,14 @@ Gem::Specification.new do |s|
11
12
  s.summary = 'An open source report generation tool for Ruby.'
12
13
  s.description = 'Thinreports is an open source report generation tool for Ruby.'
13
14
  s.homepage = 'http://www.thinreports.org'
14
- s.licenses = ['MIT']
15
-
16
- s.platform = Gem::Platform::RUBY
17
- s.required_ruby_version = '>= 1.9.3'
15
+ s.license = 'MIT'
18
16
 
19
- s.rdoc_options = ['--main', 'README.md']
20
- s.extra_rdoc_files = ['README.md']
17
+ s.required_ruby_version = '>= 2.4.0'
21
18
 
22
- s.files = `git ls-files`.split($\)
23
- s.test_files = s.files.grep %r{^test/}
19
+ s.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^test/}) }
21
+ end
24
22
  s.require_paths = ['lib']
25
23
 
26
- s.add_dependency 'prawn', '1.3.0'
27
- s.add_dependency 'chunky_png', '~> 1.3'
28
-
29
- s.add_development_dependency 'bundler', ['>= 1.0.0']
30
- s.add_development_dependency 'minitest', ['>= 5.0.0']
31
- s.add_development_dependency 'mocha', ['>= 0']
32
- s.add_development_dependency 'rake', ['>= 0']
33
- s.add_development_dependency 'yard'
24
+ s.add_dependency 'prawn', '~> 2.2.0'
34
25
  end