thinreports 0.7.6 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -5
- data/.travis.yml +8 -4
- data/CHANGELOG.md +220 -0
- data/Gemfile +2 -9
- data/MIT-LICENSE +1 -1
- data/README.md +286 -0
- data/Rakefile +38 -8
- data/examples/character_spacing/character_spacing.rb +8 -0
- data/examples/character_spacing/character_spacing.tlf +1 -0
- data/examples/dynamic_image/dynamic_image.rb +31 -0
- data/examples/dynamic_image/dynamic_image.tlf +1 -0
- data/examples/dynamic_style/dynamic_style.rb +150 -0
- data/examples/dynamic_style/dynamic_style.tlf +1 -0
- data/examples/dynamic_style/dynamic_style_in_list.tlf +1 -0
- data/examples/eudc/eudc.rb +20 -0
- data/examples/eudc/eudc.tlf +1 -0
- data/examples/helper.rb +50 -0
- data/examples/hidden_shapes/hidden_shapes.rb +9 -0
- data/examples/hidden_shapes/hidden_shapes.tlf +1 -0
- data/examples/list_events/list_events.rb +59 -0
- data/examples/list_events/list_events_0_7_7.tlf +1 -0
- data/examples/list_events/list_events_0_8.tlf +1 -0
- data/examples/list_manual_generation/list_manual_generation.rb +22 -0
- data/examples/list_manual_generation/list_manual_generation.tlf +1 -0
- data/examples/list_page_number/list_page_number.rb +17 -0
- data/examples/list_page_number/list_page_number.tlf +1 -0
- data/examples/page_number/page_number.rb +33 -0
- data/examples/page_number/page_number.tlf +1 -0
- data/examples/password_setting/password_setting.rb +10 -0
- data/examples/password_setting/password_setting.tlf +1 -0
- data/examples/report_callbacks/report_callbacks.rb +31 -0
- data/examples/report_callbacks/report_callbacks.tlf +1 -0
- data/examples/single_line_tblock/single_line_tblock.rb +13 -0
- data/examples/single_line_tblock/single_line_tblock.tlf +1 -0
- data/examples/tblock_overflow/tblock_overflow.rb +20 -0
- data/examples/tblock_overflow/tblock_overflow.tlf +1 -0
- data/examples/tblock_styles/font_size.tlf +1 -0
- data/examples/tblock_styles/tblock_styles.rb +43 -0
- data/examples/tblock_styles/tblock_styles.tlf +1 -0
- data/examples/text_align/text_align.rb +8 -0
- data/examples/text_align/text_align.tlf +1 -0
- data/examples/typeB_page_size/B4_ISO.tlf +1 -0
- data/examples/typeB_page_size/B4_JIS.tlf +1 -0
- data/examples/typeB_page_size/typeB_page_size.rb +17 -0
- data/examples/word_wrap/word_wrap.rb +26 -0
- data/examples/word_wrap/word_wrap.tlf +1 -0
- data/lib/thinreports/config.rb +30 -10
- data/lib/thinreports/core/errors.rb +23 -20
- data/lib/thinreports/core/events.rb +18 -19
- data/lib/thinreports/core/format/base.rb +20 -25
- data/lib/thinreports/core/format/builder.rb +19 -27
- data/lib/thinreports/core/shape/base/interface.rb +15 -15
- data/lib/thinreports/core/shape/base/internal.rb +15 -20
- data/lib/thinreports/core/shape/base.rb +4 -5
- data/lib/thinreports/core/shape/basic/block_format.rb +3 -4
- data/lib/thinreports/core/shape/basic/block_interface.rb +9 -4
- data/lib/thinreports/core/shape/basic/block_internal.rb +9 -10
- data/lib/thinreports/core/shape/basic/format.rb +11 -10
- data/lib/thinreports/core/shape/basic/interface.rb +3 -3
- data/lib/thinreports/core/shape/basic/internal.rb +9 -6
- data/lib/thinreports/core/shape/basic.rb +1 -1
- data/lib/thinreports/core/shape/image_block/format.rb +5 -6
- data/lib/thinreports/core/shape/image_block/interface.rb +9 -7
- data/lib/thinreports/core/shape/image_block/internal.rb +5 -6
- data/lib/thinreports/core/shape/image_block.rb +1 -1
- data/lib/thinreports/core/shape/list/configuration.rb +37 -16
- data/lib/thinreports/core/shape/list/events.rb +11 -11
- data/lib/thinreports/core/shape/list/format.rb +27 -28
- data/lib/thinreports/core/shape/list/manager.rb +135 -95
- data/lib/thinreports/core/shape/list/page.rb +57 -51
- data/lib/thinreports/core/shape/list/page_state.rb +19 -17
- data/lib/thinreports/core/shape/list/section_format.rb +14 -15
- data/lib/thinreports/core/shape/list/section_interface.rb +15 -16
- data/lib/thinreports/core/shape/list/section_internal.rb +7 -8
- data/lib/thinreports/core/shape/list/store.rb +10 -11
- data/lib/thinreports/core/shape/list.rb +1 -1
- data/lib/thinreports/core/shape/manager/format.rb +10 -11
- data/lib/thinreports/core/shape/manager/internal.rb +22 -21
- data/lib/thinreports/core/shape/manager/target.rb +63 -34
- data/lib/thinreports/core/shape/manager.rb +1 -1
- data/lib/thinreports/core/shape/page_number/format.rb +25 -0
- data/lib/thinreports/core/shape/page_number/interface.rb +27 -0
- data/lib/thinreports/core/shape/page_number/internal.rb +57 -0
- data/lib/thinreports/core/shape/page_number.rb +15 -0
- data/lib/thinreports/core/shape/style/base.rb +29 -29
- data/lib/thinreports/core/shape/style/basic.rb +1 -1
- data/lib/thinreports/core/shape/style/graphic.rb +10 -25
- data/lib/thinreports/core/shape/style/text.rb +41 -31
- data/lib/thinreports/core/shape/style.rb +1 -1
- data/lib/thinreports/core/shape/text/format.rb +8 -9
- data/lib/thinreports/core/shape/text/interface.rb +2 -2
- data/lib/thinreports/core/shape/text/internal.rb +6 -7
- data/lib/thinreports/core/shape/text.rb +1 -1
- data/lib/thinreports/core/shape/text_block/format.rb +17 -17
- data/lib/thinreports/core/shape/text_block/formatter/basic.rb +13 -12
- data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +8 -9
- data/lib/thinreports/core/shape/text_block/formatter/number.rb +11 -12
- data/lib/thinreports/core/shape/text_block/formatter/padding.rb +9 -32
- data/lib/thinreports/core/shape/text_block/formatter.rb +7 -8
- data/lib/thinreports/core/shape/text_block/interface.rb +2 -2
- data/lib/thinreports/core/shape/text_block/internal.rb +19 -20
- data/lib/thinreports/core/shape/text_block.rb +1 -1
- data/lib/thinreports/core/shape.rb +11 -13
- data/lib/thinreports/core/utils.rb +33 -32
- data/lib/thinreports/generator/base.rb +15 -24
- data/lib/thinreports/generator/configuration.rb +10 -9
- data/lib/thinreports/generator/pdf/configuration.rb +11 -6
- data/lib/thinreports/generator/pdf/document/draw_shape.rb +41 -32
- data/lib/thinreports/generator/pdf/document/font.rb +53 -44
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +34 -25
- data/lib/thinreports/generator/pdf/document/graphics/basic.rb +25 -25
- data/lib/thinreports/generator/pdf/document/graphics/image.rb +15 -15
- data/lib/thinreports/generator/pdf/document/graphics/text.rb +43 -41
- data/lib/thinreports/generator/pdf/document/graphics.rb +8 -9
- data/lib/thinreports/generator/pdf/document/page.rb +37 -23
- data/lib/thinreports/generator/pdf/document/parse_color.rb +9 -10
- data/lib/thinreports/generator/pdf/document/parse_svg.rb +14 -15
- data/lib/thinreports/generator/pdf/document.rb +28 -28
- data/lib/thinreports/generator/pdf/drawer/base.rb +16 -22
- data/lib/thinreports/generator/pdf/drawer/list.rb +39 -21
- data/lib/thinreports/generator/pdf/drawer/list_section.rb +17 -18
- data/lib/thinreports/generator/pdf/drawer/page.rb +37 -26
- data/lib/thinreports/generator/pdf/prawn_ext.rb +18 -17
- data/lib/thinreports/generator/pdf.rb +28 -31
- data/lib/thinreports/generator.rb +6 -8
- data/lib/thinreports/layout/base.rb +24 -36
- data/lib/thinreports/layout/configuration.rb +11 -9
- data/lib/thinreports/layout/format.rb +26 -31
- data/lib/thinreports/layout/version.rb +8 -9
- data/lib/thinreports/layout.rb +2 -2
- data/lib/thinreports/report/base.rb +117 -109
- data/lib/thinreports/report/events.rb +5 -5
- data/lib/thinreports/report/internal.rb +48 -38
- data/lib/thinreports/{core → report}/page.rb +42 -32
- data/lib/thinreports/report.rb +10 -14
- data/lib/thinreports/version.rb +2 -3
- data/lib/thinreports.rb +14 -2
- data/test/data/font.ttf +0 -0
- data/test/data/layout_block.tlf +1 -0
- data/test/data/layout_list.tlf +1 -0
- data/test/data/layout_list_noheader.tlf +1 -0
- data/test/data/layout_text1.tlf +1 -0
- data/test/data/layout_text2.tlf +1 -0
- data/test/test_helper.rb +74 -0
- data/test/tmp/.gitkeep +0 -0
- data/test/unit/core/format/test_base.rb +14 -14
- data/test/unit/core/format/test_builder.rb +20 -25
- data/test/unit/core/shape/base/test_internal.rb +34 -37
- data/test/unit/core/shape/basic/test_basic_format.rb +4 -4
- data/test/unit/core/shape/basic/test_basic_interface.rb +15 -13
- data/test/unit/core/shape/basic/test_basic_internal.rb +19 -16
- data/test/unit/core/shape/basic/test_format.rb +4 -4
- data/test/unit/core/shape/basic/test_interface.rb +36 -46
- data/test/unit/core/shape/basic/test_internal.rb +29 -18
- data/test/unit/core/shape/image_block/test_format.rb +5 -5
- data/test/unit/core/shape/image_block/test_interface.rb +17 -16
- data/test/unit/core/shape/image_block/test_internal.rb +19 -16
- data/test/unit/core/shape/list/test_configuration.rb +50 -33
- data/test/unit/core/shape/list/test_events.rb +7 -7
- data/test/unit/core/shape/list/test_format.rb +16 -18
- data/test/unit/core/shape/list/test_manager.rb +15 -5
- data/test/unit/core/shape/list/test_page.rb +80 -22
- data/test/unit/core/shape/list/test_page_state.rb +13 -13
- data/test/unit/core/shape/list/test_section_format.rb +16 -17
- data/test/unit/core/shape/list/test_section_interface.rb +30 -22
- data/test/unit/core/shape/list/test_section_internal.rb +21 -19
- data/test/unit/core/shape/list/test_store.rb +7 -7
- data/test/unit/core/shape/manager/test_format.rb +11 -15
- data/test/unit/core/shape/manager/test_internal.rb +9 -9
- data/test/unit/core/shape/manager/test_target.rb +85 -57
- data/test/unit/core/shape/page_number/test_format.rb +73 -0
- data/test/unit/core/shape/page_number/test_interface.rb +33 -0
- data/test/unit/core/shape/page_number/test_internal.rb +81 -0
- data/test/unit/core/shape/styles/test_base.rb +9 -9
- data/test/unit/core/shape/styles/test_basic.rb +5 -5
- data/test/unit/core/shape/styles/test_graphic.rb +19 -33
- data/test/unit/core/shape/styles/test_text.rb +29 -7
- data/test/unit/core/shape/text/test_format.rb +6 -6
- data/test/unit/core/shape/text/test_internal.rb +11 -12
- data/test/unit/core/shape/text_block/formatter/test_basic.rb +16 -16
- data/test/unit/core/shape/text_block/formatter/test_datetime.rb +22 -20
- data/test/unit/core/shape/text_block/formatter/test_number.rb +34 -34
- data/test/unit/core/shape/text_block/formatter/test_padding.rb +44 -44
- data/test/unit/core/shape/text_block/test_format.rb +13 -8
- data/test/unit/core/shape/text_block/test_formatter.rb +17 -17
- data/test/unit/core/shape/text_block/test_interface.rb +37 -20
- data/test/unit/core/shape/text_block/test_internal.rb +38 -38
- data/test/unit/core/test_events.rb +10 -8
- data/test/unit/core/test_shape.rb +11 -7
- data/test/unit/core/test_utils.rb +68 -0
- data/test/unit/generator/pdf/document/graphics/test_attributes.rb +10 -4
- data/test/unit/generator/pdf/document/graphics/test_text.rb +60 -53
- data/test/unit/generator/pdf/document/test_draw_shape.rb +14 -6
- data/test/unit/generator/pdf/document/test_font.rb +79 -58
- data/test/unit/generator/pdf/document/test_graphics.rb +18 -19
- data/test/unit/generator/pdf/document/test_page.rb +68 -43
- data/test/unit/generator/pdf/document/test_parse_color.rb +5 -5
- data/test/unit/generator/pdf/test_configuration.rb +16 -9
- data/test/unit/generator/pdf/test_document.rb +8 -16
- data/test/unit/generator/test_base.rb +31 -42
- data/test/unit/generator/test_configuration.rb +6 -6
- data/test/unit/generator/test_pdf.rb +15 -21
- data/test/unit/layout/test_base.rb +34 -79
- data/test/unit/layout/test_configuration.rb +12 -37
- data/test/unit/layout/test_format.rb +36 -39
- data/test/unit/layout/test_version.rb +4 -4
- data/test/unit/report/test_base.rb +160 -192
- data/test/unit/report/test_events.rb +4 -4
- data/test/unit/report/test_internal.rb +102 -82
- data/test/unit/test_config.rb +31 -12
- data/test/unit/test_layout.rb +7 -7
- data/test/unit/test_report.rb +12 -24
- data/thinreports.gemspec +23 -26
- metadata +118 -181
- data/.yardopts +0 -1
- data/LICENSE +0 -1
- data/README.rdoc +0 -167
- data/doc/yardoc_templates/default/layout/html/footer.erb +0 -10
- data/lib/thinreports/core/ext/array.rb +0 -19
- data/lib/thinreports/core/ext/hash.rb +0 -19
- data/lib/thinreports/core/ext/object.rb +0 -25
- data/lib/thinreports/core/ext.rb +0 -5
- data/lib/thinreports/core/format.rb +0 -14
- data/lib/thinreports/core/ordered_hash.rb +0 -39
- data/lib/thinreports/core.rb +0 -20
- data/lib/thinreports/generator/pdf/drawer.rb +0 -16
- data/tasks/doc.rake +0 -13
- data/tasks/test.rake +0 -56
- data/test/benchmark/basic_estimate.tlf +0 -1
- data/test/benchmark/bench_basic_estimate.rb +0 -95
- data/test/case/character_spacing/character_spacing.rb +0 -7
- data/test/case/character_spacing/character_spacing.tlf +0 -1
- data/test/case/dynamic_image/dynamic_image.rb +0 -41
- data/test/case/dynamic_image/dynamic_image.tlf +0 -1
- data/test/case/dynamic_style/dynamic_style.rb +0 -154
- data/test/case/dynamic_style/dynamic_style.tlf +0 -1
- data/test/case/dynamic_style/dynamic_style_in_list.tlf +0 -1
- data/test/case/eudc/eudc.rb +0 -20
- data/test/case/eudc/eudc.tlf +0 -1
- data/test/case/helper.rb +0 -29
- data/test/case/hidden_shapes/hidden_shapes.rb +0 -13
- data/test/case/hidden_shapes/hidden_shapes.tlf +0 -1
- data/test/case/list_events/list_events.rb +0 -32
- data/test/case/list_events/list_events.tlf +0 -1
- data/test/case/list_header_inheriting/list_header_inheriting.rb +0 -17
- data/test/case/list_header_inheriting/list_header_inheriting.tlf +0 -1
- data/test/case/list_manual_generation/list_manual_generation.rb +0 -22
- data/test/case/list_manual_generation/list_manual_generation.tlf +0 -1
- data/test/case/single_line_tblock/single_line_tblock.rb +0 -15
- data/test/case/single_line_tblock/single_line_tblock.tlf +0 -1
- data/test/case/tblock_overflow/tblock_overflow.rb +0 -20
- data/test/case/tblock_overflow/tblock_overflow.tlf +0 -1
- data/test/case/tblock_styles/tblock_styles.rb +0 -27
- data/test/case/tblock_styles/tblock_styles.tlf +0 -1
- data/test/case/text_align/text_align.rb +0 -9
- data/test/case/text_align/text_align.tlf +0 -1
- data/test/unit/core/ext/array_spec.rb +0 -29
- data/test/unit/core/ext/hash_spec.rb +0 -29
- data/test/unit/core/ext/object_spec.rb +0 -30
- data/test/unit/core/ordered_hash_spec.rb +0 -51
- data/test/unit/core/shape/base/test_interface.rb +0 -52
- data/test/unit/core/utils_spec.rb +0 -56
- data/test/unit/data/basic_layout1.tlf +0 -1
- data/test/unit/data/basic_layout2.tlf +0 -1
- data/test/unit/data/basic_list_layout.tlf +0 -1
- data/test/unit/data/basic_list_noheader_layout.tlf +0 -1
- data/test/unit/helper.rb +0 -65
- /data/{test/case → examples}/dynamic_image/img200x100.png +0 -0
- /data/{test/case → examples}/dynamic_image/img50x50.png +0 -0
- /data/{test/case → examples}/dynamic_style/image.png +0 -0
- /data/{test/case → examples}/eudc/eudc.ttf +0 -0
- /data/{resources/fonts → fonts}/IPA_Font_License_Agreement_v1.0.txt +0 -0
- /data/{resources/fonts → fonts}/ipag.ttf +0 -0
- /data/{resources/fonts → fonts}/ipagp.ttf +0 -0
- /data/{resources/fonts → fonts}/ipam.ttf +0 -0
- /data/{resources/fonts → fonts}/ipamp.ttf +0 -0
@@ -1,30 +1,29 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module Thinreports
|
4
4
|
module Report
|
5
|
-
|
5
|
+
|
6
6
|
class Base
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
extend Forwardable
|
8
|
+
include Utils
|
9
|
+
|
11
10
|
class << self
|
12
11
|
# @param options (see #initialize)
|
13
12
|
# @option options (see #initialize)
|
14
13
|
# @yield [report]
|
15
|
-
# @yieldparam [
|
16
|
-
# @return [
|
14
|
+
# @yieldparam [Thinreports::Report::Base] report
|
15
|
+
# @return [Thinreports::Report::Base]
|
17
16
|
def create(options = {}, &block)
|
18
17
|
unless block_given?
|
19
18
|
raise ArgumentError, '#create requires a block'
|
20
19
|
end
|
21
20
|
report = new(options)
|
22
|
-
|
21
|
+
call_block_in(report, &block)
|
23
22
|
report.finalize
|
24
|
-
|
23
|
+
|
25
24
|
report
|
26
25
|
end
|
27
|
-
|
26
|
+
|
28
27
|
# @overload generate(type, options = {}, &block)
|
29
28
|
# @param [Symbol] type
|
30
29
|
# @param [Hash] options
|
@@ -39,40 +38,22 @@ module ThinReports
|
|
39
38
|
# @return [String]
|
40
39
|
def generate(*args, &block)
|
41
40
|
raise ArgumentError, '#generate requires a block' unless block_given?
|
42
|
-
|
41
|
+
|
43
42
|
report_opts, generator_opts = extract_options!(args)
|
44
|
-
|
43
|
+
|
45
44
|
report = create(report_opts, &block)
|
46
45
|
report.generate(*args.push(generator_opts))
|
47
46
|
end
|
48
|
-
|
49
|
-
# @overload generate_file(type, filename, options = {}, &block)
|
50
|
-
# @overload generate_file(filename, options = {}, &block)
|
51
|
-
# @param filename (see #generate_file)
|
52
|
-
# @yield (see .create)
|
53
|
-
# @yieldparam (see .create)
|
54
|
-
# @see .generate
|
55
|
-
# @return [void]
|
56
|
-
def generate_file(*args, &block)
|
57
|
-
raise ArgumentError, '#generate_file requires a block' unless block_given?
|
58
|
-
|
59
|
-
report_opts, generator_opts = extract_options!(args)
|
60
|
-
|
61
|
-
report = create(report_opts, &block)
|
62
|
-
report.generate_file(*args.push(generator_opts))
|
63
|
-
end
|
64
|
-
|
65
|
-
private
|
66
|
-
|
47
|
+
|
67
48
|
# @param [Array] args
|
68
49
|
# @return [Array<Hash>]
|
69
50
|
def extract_options!(args)
|
70
51
|
if args.last.is_a?(::Hash)
|
71
52
|
options = args.pop
|
72
|
-
|
53
|
+
|
73
54
|
generator = options.delete(:generator) || {}
|
74
55
|
report = options.delete(:report) || {}
|
75
|
-
|
56
|
+
|
76
57
|
if options.key?(:layout)
|
77
58
|
report[:layout] = options.delete(:layout)
|
78
59
|
end
|
@@ -82,124 +63,151 @@ module ThinReports
|
|
82
63
|
end
|
83
64
|
end
|
84
65
|
end
|
85
|
-
|
66
|
+
|
67
|
+
# @return [Thinreports::Report::Internal]
|
68
|
+
attr_reader :internal
|
69
|
+
|
70
|
+
# @return [Integer]
|
71
|
+
attr_reader :start_page_number
|
72
|
+
|
73
|
+
# @return [Thinreports::Report::Page]
|
74
|
+
def_delegator :internal, :page
|
75
|
+
|
76
|
+
# @return [Integer]
|
77
|
+
def_delegator :internal, :page_count
|
78
|
+
|
79
|
+
# @return [Array<Thinreports::Report::Page>]
|
80
|
+
def_delegator :internal, :pages
|
81
|
+
|
82
|
+
# @return [Thinreports::Layout::Base]
|
83
|
+
def_delegator :internal, :default_layout
|
84
|
+
|
86
85
|
# @param [Hash] options
|
87
86
|
# @option options [String, nil] :layout (nil)
|
88
87
|
def initialize(options = {})
|
89
88
|
@internal = Report::Internal.new(self, options)
|
89
|
+
@start_page_number = 1
|
90
|
+
|
91
|
+
@page_create_handler = nil
|
92
|
+
@generate_handler = nil
|
93
|
+
end
|
94
|
+
|
95
|
+
# @yield [page]
|
96
|
+
# @yieldparam [Thinreports::Report::Page] page
|
97
|
+
# @example
|
98
|
+
# report.on_page_create do |page|
|
99
|
+
# page.item(:header_title).value = 'Title'
|
100
|
+
# end
|
101
|
+
def on_page_create(&block)
|
102
|
+
internal.page_create_handler = block
|
90
103
|
end
|
91
|
-
|
92
|
-
# @param [
|
104
|
+
|
105
|
+
# @param [Integer] page_number
|
106
|
+
def start_page_number_from(page_number)
|
107
|
+
@start_page_number = page_number
|
108
|
+
end
|
109
|
+
|
110
|
+
# @param [String] layout filename of layout file
|
93
111
|
# @param [Hash] options
|
94
112
|
# @option options [Boolean] :default (true)
|
95
113
|
# @option options [Symbol] :id (nil)
|
96
114
|
# @yield [config]
|
97
|
-
# @yieldparam [
|
98
|
-
# @
|
115
|
+
# @yieldparam [Thinreports::Layout::Configuration] config
|
116
|
+
# @example
|
117
|
+
# report.use_layout '/path/to/default_layout.tlf' # Default layout
|
118
|
+
# report.use_layout '/path/to/default_layout.tlf', default: true
|
119
|
+
# report.use_layout '/path/to/other_layout', id: :other_layout
|
99
120
|
def use_layout(layout, options = {}, &block)
|
100
121
|
internal.register_layout(layout, options, &block)
|
101
122
|
end
|
102
|
-
|
123
|
+
|
124
|
+
# @example
|
125
|
+
# page = report.start_new_page
|
126
|
+
#
|
127
|
+
# report.start_new_page do |page|
|
128
|
+
# page.item(:text).value = 'value'
|
129
|
+
# end
|
130
|
+
#
|
131
|
+
# report.use_layout 'foo.tlf', default: true
|
132
|
+
# report.use_layout 'bar.tlf', id: :bar
|
133
|
+
#
|
134
|
+
# report.start_new_page # Use 'foo.tlf'
|
135
|
+
# report.start_new_page layout: :bar # Use 'bar.tlf'
|
136
|
+
# report.start_new_page layout: 'boo.tlf' # Use 'boo.tlf'
|
103
137
|
# @param [Hash] options
|
104
138
|
# @option options [String, Symbol] :layout (nil)
|
139
|
+
# @option options [Boolean] :count (true)
|
105
140
|
# @yield [page]
|
106
|
-
# @yieldparam [
|
107
|
-
# @return [
|
141
|
+
# @yieldparam [Thinreports::Report::Page] page
|
142
|
+
# @return [Thinreports::Report::Page]
|
108
143
|
def start_new_page(options = {}, &block)
|
109
|
-
unless layout = internal.load_layout(options
|
110
|
-
raise
|
144
|
+
unless layout = internal.load_layout(options.delete(:layout))
|
145
|
+
raise Thinreports::Errors::NoRegisteredLayoutFound
|
111
146
|
end
|
112
|
-
|
113
|
-
page = internal.add_page(layout.
|
114
|
-
|
147
|
+
|
148
|
+
page = internal.add_page(layout.new_page(self, options))
|
149
|
+
call_block_in(page, &block)
|
115
150
|
end
|
116
|
-
|
151
|
+
|
117
152
|
# @param [Hash] options
|
118
153
|
# @option options [Boolean] :count (true)
|
119
|
-
# @return [
|
154
|
+
# @return [Thinreports::Report::BlankPage]
|
120
155
|
def add_blank_page(options = {})
|
121
|
-
internal.add_page(
|
156
|
+
internal.add_page(Report::BlankPage.new(options[:count]))
|
122
157
|
end
|
123
158
|
alias_method :blank_page, :add_blank_page
|
124
|
-
|
125
|
-
# @param [Symbol, nil] id
|
126
|
-
#
|
127
|
-
# @return [ThinReports::Layout::Base]
|
159
|
+
|
160
|
+
# @param [Symbol, nil] id
|
161
|
+
# @return [Thinreports::Layout::Base]
|
128
162
|
def layout(id = nil)
|
129
163
|
if id
|
130
164
|
internal.layout_registry[id] ||
|
131
|
-
raise(
|
165
|
+
raise(Thinreports::Errors::UnknownLayoutId)
|
132
166
|
else
|
133
167
|
internal.default_layout
|
134
168
|
end
|
135
169
|
end
|
136
|
-
|
137
|
-
# @return [ThinReports::Layout::Base]
|
138
|
-
def default_layout
|
139
|
-
internal.default_layout
|
140
|
-
end
|
141
|
-
|
142
|
-
# @overload generate(type, options = {})
|
143
|
-
# Specify the generator type.
|
144
|
-
# @param [Symbol] type
|
145
|
-
# @return [String]
|
170
|
+
|
146
171
|
# @overload generate(options = {})
|
147
|
-
# Using the default generator type.
|
148
172
|
# @param [Hash] options ({})
|
149
173
|
# @return [String]
|
174
|
+
# @overload generate(type, options = {})
|
175
|
+
# This way has been DEPRECATED. Use instead #generate(options = {}).
|
176
|
+
# @param [Symbol] type
|
177
|
+
# @return [String]
|
178
|
+
# @example Generate PDF data
|
179
|
+
# report.generate # => "%PDF-1.4...."
|
180
|
+
# @example Create a PDF file
|
181
|
+
# report.generate(filename: 'foo.pdf')
|
150
182
|
def generate(*args)
|
151
183
|
options = args.last.is_a?(::Hash) ? args.pop : {}
|
152
|
-
type
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
# @param type (#generate)
|
158
|
-
# @return [void]
|
159
|
-
# @overload generate_file(filename, options = {})
|
160
|
-
# @param [String] filename
|
161
|
-
# @param options (see #generate)
|
162
|
-
# @return [void]
|
163
|
-
def generate_file(*args)
|
164
|
-
options = args.last.is_a?(::Hash) ? args.pop : {}
|
165
|
-
args.unshift(ThinReports.config.generator.default) if args.size == 1
|
166
|
-
type, filename = args
|
167
|
-
ThinReports::Generator.new(type, self, options).generate_file(filename)
|
184
|
+
type = args.first || Thinreports.config.generator.default
|
185
|
+
filename = options.delete(:filename)
|
186
|
+
generator = Thinreports::Generator.new(type, self, options)
|
187
|
+
|
188
|
+
generator.generate(filename)
|
168
189
|
end
|
169
|
-
|
170
|
-
# @see
|
190
|
+
|
191
|
+
# @see Thinreports::Core::Shape::Manager::Target#list
|
171
192
|
def list(id = nil, &block)
|
172
193
|
start_new_page if page.nil? || page.finalized?
|
173
194
|
page.list(id, &block)
|
174
195
|
end
|
175
|
-
|
176
|
-
# @return [
|
196
|
+
|
197
|
+
# @return [Thinreports::Report::Events]
|
198
|
+
# @deprecated
|
199
|
+
# `Report::Base#events` will be removed in the next major version.
|
200
|
+
# Please use #on_page_create callbacks instead.
|
201
|
+
# See also https://github.com/thinreports/thinreports-generator/blob/master/examples/report_callbacks/report_callbacks.rb.
|
177
202
|
def events
|
203
|
+
warn '[DEPRECATION] `Report::Base#events` will be removed in the next major version. ' +
|
204
|
+
'Please use #on_page_create callbacks instead. ' +
|
205
|
+
'See also https://github.com/thinreports/thinreports-generator/blob/master/examples/report_callbacks/report_callbacks.rb.'
|
178
206
|
internal.events
|
179
207
|
end
|
180
|
-
|
181
|
-
|
182
|
-
def page
|
183
|
-
internal.page
|
184
|
-
end
|
185
|
-
|
186
|
-
# @return [Integer]
|
187
|
-
def page_count
|
188
|
-
internal.page_count
|
189
|
-
end
|
190
|
-
|
191
|
-
# @return [void]
|
192
|
-
# @private
|
193
|
-
def finalize
|
194
|
-
internal.finalize
|
195
|
-
end
|
196
|
-
|
197
|
-
# @return [Boolean]
|
198
|
-
# @private
|
199
|
-
def finalized?
|
200
|
-
internal.finalized?
|
201
|
-
end
|
208
|
+
|
209
|
+
def_delegators :internal, :finalize, :finalized?
|
202
210
|
end
|
203
|
-
|
211
|
+
|
204
212
|
end
|
205
213
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module Thinreports
|
4
4
|
module Report
|
5
5
|
|
6
6
|
class Events < Core::Events
|
@@ -9,14 +9,14 @@ module ThinReports
|
|
9
9
|
:generate)
|
10
10
|
end
|
11
11
|
|
12
|
-
class Event <
|
13
|
-
# @return [
|
12
|
+
class Event < Thinreports::Core::Events::Event
|
13
|
+
# @return [Thinreports::Report::Page, nil]
|
14
14
|
attr_reader :page
|
15
15
|
|
16
|
-
# @return [Array<
|
16
|
+
# @return [Array<Thinreports::Report::Page>]
|
17
17
|
attr_reader :pages
|
18
18
|
|
19
|
-
# @return [
|
19
|
+
# @return [Thinreports::Report::Base]
|
20
20
|
alias_method :report, :target
|
21
21
|
|
22
22
|
def initialize(type, target, page = nil, pages = nil)
|
@@ -1,9 +1,8 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module Thinreports
|
4
4
|
module Report
|
5
|
-
|
6
|
-
# @private
|
5
|
+
|
7
6
|
class Internal
|
8
7
|
attr_reader :pages
|
9
8
|
attr_reader :page
|
@@ -11,9 +10,12 @@ module ThinReports
|
|
11
10
|
attr_reader :default_layout
|
12
11
|
attr_reader :layout_registry
|
13
12
|
attr_reader :events
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
|
14
|
+
attr_accessor :page_create_handler
|
15
|
+
attr_accessor :generate_handler
|
16
|
+
|
17
|
+
# @param [Thinreports::Report::Base] report
|
18
|
+
# @param options (see Thinreports::Report::Base#initialize)
|
17
19
|
def initialize(report, options)
|
18
20
|
@report = report
|
19
21
|
# Default layout
|
@@ -24,17 +26,20 @@ module ThinReports
|
|
24
26
|
@pages = []
|
25
27
|
@page = nil
|
26
28
|
@page_count = 0
|
27
|
-
|
29
|
+
|
30
|
+
@page_create_handler = nil
|
31
|
+
@generate_handler = nil
|
32
|
+
|
28
33
|
@events = Report::Events.new
|
29
34
|
end
|
30
|
-
|
31
|
-
# @see
|
35
|
+
|
36
|
+
# @see Thinreports::Report::Base#use_layout
|
32
37
|
def register_layout(layout, options = {}, &block)
|
33
38
|
layout = if options.empty? || options[:default]
|
34
39
|
@default_layout = init_layout(layout)
|
35
40
|
else
|
36
41
|
id = options[:id].to_sym
|
37
|
-
|
42
|
+
|
38
43
|
if layout_registry.key?(id)
|
39
44
|
raise ArgumentError, "Id :#{id} is already in use."
|
40
45
|
end
|
@@ -42,87 +47,92 @@ module ThinReports
|
|
42
47
|
end
|
43
48
|
layout.config(&block)
|
44
49
|
end
|
45
|
-
|
50
|
+
|
46
51
|
def add_page(new_page)
|
47
52
|
finalize_current_page
|
48
53
|
insert_page(new_page)
|
49
54
|
end
|
50
|
-
|
55
|
+
|
51
56
|
def copy_page
|
52
|
-
finalize_current_page(:
|
57
|
+
finalize_current_page(at: :copy)
|
53
58
|
insert_page(page.copy)
|
54
59
|
end
|
55
|
-
|
60
|
+
|
56
61
|
def finalize
|
57
62
|
unless finalized?
|
58
63
|
finalize_current_page
|
59
64
|
@finalized = true
|
60
|
-
|
61
|
-
#
|
65
|
+
|
66
|
+
# [DEPRECATION] Please use Report::Base#on_generate callback instead.
|
62
67
|
events.dispatch(Report::Events::Event.new(:generate,
|
63
68
|
@report, nil, pages))
|
69
|
+
|
70
|
+
@generate_handler.call(pages) if @generate_handler
|
64
71
|
end
|
65
72
|
end
|
66
|
-
|
73
|
+
|
67
74
|
def finalized?
|
68
75
|
@finalized
|
69
76
|
end
|
70
|
-
|
71
|
-
def load_layout(
|
72
|
-
return @default_layout if
|
73
|
-
|
74
|
-
case
|
77
|
+
|
78
|
+
def load_layout(id_or_filename)
|
79
|
+
return @default_layout if id_or_filename.nil?
|
80
|
+
|
81
|
+
layout = case id_or_filename
|
75
82
|
when Symbol
|
76
|
-
layout_registry[
|
83
|
+
layout_registry[id_or_filename]
|
77
84
|
when String
|
78
|
-
prepare_layout(
|
85
|
+
prepare_layout(id_or_filename)
|
79
86
|
else
|
80
87
|
raise ArgumentError, 'Invalid argument for layout.'
|
81
88
|
end
|
89
|
+
@default_layout = layout unless @default_layout
|
90
|
+
layout
|
82
91
|
end
|
83
|
-
|
92
|
+
|
84
93
|
private
|
85
|
-
|
94
|
+
|
86
95
|
def insert_page(new_page)
|
87
96
|
@pages << new_page
|
88
|
-
|
97
|
+
|
89
98
|
if new_page.count?
|
90
99
|
@page_count += 1
|
91
100
|
new_page.no = @page_count
|
92
101
|
end
|
93
|
-
|
94
|
-
# But do not dispatch if page is blank-page.
|
102
|
+
|
95
103
|
unless new_page.blank?
|
104
|
+
# [DEPRECATION] Please use #on_page_create callback instead.
|
96
105
|
events.dispatch(Report::Events::Event.new(:page_create,
|
97
106
|
@report,
|
98
107
|
new_page))
|
108
|
+
@page_create_handler.call(new_page) if @page_create_handler
|
99
109
|
end
|
100
110
|
@page = new_page
|
101
111
|
end
|
102
|
-
|
103
|
-
# @param (see
|
112
|
+
|
113
|
+
# @param (see Thinreports::Report::Page#finalize)
|
104
114
|
def finalize_current_page(options = {})
|
105
|
-
page.finalize(options) unless page.blank?
|
115
|
+
page.finalize(options) unless page.nil? || page.blank?
|
106
116
|
end
|
107
|
-
|
117
|
+
|
108
118
|
def prepare_layout(layout)
|
109
119
|
return nil if layout.nil?
|
110
|
-
|
120
|
+
|
111
121
|
case layout
|
112
122
|
when String
|
113
123
|
init_layout(layout)
|
114
124
|
# @note Currently not used. Since 0.6.0?
|
115
|
-
when
|
125
|
+
when Thinreports::Layout::Base
|
116
126
|
layout
|
117
127
|
else
|
118
128
|
raise ArgumentError, 'Invalid argument for layout.'
|
119
129
|
end
|
120
130
|
end
|
121
|
-
|
131
|
+
|
122
132
|
def init_layout(filename, id = nil)
|
123
|
-
|
133
|
+
Thinreports::Layout.new(filename, id: id)
|
124
134
|
end
|
125
135
|
end
|
126
|
-
|
136
|
+
|
127
137
|
end
|
128
138
|
end
|
@@ -1,91 +1,101 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
4
|
-
module
|
5
|
-
|
3
|
+
module Thinreports
|
4
|
+
module Report
|
5
|
+
|
6
6
|
class BlankPage
|
7
|
+
# @example
|
8
|
+
# 3.times do
|
9
|
+
# page = report.start_new_page
|
10
|
+
# puts page.no
|
11
|
+
# end
|
12
|
+
# # => 1, 2, 3
|
7
13
|
# @return [Integer]
|
8
14
|
attr_accessor :no
|
9
|
-
|
15
|
+
|
10
16
|
# @param [Boolean] count (nil)
|
11
17
|
def initialize(count = nil)
|
12
18
|
@count = count.nil? ? true : count
|
13
19
|
end
|
14
|
-
|
20
|
+
|
21
|
+
# @example
|
22
|
+
# page = report.start_new_page
|
23
|
+
# page.count? # => true
|
24
|
+
#
|
25
|
+
# page = report.start_new_page count: false
|
26
|
+
# page.count? # => false
|
15
27
|
# @return [Boolean]
|
16
28
|
def count?
|
17
29
|
@count
|
18
30
|
end
|
19
|
-
|
31
|
+
|
20
32
|
# @return [Boolean] (true)
|
21
33
|
def blank?
|
22
34
|
true
|
23
35
|
end
|
24
36
|
end
|
25
|
-
|
37
|
+
|
26
38
|
class Page < BlankPage
|
27
39
|
include Core::Shape::Manager::Target
|
28
|
-
|
29
|
-
# @return [
|
30
|
-
# @private
|
40
|
+
|
41
|
+
# @return [Thinreports::Report::Base]
|
31
42
|
attr_reader :report
|
32
|
-
|
33
|
-
# @return [
|
43
|
+
|
44
|
+
# @return [Thinreports::Layout::Base]
|
34
45
|
attr_reader :layout
|
35
|
-
|
36
|
-
# @param [
|
37
|
-
# @param [
|
38
|
-
|
39
|
-
|
40
|
-
|
46
|
+
|
47
|
+
# @param [Thinreports::Report::Base] report
|
48
|
+
# @param [Thinreports::Layout::Base] layout
|
49
|
+
# @param [Hash] options ({})
|
50
|
+
# @option options [Boolean] :count (true)
|
51
|
+
def initialize(report, layout, options = {})
|
52
|
+
super(options.key?(:count) ? options[:count] : true)
|
53
|
+
|
41
54
|
@report = report
|
42
55
|
@layout = layout
|
43
56
|
@finalized = false
|
44
|
-
|
57
|
+
|
45
58
|
initialize_manager(layout.format) do |f|
|
46
59
|
Core::Shape::Interface(self, f)
|
47
60
|
end
|
48
61
|
end
|
49
|
-
|
62
|
+
|
50
63
|
# @return [Boolean] (false)
|
51
64
|
def blank?
|
52
65
|
false
|
53
66
|
end
|
54
|
-
|
55
|
-
# @private
|
67
|
+
|
56
68
|
def copy
|
57
|
-
new_page = self.class.new(report, layout)
|
58
|
-
|
69
|
+
new_page = self.class.new(report, layout, count: count?)
|
70
|
+
|
59
71
|
manager.shapes.each do |id, shape|
|
60
72
|
new_shape = shape.copy(new_page)
|
61
73
|
new_page.manager.shapes[id] = new_shape
|
62
|
-
|
74
|
+
|
63
75
|
if new_shape.internal.type_of?(:list)
|
64
76
|
new_page.manager.lists[id] = new_shape
|
65
77
|
end
|
66
78
|
end
|
67
79
|
new_page
|
68
80
|
end
|
69
|
-
|
81
|
+
|
70
82
|
# @param [Hash] options
|
71
83
|
# @option options [:create, :copy] :at (:create)
|
72
|
-
# @private
|
73
84
|
def finalize(options = {})
|
74
85
|
at = options[:at] || :create
|
75
|
-
|
86
|
+
|
76
87
|
# For list shapes.
|
77
88
|
if at == :create
|
78
89
|
manager.lists.values.each {|list| list.manager.finalize }
|
79
90
|
end
|
80
|
-
|
91
|
+
|
81
92
|
@finalized = true
|
82
93
|
end
|
83
|
-
|
84
|
-
# @private
|
94
|
+
|
85
95
|
def finalized?
|
86
96
|
@finalized
|
87
97
|
end
|
88
98
|
end
|
89
|
-
|
99
|
+
|
90
100
|
end
|
91
101
|
end
|
data/lib/thinreports/report.rb
CHANGED
@@ -1,31 +1,27 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
4
|
-
|
3
|
+
module Thinreports
|
4
|
+
|
5
5
|
module Report
|
6
|
-
# @see
|
6
|
+
# @see Thinreports::Report::Base#initialize
|
7
7
|
def self.new(*args)
|
8
8
|
Base.new(*args)
|
9
9
|
end
|
10
|
-
|
11
|
-
# @see
|
10
|
+
|
11
|
+
# @see Thinreports::Report::Base#create
|
12
12
|
def self.create(*args, &block)
|
13
13
|
Base.create(*args, &block)
|
14
14
|
end
|
15
|
-
|
16
|
-
# @see
|
15
|
+
|
16
|
+
# @see Thinreports::Report::Base#generate
|
17
17
|
def self.generate(*args, &block)
|
18
18
|
Base.generate(*args, &block)
|
19
19
|
end
|
20
|
-
|
21
|
-
# @see ThinReports::Report::Base#generate_file
|
22
|
-
def self.generate_file(*args, &block)
|
23
|
-
Base.generate_file(*args, &block)
|
24
|
-
end
|
25
20
|
end
|
26
|
-
|
21
|
+
|
27
22
|
end
|
28
23
|
|
29
24
|
require 'thinreports/report/base'
|
30
25
|
require 'thinreports/report/internal'
|
31
|
-
require 'thinreports/report/events'
|
26
|
+
require 'thinreports/report/events'
|
27
|
+
require 'thinreports/report/page'
|