thinreports 0.9.1 → 0.10.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +41 -0
- data/.travis.yml +4 -6
- data/CHANGELOG.md +21 -2
- data/Gemfile +2 -4
- data/README.md +4 -5
- data/Rakefile +7 -8
- data/examples/character_spacing/character_spacing.rb +1 -1
- data/examples/dynamic_image/dynamic_image.rb +3 -3
- data/examples/dynamic_style/dynamic_style.rb +1 -1
- data/examples/eudc/eudc.rb +1 -1
- data/examples/helper.rb +2 -2
- data/examples/hidden_shapes/hidden_shapes.rb +1 -1
- data/examples/list_events/list_events.rb +1 -1
- data/examples/list_manual_generation/list_manual_generation.rb +1 -1
- data/examples/list_page_number/list_page_number.rb +1 -1
- data/examples/page_number/page_number.rb +1 -1
- data/examples/palleted_png/palleted_png.rb +1 -3
- data/examples/password_setting/password_setting.rb +1 -1
- data/examples/report_callbacks/report_callbacks.rb +1 -1
- data/examples/single_line_tblock/single_line_tblock.rb +1 -1
- data/examples/tblock_overflow/tblock_overflow.rb +1 -1
- data/examples/tblock_styles/tblock_styles.rb +1 -1
- data/examples/text_align/text_align.rb +1 -1
- data/examples/typeB_page_size/typeB_page_size.rb +1 -1
- data/examples/word_wrap/word_wrap.rb +1 -1
- data/lib/thinreports.rb +16 -15
- data/lib/thinreports/config.rb +2 -24
- data/lib/thinreports/core/errors.rb +6 -17
- data/lib/thinreports/core/format/base.rb +62 -61
- data/lib/thinreports/core/shape.rb +13 -14
- data/lib/thinreports/core/shape/base.rb +3 -12
- data/lib/thinreports/core/shape/base/interface.rb +35 -32
- data/lib/thinreports/core/shape/base/internal.rb +45 -43
- data/lib/thinreports/core/shape/basic.rb +12 -12
- data/lib/thinreports/core/shape/basic/block_format.rb +8 -6
- data/lib/thinreports/core/shape/basic/block_interface.rb +24 -22
- data/lib/thinreports/core/shape/basic/block_internal.rb +28 -26
- data/lib/thinreports/core/shape/basic/format.rb +11 -9
- data/lib/thinreports/core/shape/basic/interface.rb +79 -77
- data/lib/thinreports/core/shape/basic/internal.rb +17 -14
- data/lib/thinreports/core/shape/image_block.rb +9 -9
- data/lib/thinreports/core/shape/image_block/format.rb +7 -5
- data/lib/thinreports/core/shape/image_block/interface.rb +15 -13
- data/lib/thinreports/core/shape/image_block/internal.rb +10 -8
- data/lib/thinreports/core/shape/list.rb +13 -13
- data/lib/thinreports/core/shape/list/format.rb +83 -77
- data/lib/thinreports/core/shape/list/manager.rb +182 -176
- data/lib/thinreports/core/shape/list/page.rb +94 -93
- data/lib/thinreports/core/shape/list/page_state.rb +42 -40
- data/lib/thinreports/core/shape/list/section_format.rb +28 -26
- data/lib/thinreports/core/shape/list/section_interface.rb +42 -40
- data/lib/thinreports/core/shape/list/section_internal.rb +21 -19
- data/lib/thinreports/core/shape/manager.rb +4 -13
- data/lib/thinreports/core/shape/manager/format.rb +21 -19
- data/lib/thinreports/core/shape/manager/internal.rb +88 -84
- data/lib/thinreports/core/shape/manager/target.rb +93 -95
- data/lib/thinreports/core/shape/page_number.rb +9 -9
- data/lib/thinreports/core/shape/page_number/format.rb +20 -18
- data/lib/thinreports/core/shape/page_number/interface.rb +20 -18
- data/lib/thinreports/core/shape/page_number/internal.rb +47 -44
- data/lib/thinreports/core/shape/style.rb +5 -14
- data/lib/thinreports/core/shape/style/base.rb +121 -120
- data/lib/thinreports/core/shape/style/basic.rb +12 -10
- data/lib/thinreports/core/shape/style/graphic.rb +35 -33
- data/lib/thinreports/core/shape/style/text.rb +113 -107
- data/lib/thinreports/core/shape/text.rb +9 -9
- data/lib/thinreports/core/shape/text/format.rb +10 -9
- data/lib/thinreports/core/shape/text/interface.rb +13 -11
- data/lib/thinreports/core/shape/text/internal.rb +14 -12
- data/lib/thinreports/core/shape/text_block.rb +10 -10
- data/lib/thinreports/core/shape/text_block/format.rb +35 -33
- data/lib/thinreports/core/shape/text_block/formatter.rb +26 -24
- data/lib/thinreports/core/shape/text_block/formatter/basic.rb +25 -25
- data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +15 -12
- data/lib/thinreports/core/shape/text_block/formatter/number.rb +45 -39
- data/lib/thinreports/core/shape/text_block/formatter/padding.rb +17 -14
- data/lib/thinreports/core/shape/text_block/interface.rb +25 -23
- data/lib/thinreports/core/shape/text_block/internal.rb +68 -68
- data/lib/thinreports/core/utils.rb +4 -3
- data/lib/thinreports/generator/pdf.rb +24 -25
- data/lib/thinreports/generator/pdf/document.rb +109 -110
- data/lib/thinreports/generator/pdf/document/draw_shape.rb +58 -51
- data/lib/thinreports/generator/pdf/document/draw_template_items.rb +51 -47
- data/lib/thinreports/generator/pdf/document/font.rb +62 -59
- data/lib/thinreports/generator/pdf/document/graphics.rb +32 -33
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +122 -121
- data/lib/thinreports/generator/pdf/document/graphics/basic.rb +113 -114
- data/lib/thinreports/generator/pdf/document/graphics/image.rb +58 -150
- data/lib/thinreports/generator/pdf/document/graphics/text.rb +152 -137
- data/lib/thinreports/generator/pdf/document/page.rb +63 -64
- data/lib/thinreports/generator/pdf/document/parse_color.rb +37 -37
- data/lib/thinreports/generator/pdf/drawer/base.rb +41 -41
- data/lib/thinreports/generator/pdf/drawer/list.rb +48 -45
- data/lib/thinreports/generator/pdf/drawer/list_section.rb +42 -40
- data/lib/thinreports/generator/pdf/drawer/page.rb +101 -96
- data/lib/thinreports/generator/pdf/prawn_ext.rb +4 -30
- data/lib/thinreports/generator/pdf/prawn_ext/calc_image_dimensions.rb +34 -0
- data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +29 -0
- data/lib/thinreports/layout.rb +5 -7
- data/lib/thinreports/layout/base.rb +5 -7
- data/lib/thinreports/layout/format.rb +18 -13
- data/lib/thinreports/layout/legacy_schema.rb +18 -10
- data/lib/thinreports/layout/version.rb +22 -25
- data/lib/thinreports/report.rb +4 -6
- data/lib/thinreports/report/base.rb +24 -51
- data/lib/thinreports/report/internal.rb +9 -11
- data/lib/thinreports/report/page.rb +5 -6
- data/lib/thinreports/version.rb +2 -2
- data/test/schema_helper.rb +4 -3
- data/test/test_helper.rb +9 -3
- data/test/unit/core/format/test_base.rb +1 -1
- data/test/unit/core/shape/base/test_internal.rb +1 -1
- data/test/unit/core/shape/basic/test_block_format.rb +1 -1
- data/test/unit/core/shape/basic/test_block_interface.rb +1 -1
- data/test/unit/core/shape/basic/test_block_internal.rb +1 -1
- data/test/unit/core/shape/basic/test_format.rb +1 -1
- data/test/unit/core/shape/basic/test_interface.rb +1 -1
- data/test/unit/core/shape/basic/test_internal.rb +1 -1
- data/test/unit/core/shape/image_block/test_interface.rb +1 -1
- data/test/unit/core/shape/image_block/test_internal.rb +1 -1
- data/test/unit/core/shape/list/test_format.rb +1 -1
- data/test/unit/core/shape/list/test_manager.rb +4 -4
- data/test/unit/core/shape/list/test_page.rb +1 -1
- data/test/unit/core/shape/list/test_page_state.rb +1 -1
- data/test/unit/core/shape/list/test_section_format.rb +1 -1
- data/test/unit/core/shape/list/test_section_interface.rb +2 -2
- data/test/unit/core/shape/list/test_section_internal.rb +1 -1
- data/test/unit/core/shape/manager/test_format.rb +2 -2
- data/test/unit/core/shape/manager/test_internal.rb +3 -3
- data/test/unit/core/shape/manager/test_target.rb +1 -1
- data/test/unit/core/shape/page_number/test_format.rb +1 -1
- data/test/unit/core/shape/page_number/test_interface.rb +1 -1
- data/test/unit/core/shape/page_number/test_internal.rb +1 -1
- data/test/unit/core/shape/styles/test_base.rb +1 -1
- data/test/unit/core/shape/styles/test_basic.rb +1 -1
- data/test/unit/core/shape/styles/test_graphic.rb +1 -1
- data/test/unit/core/shape/styles/test_text.rb +1 -1
- data/test/unit/core/shape/text/test_format.rb +1 -1
- data/test/unit/core/shape/text/test_internal.rb +1 -1
- data/test/unit/core/shape/text_block/formatter/test_basic.rb +1 -1
- data/test/unit/core/shape/text_block/formatter/test_datetime.rb +1 -1
- data/test/unit/core/shape/text_block/formatter/test_number.rb +1 -1
- data/test/unit/core/shape/text_block/formatter/test_padding.rb +2 -2
- data/test/unit/core/shape/text_block/test_format.rb +1 -1
- data/test/unit/core/shape/text_block/test_formatter.rb +1 -1
- data/test/unit/core/shape/text_block/test_interface.rb +1 -1
- data/test/unit/core/shape/text_block/test_internal.rb +3 -3
- data/test/unit/core/test_shape.rb +1 -1
- data/test/unit/core/test_utils.rb +2 -2
- data/test/unit/generator/pdf/document/graphics/test_attributes.rb +1 -1
- data/test/unit/generator/pdf/document/graphics/test_basic.rb +2 -1
- data/test/unit/generator/pdf/document/graphics/test_image.rb +27 -131
- data/test/unit/generator/pdf/document/graphics/test_text.rb +1 -1
- data/test/unit/generator/pdf/document/test_font.rb +2 -2
- data/test/unit/generator/pdf/document/test_graphics.rb +1 -1
- data/test/unit/generator/pdf/document/test_page.rb +7 -7
- data/test/unit/generator/pdf/document/test_parse_color.rb +1 -1
- data/test/unit/generator/pdf/prawn_ext/test_calc_image_dimensions.rb +41 -0
- data/test/unit/generator/pdf/prawn_ext/test_width_of.rb +22 -0
- data/test/unit/generator/pdf/test_document.rb +8 -6
- data/test/unit/generator/test_pdf.rb +12 -10
- data/test/unit/layout/test_base.rb +1 -1
- data/test/unit/layout/test_format.rb +2 -2
- data/test/unit/layout/test_legacy_schema.rb +4 -4
- data/test/unit/layout/test_version.rb +11 -80
- data/test/unit/report/test_base.rb +45 -59
- data/test/unit/report/test_internal.rb +1 -1
- data/test/unit/test_config.rb +1 -16
- data/test/unit/test_layout.rb +1 -1
- data/test/unit/test_report.rb +1 -1
- data/thinreports.gemspec +11 -14
- metadata +42 -103
- data/lib/thinreports/generator.rb +0 -29
- data/lib/thinreports/generator/base.rb +0 -40
- data/lib/thinreports/generator/configuration.rb +0 -31
- data/lib/thinreports/report/events.rb +0 -32
- data/test/unit/generator/test_base.rb +0 -40
- data/test/unit/generator/test_configuration.rb +0 -21
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'json'
|
|
4
4
|
require 'rexml/document'
|
|
5
5
|
|
|
6
6
|
module Thinreports
|
|
7
7
|
module Layout
|
|
8
|
+
# rubocop:disable Metrics/ClassLength
|
|
8
9
|
class LegacySchema
|
|
9
10
|
include Utils
|
|
10
11
|
|
|
@@ -13,9 +14,10 @@ module Thinreports
|
|
|
13
14
|
@legacy_svg = legacy_schema['svg'].dup
|
|
14
15
|
@legacy_item_schemas = extract_legacy_item_schemas(legacy_svg)
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
@legacy_svg = cleanup_svg(@legacy_svg)
|
|
17
18
|
end
|
|
18
19
|
|
|
20
|
+
# rubocop:disable Metrics/AbcSize
|
|
19
21
|
def upgrade
|
|
20
22
|
config = legacy_schema['config']
|
|
21
23
|
page_config = config['page']
|
|
@@ -28,7 +30,12 @@ module Thinreports
|
|
|
28
30
|
'width' => page_config['width'].to_f,
|
|
29
31
|
'height' => page_config['height'].to_f,
|
|
30
32
|
'orientation' => page_config['orientation'],
|
|
31
|
-
'margin' => page_config.values_at(
|
|
33
|
+
'margin' => page_config.values_at(
|
|
34
|
+
'margin-top',
|
|
35
|
+
'margin-right',
|
|
36
|
+
'margin-bottom',
|
|
37
|
+
'margin-left'
|
|
38
|
+
).map(&:to_f)
|
|
32
39
|
},
|
|
33
40
|
'items' => item_schemas
|
|
34
41
|
}
|
|
@@ -41,6 +48,7 @@ module Thinreports
|
|
|
41
48
|
build_item_schemas_from_svg(svg.elements['/svg/g'])
|
|
42
49
|
end
|
|
43
50
|
|
|
51
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
|
44
52
|
def build_item_schemas_from_svg(svg_elements)
|
|
45
53
|
return [] unless svg_elements
|
|
46
54
|
|
|
@@ -78,7 +86,7 @@ module Thinreports
|
|
|
78
86
|
'display' => display(attributes['x-display']),
|
|
79
87
|
'texts' => texts,
|
|
80
88
|
'style' => {
|
|
81
|
-
'font-family' => [
|
|
89
|
+
'font-family' => [attributes['font-family']],
|
|
82
90
|
'font-size' => attributes['font-size'].to_f,
|
|
83
91
|
'color' => attributes['fill'],
|
|
84
92
|
'font-style' => font_style(attributes),
|
|
@@ -144,7 +152,7 @@ module Thinreports
|
|
|
144
152
|
end
|
|
145
153
|
|
|
146
154
|
def image_item_schema(attributes)
|
|
147
|
-
_, image_type, image_data = attributes['xlink:href'].match(%r
|
|
155
|
+
_, image_type, image_data = attributes['xlink:href'].match(%r{^data:(image/[a-z]+?);base64,(.+)}).to_a
|
|
148
156
|
|
|
149
157
|
{
|
|
150
158
|
'id' => attributes['x-id'],
|
|
@@ -173,7 +181,7 @@ module Thinreports
|
|
|
173
181
|
'target' => attributes['x-target'],
|
|
174
182
|
'display' => display(attributes['x-display']),
|
|
175
183
|
'style' => {
|
|
176
|
-
'font-family' => [
|
|
184
|
+
'font-family' => [attributes['font-family']],
|
|
177
185
|
'font-size' => attributes['font-size'].to_f,
|
|
178
186
|
'color' => attributes['fill'],
|
|
179
187
|
'font-style' => font_style(attributes),
|
|
@@ -235,7 +243,7 @@ module Thinreports
|
|
|
235
243
|
'format' => text_format,
|
|
236
244
|
'reference-id' => attributes['x-ref-id'],
|
|
237
245
|
'style' => {
|
|
238
|
-
'font-family' => [
|
|
246
|
+
'font-family' => [attributes['font-family']],
|
|
239
247
|
'font-size' => attributes['font-size'].to_f,
|
|
240
248
|
'color' => attributes['fill'],
|
|
241
249
|
'font-style' => font_style(attributes),
|
|
@@ -368,9 +376,9 @@ module Thinreports
|
|
|
368
376
|
items
|
|
369
377
|
end
|
|
370
378
|
|
|
371
|
-
def
|
|
372
|
-
svg.gsub
|
|
373
|
-
|
|
379
|
+
def cleanup_svg(svg)
|
|
380
|
+
cleaned_svg = svg.gsub(/<!--SHAPE.*?SHAPE-->/, '')
|
|
381
|
+
cleaned_svg.gsub(/<!--LAYOUT(.*?)LAYOUT-->/) { $1 }
|
|
374
382
|
end
|
|
375
383
|
end
|
|
376
384
|
end
|
|
@@ -1,42 +1,39 @@
|
|
|
1
|
-
#
|
|
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'.freeze
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
class << self
|
|
10
|
+
def compatible_rules
|
|
11
|
+
COMPATIBLE_RULES
|
|
12
|
+
end
|
|
13
|
+
end
|
|
8
14
|
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
16
|
-
|
|
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
|
-
|
|
22
|
+
schema_version.send(op.to_sym, normalize_version(ver))
|
|
22
23
|
end
|
|
23
24
|
end
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
'(' + REQUIRED_RULES.join(' and ') + ')'
|
|
26
|
+
def legacy?
|
|
27
|
+
@schema_version < normalize_version(NEW_SCHEMA_FROM)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
data/lib/thinreports/report.rb
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
#
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
require_relative 'report/base'
|
|
23
|
+
require_relative 'report/internal'
|
|
24
|
+
require_relative 'report/page'
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
#
|
|
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
|
-
|
|
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
|
-
# @
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
layout ||= report[:layout]
|
|
42
|
+
filename ||= generator[:filename]
|
|
43
|
+
security ||= generator[:security]
|
|
47
44
|
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
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
|
-
# @
|
|
167
|
-
#
|
|
168
|
-
#
|
|
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(
|
|
178
|
-
|
|
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
|
-
#
|
|
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
|
|
23
|
-
@pages
|
|
24
|
-
@page
|
|
21
|
+
@finalized = false
|
|
22
|
+
@pages = []
|
|
23
|
+
@page = nil
|
|
25
24
|
@page_count = 0
|
|
26
25
|
|
|
27
26
|
@page_create_handler = nil
|
|
@@ -52,10 +51,10 @@ module Thinreports
|
|
|
52
51
|
end
|
|
53
52
|
|
|
54
53
|
def finalize
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
return if finalized?
|
|
55
|
+
|
|
56
|
+
finalize_current_page
|
|
57
|
+
@finalized = true
|
|
59
58
|
end
|
|
60
59
|
|
|
61
60
|
def finalized?
|
|
@@ -79,7 +78,7 @@ module Thinreports
|
|
|
79
78
|
layout
|
|
80
79
|
end
|
|
81
80
|
|
|
82
|
-
|
|
81
|
+
private
|
|
83
82
|
|
|
84
83
|
def insert_page(new_page)
|
|
85
84
|
@pages << new_page
|
|
@@ -102,6 +101,5 @@ module Thinreports
|
|
|
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
|
-
#
|
|
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
|
|
55
|
-
@layout
|
|
53
|
+
@report = report
|
|
54
|
+
@layout = layout
|
|
56
55
|
@finalized = false
|
|
57
56
|
|
|
58
57
|
initialize_manager(layout.format) do |f|
|
|
@@ -65,6 +64,7 @@ module Thinreports
|
|
|
65
64
|
false
|
|
66
65
|
end
|
|
67
66
|
|
|
67
|
+
# rubocop:disable Metrics/AbcSize
|
|
68
68
|
def copy
|
|
69
69
|
new_page = self.class.new(report, layout, count: count?)
|
|
70
70
|
|
|
@@ -86,7 +86,7 @@ module Thinreports
|
|
|
86
86
|
|
|
87
87
|
# For list shapes.
|
|
88
88
|
if at == :create
|
|
89
|
-
manager.lists.values.each {|list| list.manager.finalize }
|
|
89
|
+
manager.lists.values.each { |list| list.manager.finalize }
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
@finalized = true
|
|
@@ -96,6 +96,5 @@ module Thinreports
|
|
|
96
96
|
@finalized
|
|
97
97
|
end
|
|
98
98
|
end
|
|
99
|
-
|
|
100
99
|
end
|
|
101
100
|
end
|
data/lib/thinreports/version.rb
CHANGED
data/test/schema_helper.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Thinreports
|
|
2
4
|
module SchemaHelper
|
|
3
5
|
BASIC_SCHEMA_JSON = <<-EOF
|
|
@@ -108,12 +110,11 @@ EOF
|
|
|
108
110
|
EOF
|
|
109
111
|
|
|
110
112
|
def layout_file(options = {})
|
|
111
|
-
|
|
112
|
-
version = options[:version] || '0.9.0'
|
|
113
|
+
schema_version = options[:version] || Thinreports::VERSION
|
|
113
114
|
schema_json = options[:schema] || BASIC_SCHEMA_JSON
|
|
114
115
|
|
|
115
116
|
Tempfile.open %w( test-thinreports-layout .tlf ) do |file|
|
|
116
|
-
file.puts (schema_json % { version:
|
|
117
|
+
file.puts (schema_json % { version: schema_version })
|
|
117
118
|
file
|
|
118
119
|
end
|
|
119
120
|
end
|
data/test/test_helper.rb
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
gem 'minitest' # for 1.9.3
|
|
4
3
|
require 'minitest/autorun'
|
|
5
4
|
require 'minitest/spec'
|
|
6
5
|
require 'minitest/unit'
|
|
7
6
|
require 'mocha/mini_test'
|
|
7
|
+
require 'pdf/inspector'
|
|
8
8
|
|
|
9
9
|
require 'digest/sha1'
|
|
10
10
|
require 'pathname'
|
|
11
|
-
require 'chunky_png'
|
|
12
11
|
require 'thinreports'
|
|
13
12
|
|
|
14
13
|
require 'schema_helper'
|
|
@@ -35,6 +34,13 @@ module Thinreports::TestHelper
|
|
|
35
34
|
ROOT.join('tmp')
|
|
36
35
|
end
|
|
37
36
|
|
|
37
|
+
def analyze_pdf_images(pdf_data)
|
|
38
|
+
analyzer = PDF::Inspector::XObject.analyze(pdf_data)
|
|
39
|
+
analyzer.page_xobjects
|
|
40
|
+
.reduce(:merge).values
|
|
41
|
+
.select { |o| o.hash[:Subtype] == :Image }
|
|
42
|
+
end
|
|
43
|
+
|
|
38
44
|
def teardown
|
|
39
45
|
super
|
|
40
46
|
FileUtils.rm Dir.glob(temp_path.join('*'))
|