thinreports 0.9.1 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/test.yml +39 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +59 -2
- data/Dockerfile +12 -0
- data/Gemfile +7 -4
- data/README.md +44 -22
- data/Rakefile +14 -31
- 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 +10 -12
- data/lib/thinreports/core/shape/base.rb +3 -12
- data/lib/thinreports/core/shape/base/interface.rb +34 -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 +179 -176
- data/lib/thinreports/core/shape/list/page.rb +91 -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 +87 -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 +46 -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 +52 -34
- 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 +66 -68
- data/lib/thinreports/core/utils.rb +7 -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 +57 -51
- data/lib/thinreports/generator/pdf/document/draw_template_items.rb +50 -47
- data/lib/thinreports/generator/pdf/document/font.rb +67 -58
- data/lib/thinreports/generator/pdf/document/graphics.rb +32 -33
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +121 -121
- data/lib/thinreports/generator/pdf/document/graphics/basic.rb +112 -114
- data/lib/thinreports/generator/pdf/document/graphics/image.rb +58 -150
- data/lib/thinreports/generator/pdf/document/graphics/text.rb +149 -137
- data/lib/thinreports/generator/pdf/document/page.rb +60 -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 +56 -54
- 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 +32 -0
- data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +35 -0
- data/lib/thinreports/layout.rb +5 -7
- data/lib/thinreports/layout/base.rb +5 -9
- data/lib/thinreports/layout/format.rb +17 -13
- data/lib/thinreports/layout/legacy_schema.rb +17 -13
- 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 +13 -15
- data/lib/thinreports/report/page.rb +5 -11
- data/lib/thinreports/version.rb +2 -2
- data/thinreports.gemspec +10 -19
- metadata +13 -288
- data/.travis.yml +0 -19
- data/examples/character_spacing/character_spacing.rb +0 -8
- data/examples/character_spacing/character_spacing.tlf +0 -293
- data/examples/dynamic_image/dynamic_image.rb +0 -31
- data/examples/dynamic_image/dynamic_image.tlf +0 -661
- data/examples/dynamic_image/img200x100.png +0 -0
- data/examples/dynamic_image/img50x50.png +0 -0
- data/examples/dynamic_style/dynamic_style.rb +0 -150
- data/examples/dynamic_style/dynamic_style.tlf +0 -1835
- data/examples/dynamic_style/dynamic_style_in_list.tlf +0 -344
- data/examples/dynamic_style/image.png +0 -0
- data/examples/eudc/eudc.rb +0 -20
- data/examples/eudc/eudc.tlf +0 -180
- data/examples/eudc/eudc.ttf +0 -0
- data/examples/helper.rb +0 -50
- data/examples/hidden_shapes/hidden_shapes.rb +0 -9
- data/examples/hidden_shapes/hidden_shapes.tlf +0 -449
- data/examples/list_events/list_events.rb +0 -32
- data/examples/list_events/list_events.tlf +0 -361
- data/examples/list_manual_generation/list_manual_generation.rb +0 -22
- data/examples/list_manual_generation/list_manual_generation.tlf +0 -132
- data/examples/list_page_number/list_page_number.rb +0 -17
- data/examples/list_page_number/list_page_number.tlf +0 -254
- data/examples/page_number/page_number.rb +0 -33
- data/examples/page_number/page_number.tlf +0 -215
- data/examples/palleted_png/palleted_png.png +0 -0
- data/examples/palleted_png/palleted_png.rb +0 -11
- data/examples/palleted_png/palleted_png.tlf +0 -47
- data/examples/password_setting/password_setting.rb +0 -10
- data/examples/password_setting/password_setting.tlf +0 -45
- data/examples/report_callbacks/report_callbacks.rb +0 -14
- data/examples/report_callbacks/report_callbacks.tlf +0 -147
- data/examples/single_line_tblock/single_line_tblock.rb +0 -13
- data/examples/single_line_tblock/single_line_tblock.tlf +0 -170
- data/examples/tblock_overflow/tblock_overflow.rb +0 -20
- data/examples/tblock_overflow/tblock_overflow.tlf +0 -538
- data/examples/tblock_styles/font_size.tlf +0 -383
- data/examples/tblock_styles/tblock_styles.rb +0 -43
- data/examples/tblock_styles/tblock_styles.tlf +0 -889
- data/examples/text_align/text_align.rb +0 -8
- data/examples/text_align/text_align.tlf +0 -241
- data/examples/typeB_page_size/B4_ISO.tlf +0 -45
- data/examples/typeB_page_size/B4_JIS.tlf +0 -45
- data/examples/typeB_page_size/typeB_page_size.rb +0 -17
- data/examples/word_wrap/word_wrap.rb +0 -26
- data/examples/word_wrap/word_wrap.tlf +0 -297
- 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/data/font.ttf +0 -0
- data/test/data/image_normal.jpg +0 -0
- data/test/data/image_normal.png +0 -0
- data/test/data/image_normal_jpg_noext +0 -0
- data/test/data/image_normal_png_noext +0 -0
- data/test/data/image_pallete_based.png +0 -0
- data/test/data/legacy_layout/all-items.tlf +0 -1
- data/test/schema_helper.rb +0 -121
- data/test/test_helper.rb +0 -42
- data/test/tmp/.gitkeep +0 -0
- data/test/unit/core/format/test_base.rb +0 -152
- data/test/unit/core/shape/base/test_internal.rb +0 -87
- data/test/unit/core/shape/basic/test_block_format.rb +0 -23
- data/test/unit/core/shape/basic/test_block_interface.rb +0 -29
- data/test/unit/core/shape/basic/test_block_internal.rb +0 -55
- data/test/unit/core/shape/basic/test_format.rb +0 -37
- data/test/unit/core/shape/basic/test_interface.rb +0 -108
- data/test/unit/core/shape/basic/test_internal.rb +0 -55
- data/test/unit/core/shape/image_block/test_interface.rb +0 -24
- data/test/unit/core/shape/image_block/test_internal.rb +0 -31
- data/test/unit/core/shape/list/test_format.rb +0 -111
- data/test/unit/core/shape/list/test_manager.rb +0 -67
- data/test/unit/core/shape/list/test_page.rb +0 -82
- data/test/unit/core/shape/list/test_page_state.rb +0 -31
- data/test/unit/core/shape/list/test_section_format.rb +0 -36
- data/test/unit/core/shape/list/test_section_interface.rb +0 -75
- data/test/unit/core/shape/list/test_section_internal.rb +0 -50
- data/test/unit/core/shape/manager/test_format.rb +0 -38
- data/test/unit/core/shape/manager/test_internal.rb +0 -132
- data/test/unit/core/shape/manager/test_target.rb +0 -140
- data/test/unit/core/shape/page_number/test_format.rb +0 -55
- data/test/unit/core/shape/page_number/test_interface.rb +0 -33
- data/test/unit/core/shape/page_number/test_internal.rb +0 -81
- data/test/unit/core/shape/styles/test_base.rb +0 -191
- data/test/unit/core/shape/styles/test_basic.rb +0 -24
- data/test/unit/core/shape/styles/test_graphic.rb +0 -50
- data/test/unit/core/shape/styles/test_text.rb +0 -97
- data/test/unit/core/shape/text/test_format.rb +0 -44
- data/test/unit/core/shape/text/test_internal.rb +0 -20
- data/test/unit/core/shape/text_block/formatter/test_basic.rb +0 -24
- data/test/unit/core/shape/text_block/formatter/test_datetime.rb +0 -49
- data/test/unit/core/shape/text_block/formatter/test_number.rb +0 -76
- data/test/unit/core/shape/text_block/formatter/test_padding.rb +0 -77
- data/test/unit/core/shape/text_block/test_format.rb +0 -169
- data/test/unit/core/shape/text_block/test_formatter.rb +0 -28
- data/test/unit/core/shape/text_block/test_interface.rb +0 -63
- data/test/unit/core/shape/text_block/test_internal.rb +0 -128
- data/test/unit/core/test_shape.rb +0 -52
- data/test/unit/core/test_utils.rb +0 -68
- data/test/unit/generator/pdf/document/graphics/test_attributes.rb +0 -135
- data/test/unit/generator/pdf/document/graphics/test_basic.rb +0 -45
- data/test/unit/generator/pdf/document/graphics/test_image.rb +0 -150
- data/test/unit/generator/pdf/document/graphics/test_text.rb +0 -171
- data/test/unit/generator/pdf/document/test_font.rb +0 -84
- data/test/unit/generator/pdf/document/test_graphics.rb +0 -42
- data/test/unit/generator/pdf/document/test_page.rb +0 -122
- data/test/unit/generator/pdf/document/test_parse_color.rb +0 -30
- data/test/unit/generator/pdf/test_document.rb +0 -20
- data/test/unit/generator/test_base.rb +0 -40
- data/test/unit/generator/test_configuration.rb +0 -21
- data/test/unit/generator/test_pdf.rb +0 -24
- data/test/unit/layout/test_base.rb +0 -41
- data/test/unit/layout/test_format.rb +0 -100
- data/test/unit/layout/test_legacy_schema.rb +0 -574
- data/test/unit/layout/test_version.rb +0 -95
- data/test/unit/report/test_base.rb +0 -262
- data/test/unit/report/test_internal.rb +0 -206
- data/test/unit/test_config.rb +0 -51
- data/test/unit/test_layout.rb +0 -12
- data/test/unit/test_report.rb +0 -18
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
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
|
-
|
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(
|
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' => [
|
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
|
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' => [
|
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' => [
|
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
|
372
|
-
svg.gsub
|
373
|
-
|
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
|
-
#
|
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
|
-
|
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
|
@@ -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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|
75
|
+
@default_layout ||= layout
|
79
76
|
layout
|
80
77
|
end
|
81
78
|
|
82
|
-
|
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
|
-
#
|
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|
|
@@ -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
|
data/lib/thinreports/version.rb
CHANGED
data/thinreports.gemspec
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
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.
|
15
|
-
|
16
|
-
s.platform = Gem::Platform::RUBY
|
17
|
-
s.required_ruby_version = '>= 1.9.3'
|
15
|
+
s.license = 'MIT'
|
18
16
|
|
19
|
-
s.
|
20
|
-
s.extra_rdoc_files = ['README.md']
|
17
|
+
s.required_ruby_version = '>= 2.4.0'
|
21
18
|
|
22
|
-
s.files
|
23
|
-
|
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', '
|
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
|