thinreports 0.7.7 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -6
- data/.travis.yml +4 -10
- data/CHANGELOG.md +220 -0
- data/Gemfile +3 -3
- 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/{test/case → examples}/dynamic_image/img200x100.png +0 -0
- data/{test/case → examples}/dynamic_image/img50x50.png +0 -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/{test/case → examples}/dynamic_style/image.png +0 -0
- data/examples/eudc/eudc.rb +20 -0
- data/examples/eudc/eudc.tlf +1 -0
- data/{test/case → examples}/eudc/eudc.ttf +0 -0
- data/{test/case → examples}/helper.rb +14 -12
- 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/{test/case → examples}/list_manual_generation/list_manual_generation.rb +4 -4
- data/examples/list_manual_generation/list_manual_generation.tlf +1 -0
- data/{test/case → examples}/list_page_number/list_page_number.rb +3 -3
- 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/{test/case → examples}/single_line_tblock/single_line_tblock.rb +2 -2
- 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/{test/case → examples}/typeB_page_size/typeB_page_size.rb +3 -3
- data/examples/word_wrap/word_wrap.rb +26 -0
- data/examples/word_wrap/word_wrap.tlf +1 -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
- data/lib/thinreports.rb +14 -2
- 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 -20
- data/lib/thinreports/core/format/builder.rb +14 -22
- data/lib/thinreports/core/shape.rb +9 -13
- data/lib/thinreports/core/shape/base.rb +4 -5
- 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/basic.rb +1 -1
- 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 +4 -5
- data/lib/thinreports/core/shape/image_block.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/list.rb +1 -1
- data/lib/thinreports/core/shape/list/configuration.rb +30 -15
- 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 +128 -95
- data/lib/thinreports/core/shape/list/page.rb +54 -50
- data/lib/thinreports/core/shape/list/page_state.rb +15 -16
- 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/manager.rb +1 -1
- data/lib/thinreports/core/shape/manager/format.rb +10 -11
- data/lib/thinreports/core/shape/manager/internal.rb +21 -20
- data/lib/thinreports/core/shape/manager/target.rb +63 -34
- data/lib/thinreports/core/shape/page_number.rb +1 -1
- data/lib/thinreports/core/shape/page_number/format.rb +3 -3
- data/lib/thinreports/core/shape/page_number/interface.rb +2 -2
- data/lib/thinreports/core/shape/page_number/internal.rb +3 -3
- data/lib/thinreports/core/shape/style.rb +1 -1
- 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 +36 -30
- data/lib/thinreports/core/shape/text.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_block.rb +1 -1
- data/lib/thinreports/core/shape/text_block/format.rb +17 -18
- data/lib/thinreports/core/shape/text_block/formatter.rb +7 -8
- 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/interface.rb +2 -2
- data/lib/thinreports/core/shape/text_block/internal.rb +19 -20
- data/lib/thinreports/core/utils.rb +33 -32
- data/lib/thinreports/generator.rb +6 -8
- data/lib/thinreports/generator/base.rb +15 -24
- data/lib/thinreports/generator/configuration.rb +10 -9
- data/lib/thinreports/generator/pdf.rb +27 -30
- data/lib/thinreports/generator/pdf/configuration.rb +11 -6
- data/lib/thinreports/generator/pdf/document.rb +28 -28
- data/lib/thinreports/generator/pdf/document/draw_shape.rb +30 -31
- data/lib/thinreports/generator/pdf/document/font.rb +53 -44
- data/lib/thinreports/generator/pdf/document/graphics.rb +8 -9
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +25 -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 +40 -41
- data/lib/thinreports/generator/pdf/document/page.rb +20 -21
- 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/drawer/base.rb +13 -14
- data/lib/thinreports/generator/pdf/drawer/list.rb +13 -14
- data/lib/thinreports/generator/pdf/drawer/list_section.rb +13 -14
- data/lib/thinreports/generator/pdf/drawer/page.rb +16 -17
- data/lib/thinreports/generator/pdf/prawn_ext.rb +17 -33
- data/lib/thinreports/layout.rb +2 -2
- data/lib/thinreports/layout/base.rb +22 -36
- data/lib/thinreports/layout/configuration.rb +11 -9
- data/lib/thinreports/layout/format.rb +26 -27
- data/lib/thinreports/layout/version.rb +8 -9
- data/lib/thinreports/report.rb +10 -14
- data/lib/thinreports/report/base.rb +104 -126
- data/lib/thinreports/report/events.rb +5 -5
- data/lib/thinreports/report/internal.rb +41 -33
- data/lib/thinreports/{core → report}/page.rb +38 -30
- data/lib/thinreports/version.rb +2 -3
- 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/{unit/tmp → tmp}/.gitkeep +0 -0
- data/test/unit/core/format/test_base.rb +14 -14
- data/test/unit/core/format/test_builder.rb +19 -23
- 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 +23 -20
- 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 +45 -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 +5 -5
- data/test/unit/core/shape/list/test_page.rb +80 -22
- data/test/unit/core/shape/list/test_page_state.rb +12 -12
- 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 +4 -4
- data/test/unit/core/shape/page_number/test_interface.rb +11 -8
- data/test/unit/core/shape/page_number/test_internal.rb +5 -5
- 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 +18 -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 +4 -4
- 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 +8 -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 +5 -5
- data/test/unit/core/test_shape.rb +6 -6
- data/test/unit/core/test_utils.rb +68 -0
- data/test/unit/generator/pdf/document/graphics/test_attributes.rb +4 -4
- data/test/unit/generator/pdf/document/graphics/test_text.rb +60 -53
- data/test/unit/generator/pdf/document/test_draw_shape.rb +9 -7
- 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 +44 -45
- 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 +17 -14
- 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 +134 -213
- data/test/unit/report/test_events.rb +4 -4
- data/test/unit/report/test_internal.rb +84 -86
- 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 +18 -22
- metadata +101 -200
- data/LICENSE +0 -1
- data/README.rdoc +0 -166
- data/doc/yardoc_templates/default/layout/html/footer.erb +0 -10
- data/lib/thinreports/core.rb +0 -20
- data/lib/thinreports/core/ext.rb +0 -5
- 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/format.rb +0 -14
- data/lib/thinreports/core/ordered_hash.rb +0 -39
- data/lib/thinreports/generator/pdf/drawer.rb +0 -16
- data/tasks/doc.rake +0 -12
- 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 -8
- 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/hidden_shapes/hidden_shapes.rb +0 -9
- 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_manual_generation/list_manual_generation.tlf +0 -1
- data/test/case/list_page_number/list_page_number.tlf +0 -1
- data/test/case/page_number/page_number.rb +0 -33
- data/test/case/page_number/page_number.tlf +0 -1
- data/test/case/password_setting/password_setting.rb +0 -10
- data/test/case/password_setting/password_setting.tlf +0 -1
- 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 -8
- data/test/case/text_align/text_align.tlf +0 -1
- data/test/case/typeB_page_size/B4_ISO.tlf +0 -1
- data/test/case/typeB_page_size/B4_JIS.tlf +0 -1
- data/test/case/word_wrap/word_wrap.rb +0 -26
- data/test/case/word_wrap/word_wrap.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 -87
@@ -1,27 +1,29 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module Thinreports
|
4
4
|
module Layout
|
5
|
-
|
5
|
+
|
6
|
+
# @deprecated This class will be removed in the next major version.
|
6
7
|
class Configuration
|
7
8
|
include Core::Shape::Manager::Target
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
# @param [ThinReports::Layout::Base] layout
|
9
|
+
|
10
|
+
# @param [Thinreports::Layout::Base] layout
|
12
11
|
def initialize(layout)
|
13
12
|
initialize_manager(layout.format) do |f|
|
14
13
|
Core::Shape::Configuration(f.type).new
|
15
14
|
end
|
16
15
|
end
|
17
|
-
|
16
|
+
|
18
17
|
# @param [String, Symbol] shape_id
|
19
18
|
# @return [Object, nil]
|
20
|
-
# @private
|
21
19
|
def activate(shape_id)
|
22
20
|
(config = manager.shapes[shape_id.to_sym]) && config.copy
|
23
21
|
end
|
22
|
+
|
23
|
+
def values
|
24
|
+
raise NoMethodError
|
25
|
+
end
|
24
26
|
end
|
25
|
-
|
27
|
+
|
26
28
|
end
|
27
29
|
end
|
@@ -2,40 +2,39 @@
|
|
2
2
|
|
3
3
|
require 'digest/sha1'
|
4
4
|
|
5
|
-
module
|
5
|
+
module Thinreports
|
6
6
|
module Layout
|
7
|
-
|
8
|
-
# @private
|
7
|
+
|
9
8
|
class Format < Core::Shape::Manager::Format
|
10
|
-
config_reader :
|
11
|
-
config_reader :
|
12
|
-
config_reader :
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
16
|
-
|
17
|
-
config_checker 'user', :
|
18
|
-
|
9
|
+
config_reader last_version: %w( version )
|
10
|
+
config_reader report_title: %w( config title )
|
11
|
+
config_reader page_paper_type: %w( config page paper-type ),
|
12
|
+
page_width: %w( config page width ),
|
13
|
+
page_height: %w( config page height ),
|
14
|
+
page_orientation: %w( config page orientation )
|
15
|
+
|
16
|
+
config_checker 'user', user_paper_type: %w( config page paper-type )
|
17
|
+
|
19
18
|
class << self
|
20
|
-
|
19
|
+
|
21
20
|
private
|
22
|
-
|
21
|
+
|
23
22
|
# @param [String] filename
|
24
23
|
# @param [Hash] options
|
25
24
|
# @option options [Boolean] :force (false)
|
26
25
|
def build_internal(filename, options = {})
|
27
26
|
build_once(filename, options[:force]) do |content, id|
|
28
27
|
raw_format = parse_json(content)
|
29
|
-
|
28
|
+
|
30
29
|
# Check the compatibility of specified layout file.
|
31
|
-
unless
|
30
|
+
unless Thinreports::Layout::Version.compatible?(raw_format['version'])
|
32
31
|
info = [filename, raw_format['version'],
|
33
|
-
|
34
|
-
raise
|
32
|
+
Thinreports::Layout::Version.inspect_required_rules]
|
33
|
+
raise Thinreports::Errors::IncompatibleLayoutFormat.new(*info)
|
35
34
|
end
|
36
|
-
|
35
|
+
|
37
36
|
compact_format!(raw_format)
|
38
|
-
|
37
|
+
|
39
38
|
# Build and initialize format.
|
40
39
|
new(raw_format, id) do |f|
|
41
40
|
build_layout(f) do |type, shape_format|
|
@@ -45,17 +44,17 @@ module ThinReports
|
|
45
44
|
end
|
46
45
|
end
|
47
46
|
end
|
48
|
-
|
47
|
+
|
49
48
|
# @param [Hash] raw_format A parsed json.
|
50
49
|
def compact_format!(raw_format)
|
51
50
|
%w( finger-print state version ).each {|attr| raw_format.delete(attr) }
|
52
51
|
end
|
53
|
-
|
52
|
+
|
54
53
|
# @param [String] filename
|
55
54
|
# @param [Boolean] force (false)
|
56
55
|
def build_once(filename, force = false, &block)
|
57
56
|
content = read_format_file(filename)
|
58
|
-
|
57
|
+
|
59
58
|
if force
|
60
59
|
block.call(content, nil)
|
61
60
|
else
|
@@ -63,19 +62,19 @@ module ThinReports
|
|
63
62
|
built_format_registry[id] ||= block.call(content, id)
|
64
63
|
end
|
65
64
|
end
|
66
|
-
|
65
|
+
|
67
66
|
# @param [String] filename
|
68
67
|
# @return [String]
|
69
68
|
def read_format_file(filename)
|
70
69
|
File.open(filename, 'r:UTF-8') {|f| f.read }
|
71
70
|
end
|
72
|
-
|
71
|
+
|
73
72
|
# @return [Hash]
|
74
73
|
def built_format_registry
|
75
74
|
@built_format_registry ||= {}
|
76
|
-
end
|
75
|
+
end
|
77
76
|
end
|
78
77
|
end
|
79
|
-
|
78
|
+
|
80
79
|
end
|
81
80
|
end
|
@@ -1,18 +1,17 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module Thinreports
|
4
4
|
module Layout
|
5
|
-
|
6
|
-
# @private
|
5
|
+
|
7
6
|
module Version
|
8
|
-
REQUIRED_RULES = ['>= 0.
|
9
|
-
|
7
|
+
REQUIRED_RULES = ['>= 0.7.7.0', '< 1.0.0']
|
8
|
+
|
10
9
|
# @param [String] version
|
11
10
|
# @return [Boolean]
|
12
11
|
def self.compatible?(version)
|
13
12
|
compare(version, *REQUIRED_RULES)
|
14
13
|
end
|
15
|
-
|
14
|
+
|
16
15
|
# @param [String] base
|
17
16
|
# @param [Array<String>] rules
|
18
17
|
# @return [Boolean]
|
@@ -22,12 +21,12 @@ module ThinReports
|
|
22
21
|
comparable_version(base).send(op.to_sym, comparable_version(ver))
|
23
22
|
end
|
24
23
|
end
|
25
|
-
|
24
|
+
|
26
25
|
# @return [String]
|
27
26
|
def self.inspect_required_rules
|
28
27
|
'(' + REQUIRED_RULES.join(' and ') + ')'
|
29
28
|
end
|
30
|
-
|
29
|
+
|
31
30
|
# @param [String] version
|
32
31
|
# @return [String]
|
33
32
|
def self.comparable_version(version)
|
@@ -38,6 +37,6 @@ module ThinReports
|
|
38
37
|
end
|
39
38
|
end
|
40
39
|
end
|
41
|
-
|
40
|
+
|
42
41
|
end
|
43
42
|
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'
|
@@ -1,33 +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
|
-
attr_reader :internal
|
7
|
+
extend Forwardable
|
8
|
+
include Utils
|
10
9
|
|
11
|
-
# @return [Integer]
|
12
|
-
attr_reader :start_page_number
|
13
|
-
|
14
10
|
class << self
|
15
11
|
# @param options (see #initialize)
|
16
12
|
# @option options (see #initialize)
|
17
13
|
# @yield [report]
|
18
|
-
# @yieldparam [
|
19
|
-
# @return [
|
14
|
+
# @yieldparam [Thinreports::Report::Base] report
|
15
|
+
# @return [Thinreports::Report::Base]
|
20
16
|
def create(options = {}, &block)
|
21
17
|
unless block_given?
|
22
18
|
raise ArgumentError, '#create requires a block'
|
23
19
|
end
|
24
20
|
report = new(options)
|
25
|
-
|
21
|
+
call_block_in(report, &block)
|
26
22
|
report.finalize
|
27
|
-
|
23
|
+
|
28
24
|
report
|
29
25
|
end
|
30
|
-
|
26
|
+
|
31
27
|
# @overload generate(type, options = {}, &block)
|
32
28
|
# @param [Symbol] type
|
33
29
|
# @param [Hash] options
|
@@ -42,41 +38,22 @@ module ThinReports
|
|
42
38
|
# @return [String]
|
43
39
|
def generate(*args, &block)
|
44
40
|
raise ArgumentError, '#generate requires a block' unless block_given?
|
45
|
-
|
41
|
+
|
46
42
|
report_opts, generator_opts = extract_options!(args)
|
47
|
-
|
43
|
+
|
48
44
|
report = create(report_opts, &block)
|
49
45
|
report.generate(*args.push(generator_opts))
|
50
46
|
end
|
51
|
-
|
52
|
-
# @overload generate_file(type, filename, options = {}, &block)
|
53
|
-
# @overload generate_file(filename, options = {}, &block)
|
54
|
-
# @param filename (see #generate_file)
|
55
|
-
# @yield (see .create)
|
56
|
-
# @yieldparam (see .create)
|
57
|
-
# @see .generate
|
58
|
-
# @deprecated Please use the #generate method with :filename option instead.
|
59
|
-
# @return [void]
|
60
|
-
def generate_file(*args, &block)
|
61
|
-
raise ArgumentError, '#generate_file requires a block' unless block_given?
|
62
47
|
|
63
|
-
report_opts, generator_opts = extract_options!(args)
|
64
|
-
|
65
|
-
report = create(report_opts, &block)
|
66
|
-
report.generate_file(*args.push(generator_opts))
|
67
|
-
end
|
68
|
-
|
69
|
-
private
|
70
|
-
|
71
48
|
# @param [Array] args
|
72
49
|
# @return [Array<Hash>]
|
73
50
|
def extract_options!(args)
|
74
51
|
if args.last.is_a?(::Hash)
|
75
52
|
options = args.pop
|
76
|
-
|
53
|
+
|
77
54
|
generator = options.delete(:generator) || {}
|
78
55
|
report = options.delete(:report) || {}
|
79
|
-
|
56
|
+
|
80
57
|
if options.key?(:layout)
|
81
58
|
report[:layout] = options.delete(:layout)
|
82
59
|
end
|
@@ -86,150 +63,151 @@ module ThinReports
|
|
86
63
|
end
|
87
64
|
end
|
88
65
|
end
|
89
|
-
|
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
|
+
|
90
85
|
# @param [Hash] options
|
91
86
|
# @option options [String, nil] :layout (nil)
|
92
87
|
def initialize(options = {})
|
93
88
|
@internal = Report::Internal.new(self, options)
|
94
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
|
95
103
|
end
|
96
104
|
|
97
105
|
# @param [Integer] page_number
|
98
106
|
def start_page_number_from(page_number)
|
99
107
|
@start_page_number = page_number
|
100
108
|
end
|
101
|
-
|
102
|
-
# @param [String] layout
|
109
|
+
|
110
|
+
# @param [String] layout filename of layout file
|
103
111
|
# @param [Hash] options
|
104
112
|
# @option options [Boolean] :default (true)
|
105
113
|
# @option options [Symbol] :id (nil)
|
106
114
|
# @yield [config]
|
107
|
-
# @yieldparam [
|
108
|
-
# @
|
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
|
109
120
|
def use_layout(layout, options = {}, &block)
|
110
121
|
internal.register_layout(layout, options, &block)
|
111
122
|
end
|
112
|
-
|
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'
|
113
137
|
# @param [Hash] options
|
114
138
|
# @option options [String, Symbol] :layout (nil)
|
115
139
|
# @option options [Boolean] :count (true)
|
116
140
|
# @yield [page]
|
117
|
-
# @yieldparam [
|
118
|
-
# @return [
|
141
|
+
# @yieldparam [Thinreports::Report::Page] page
|
142
|
+
# @return [Thinreports::Report::Page]
|
119
143
|
def start_new_page(options = {}, &block)
|
120
144
|
unless layout = internal.load_layout(options.delete(:layout))
|
121
|
-
raise
|
145
|
+
raise Thinreports::Errors::NoRegisteredLayoutFound
|
122
146
|
end
|
123
|
-
|
124
|
-
page = internal.add_page(layout.
|
125
|
-
|
147
|
+
|
148
|
+
page = internal.add_page(layout.new_page(self, options))
|
149
|
+
call_block_in(page, &block)
|
126
150
|
end
|
127
|
-
|
151
|
+
|
128
152
|
# @param [Hash] options
|
129
153
|
# @option options [Boolean] :count (true)
|
130
|
-
# @return [
|
154
|
+
# @return [Thinreports::Report::BlankPage]
|
131
155
|
def add_blank_page(options = {})
|
132
|
-
internal.add_page(
|
156
|
+
internal.add_page(Report::BlankPage.new(options[:count]))
|
133
157
|
end
|
134
158
|
alias_method :blank_page, :add_blank_page
|
135
|
-
|
136
|
-
# @param [Symbol, nil] id
|
137
|
-
#
|
138
|
-
# @return [ThinReports::Layout::Base]
|
159
|
+
|
160
|
+
# @param [Symbol, nil] id
|
161
|
+
# @return [Thinreports::Layout::Base]
|
139
162
|
def layout(id = nil)
|
140
163
|
if id
|
141
164
|
internal.layout_registry[id] ||
|
142
|
-
raise(
|
165
|
+
raise(Thinreports::Errors::UnknownLayoutId)
|
143
166
|
else
|
144
167
|
internal.default_layout
|
145
168
|
end
|
146
169
|
end
|
147
|
-
|
148
|
-
# @return [ThinReports::Layout::Base]
|
149
|
-
def default_layout
|
150
|
-
internal.default_layout
|
151
|
-
end
|
152
|
-
|
153
|
-
# @overload generate(type, options = {})
|
154
|
-
# Specify the generator type.
|
155
|
-
# @param [Symbol] type
|
156
|
-
# @return [String]
|
170
|
+
|
157
171
|
# @overload generate(options = {})
|
158
|
-
# Using the default generator type.
|
159
172
|
# @param [Hash] options ({})
|
160
173
|
# @return [String]
|
161
|
-
# @
|
162
|
-
#
|
163
|
-
#
|
164
|
-
#
|
165
|
-
#
|
166
|
-
#
|
167
|
-
#
|
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')
|
168
182
|
def generate(*args)
|
169
183
|
options = args.last.is_a?(::Hash) ? args.pop : {}
|
170
|
-
type = args.first ||
|
184
|
+
type = args.first || Thinreports.config.generator.default
|
171
185
|
filename = options.delete(:filename)
|
172
|
-
generator =
|
186
|
+
generator = Thinreports::Generator.new(type, self, options)
|
173
187
|
|
174
|
-
|
175
|
-
generator.generate_file(filename)
|
176
|
-
else
|
177
|
-
generator.generate
|
178
|
-
end
|
188
|
+
generator.generate(filename)
|
179
189
|
end
|
180
|
-
|
181
|
-
# @overload generate_file(type, filename, options = {})
|
182
|
-
# @param type (#generate)
|
183
|
-
# @return [void]
|
184
|
-
# @overload generate_file(filename, options = {})
|
185
|
-
# @param [String] filename
|
186
|
-
# @param options (see #generate)
|
187
|
-
# @return [void]
|
188
|
-
# @deprecated Please use the #generate method with :filename option instead.
|
189
|
-
def generate_file(*args)
|
190
|
-
warn '[DEPRECATION] The #generate_file method is deprecated. ' +
|
191
|
-
'Please use the #generate(:filename => "filename") instead.'
|
192
190
|
|
193
|
-
|
194
|
-
args.unshift(ThinReports.config.generator.default) if args.size == 1
|
195
|
-
type, filename = args
|
196
|
-
|
197
|
-
generate(type, options.merge(:filename => filename))
|
198
|
-
end
|
199
|
-
|
200
|
-
# @see ThinReports::Core::Shape::Manager::Target#list
|
191
|
+
# @see Thinreports::Core::Shape::Manager::Target#list
|
201
192
|
def list(id = nil, &block)
|
202
193
|
start_new_page if page.nil? || page.finalized?
|
203
194
|
page.list(id, &block)
|
204
195
|
end
|
205
|
-
|
206
|
-
# @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.
|
207
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.'
|
208
206
|
internal.events
|
209
207
|
end
|
210
|
-
|
211
|
-
|
212
|
-
def page
|
213
|
-
internal.page
|
214
|
-
end
|
215
|
-
|
216
|
-
# @return [Integer]
|
217
|
-
def page_count
|
218
|
-
internal.page_count
|
219
|
-
end
|
220
|
-
|
221
|
-
# @return [void]
|
222
|
-
# @private
|
223
|
-
def finalize
|
224
|
-
internal.finalize
|
225
|
-
end
|
226
|
-
|
227
|
-
# @return [Boolean]
|
228
|
-
# @private
|
229
|
-
def finalized?
|
230
|
-
internal.finalized?
|
231
|
-
end
|
208
|
+
|
209
|
+
def_delegators :internal, :finalize, :finalized?
|
232
210
|
end
|
233
|
-
|
211
|
+
|
234
212
|
end
|
235
213
|
end
|