thinreports 0.9.1 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +41 -0
- data/.travis.yml +4 -6
- data/CHANGELOG.md +21 -2
- data/Gemfile +2 -4
- data/README.md +4 -5
- data/Rakefile +7 -8
- data/examples/character_spacing/character_spacing.rb +1 -1
- data/examples/dynamic_image/dynamic_image.rb +3 -3
- data/examples/dynamic_style/dynamic_style.rb +1 -1
- data/examples/eudc/eudc.rb +1 -1
- data/examples/helper.rb +2 -2
- data/examples/hidden_shapes/hidden_shapes.rb +1 -1
- data/examples/list_events/list_events.rb +1 -1
- data/examples/list_manual_generation/list_manual_generation.rb +1 -1
- data/examples/list_page_number/list_page_number.rb +1 -1
- data/examples/page_number/page_number.rb +1 -1
- data/examples/palleted_png/palleted_png.rb +1 -3
- data/examples/password_setting/password_setting.rb +1 -1
- data/examples/report_callbacks/report_callbacks.rb +1 -1
- data/examples/single_line_tblock/single_line_tblock.rb +1 -1
- data/examples/tblock_overflow/tblock_overflow.rb +1 -1
- data/examples/tblock_styles/tblock_styles.rb +1 -1
- data/examples/text_align/text_align.rb +1 -1
- data/examples/typeB_page_size/typeB_page_size.rb +1 -1
- data/examples/word_wrap/word_wrap.rb +1 -1
- data/lib/thinreports.rb +16 -15
- data/lib/thinreports/config.rb +2 -24
- data/lib/thinreports/core/errors.rb +6 -17
- data/lib/thinreports/core/format/base.rb +62 -61
- data/lib/thinreports/core/shape.rb +13 -14
- data/lib/thinreports/core/shape/base.rb +3 -12
- data/lib/thinreports/core/shape/base/interface.rb +35 -32
- data/lib/thinreports/core/shape/base/internal.rb +45 -43
- data/lib/thinreports/core/shape/basic.rb +12 -12
- data/lib/thinreports/core/shape/basic/block_format.rb +8 -6
- data/lib/thinreports/core/shape/basic/block_interface.rb +24 -22
- data/lib/thinreports/core/shape/basic/block_internal.rb +28 -26
- data/lib/thinreports/core/shape/basic/format.rb +11 -9
- data/lib/thinreports/core/shape/basic/interface.rb +79 -77
- data/lib/thinreports/core/shape/basic/internal.rb +17 -14
- data/lib/thinreports/core/shape/image_block.rb +9 -9
- data/lib/thinreports/core/shape/image_block/format.rb +7 -5
- data/lib/thinreports/core/shape/image_block/interface.rb +15 -13
- data/lib/thinreports/core/shape/image_block/internal.rb +10 -8
- data/lib/thinreports/core/shape/list.rb +13 -13
- data/lib/thinreports/core/shape/list/format.rb +83 -77
- data/lib/thinreports/core/shape/list/manager.rb +182 -176
- data/lib/thinreports/core/shape/list/page.rb +94 -93
- data/lib/thinreports/core/shape/list/page_state.rb +42 -40
- data/lib/thinreports/core/shape/list/section_format.rb +28 -26
- data/lib/thinreports/core/shape/list/section_interface.rb +42 -40
- data/lib/thinreports/core/shape/list/section_internal.rb +21 -19
- data/lib/thinreports/core/shape/manager.rb +4 -13
- data/lib/thinreports/core/shape/manager/format.rb +21 -19
- data/lib/thinreports/core/shape/manager/internal.rb +88 -84
- data/lib/thinreports/core/shape/manager/target.rb +93 -95
- data/lib/thinreports/core/shape/page_number.rb +9 -9
- data/lib/thinreports/core/shape/page_number/format.rb +20 -18
- data/lib/thinreports/core/shape/page_number/interface.rb +20 -18
- data/lib/thinreports/core/shape/page_number/internal.rb +47 -44
- data/lib/thinreports/core/shape/style.rb +5 -14
- data/lib/thinreports/core/shape/style/base.rb +121 -120
- data/lib/thinreports/core/shape/style/basic.rb +12 -10
- data/lib/thinreports/core/shape/style/graphic.rb +35 -33
- data/lib/thinreports/core/shape/style/text.rb +113 -107
- data/lib/thinreports/core/shape/text.rb +9 -9
- data/lib/thinreports/core/shape/text/format.rb +10 -9
- data/lib/thinreports/core/shape/text/interface.rb +13 -11
- data/lib/thinreports/core/shape/text/internal.rb +14 -12
- data/lib/thinreports/core/shape/text_block.rb +10 -10
- data/lib/thinreports/core/shape/text_block/format.rb +35 -33
- data/lib/thinreports/core/shape/text_block/formatter.rb +26 -24
- data/lib/thinreports/core/shape/text_block/formatter/basic.rb +25 -25
- data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +15 -12
- data/lib/thinreports/core/shape/text_block/formatter/number.rb +45 -39
- data/lib/thinreports/core/shape/text_block/formatter/padding.rb +17 -14
- data/lib/thinreports/core/shape/text_block/interface.rb +25 -23
- data/lib/thinreports/core/shape/text_block/internal.rb +68 -68
- data/lib/thinreports/core/utils.rb +4 -3
- data/lib/thinreports/generator/pdf.rb +24 -25
- data/lib/thinreports/generator/pdf/document.rb +109 -110
- data/lib/thinreports/generator/pdf/document/draw_shape.rb +58 -51
- data/lib/thinreports/generator/pdf/document/draw_template_items.rb +51 -47
- data/lib/thinreports/generator/pdf/document/font.rb +62 -59
- data/lib/thinreports/generator/pdf/document/graphics.rb +32 -33
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +122 -121
- data/lib/thinreports/generator/pdf/document/graphics/basic.rb +113 -114
- data/lib/thinreports/generator/pdf/document/graphics/image.rb +58 -150
- data/lib/thinreports/generator/pdf/document/graphics/text.rb +152 -137
- data/lib/thinreports/generator/pdf/document/page.rb +63 -64
- data/lib/thinreports/generator/pdf/document/parse_color.rb +37 -37
- data/lib/thinreports/generator/pdf/drawer/base.rb +41 -41
- data/lib/thinreports/generator/pdf/drawer/list.rb +48 -45
- data/lib/thinreports/generator/pdf/drawer/list_section.rb +42 -40
- data/lib/thinreports/generator/pdf/drawer/page.rb +101 -96
- data/lib/thinreports/generator/pdf/prawn_ext.rb +4 -30
- data/lib/thinreports/generator/pdf/prawn_ext/calc_image_dimensions.rb +34 -0
- data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +29 -0
- data/lib/thinreports/layout.rb +5 -7
- data/lib/thinreports/layout/base.rb +5 -7
- data/lib/thinreports/layout/format.rb +18 -13
- data/lib/thinreports/layout/legacy_schema.rb +18 -10
- data/lib/thinreports/layout/version.rb +22 -25
- data/lib/thinreports/report.rb +4 -6
- data/lib/thinreports/report/base.rb +24 -51
- data/lib/thinreports/report/internal.rb +9 -11
- data/lib/thinreports/report/page.rb +5 -6
- data/lib/thinreports/version.rb +2 -2
- data/test/schema_helper.rb +4 -3
- data/test/test_helper.rb +9 -3
- data/test/unit/core/format/test_base.rb +1 -1
- data/test/unit/core/shape/base/test_internal.rb +1 -1
- data/test/unit/core/shape/basic/test_block_format.rb +1 -1
- data/test/unit/core/shape/basic/test_block_interface.rb +1 -1
- data/test/unit/core/shape/basic/test_block_internal.rb +1 -1
- data/test/unit/core/shape/basic/test_format.rb +1 -1
- data/test/unit/core/shape/basic/test_interface.rb +1 -1
- data/test/unit/core/shape/basic/test_internal.rb +1 -1
- data/test/unit/core/shape/image_block/test_interface.rb +1 -1
- data/test/unit/core/shape/image_block/test_internal.rb +1 -1
- data/test/unit/core/shape/list/test_format.rb +1 -1
- data/test/unit/core/shape/list/test_manager.rb +4 -4
- data/test/unit/core/shape/list/test_page.rb +1 -1
- data/test/unit/core/shape/list/test_page_state.rb +1 -1
- data/test/unit/core/shape/list/test_section_format.rb +1 -1
- data/test/unit/core/shape/list/test_section_interface.rb +2 -2
- data/test/unit/core/shape/list/test_section_internal.rb +1 -1
- data/test/unit/core/shape/manager/test_format.rb +2 -2
- data/test/unit/core/shape/manager/test_internal.rb +3 -3
- data/test/unit/core/shape/manager/test_target.rb +1 -1
- data/test/unit/core/shape/page_number/test_format.rb +1 -1
- data/test/unit/core/shape/page_number/test_interface.rb +1 -1
- data/test/unit/core/shape/page_number/test_internal.rb +1 -1
- data/test/unit/core/shape/styles/test_base.rb +1 -1
- data/test/unit/core/shape/styles/test_basic.rb +1 -1
- data/test/unit/core/shape/styles/test_graphic.rb +1 -1
- data/test/unit/core/shape/styles/test_text.rb +1 -1
- data/test/unit/core/shape/text/test_format.rb +1 -1
- data/test/unit/core/shape/text/test_internal.rb +1 -1
- data/test/unit/core/shape/text_block/formatter/test_basic.rb +1 -1
- data/test/unit/core/shape/text_block/formatter/test_datetime.rb +1 -1
- data/test/unit/core/shape/text_block/formatter/test_number.rb +1 -1
- data/test/unit/core/shape/text_block/formatter/test_padding.rb +2 -2
- data/test/unit/core/shape/text_block/test_format.rb +1 -1
- data/test/unit/core/shape/text_block/test_formatter.rb +1 -1
- data/test/unit/core/shape/text_block/test_interface.rb +1 -1
- data/test/unit/core/shape/text_block/test_internal.rb +3 -3
- data/test/unit/core/test_shape.rb +1 -1
- data/test/unit/core/test_utils.rb +2 -2
- data/test/unit/generator/pdf/document/graphics/test_attributes.rb +1 -1
- data/test/unit/generator/pdf/document/graphics/test_basic.rb +2 -1
- data/test/unit/generator/pdf/document/graphics/test_image.rb +27 -131
- data/test/unit/generator/pdf/document/graphics/test_text.rb +1 -1
- data/test/unit/generator/pdf/document/test_font.rb +2 -2
- data/test/unit/generator/pdf/document/test_graphics.rb +1 -1
- data/test/unit/generator/pdf/document/test_page.rb +7 -7
- data/test/unit/generator/pdf/document/test_parse_color.rb +1 -1
- data/test/unit/generator/pdf/prawn_ext/test_calc_image_dimensions.rb +41 -0
- data/test/unit/generator/pdf/prawn_ext/test_width_of.rb +22 -0
- data/test/unit/generator/pdf/test_document.rb +8 -6
- data/test/unit/generator/test_pdf.rb +12 -10
- data/test/unit/layout/test_base.rb +1 -1
- data/test/unit/layout/test_format.rb +2 -2
- data/test/unit/layout/test_legacy_schema.rb +4 -4
- data/test/unit/layout/test_version.rb +11 -80
- data/test/unit/report/test_base.rb +45 -59
- data/test/unit/report/test_internal.rb +1 -1
- data/test/unit/test_config.rb +1 -16
- data/test/unit/test_layout.rb +1 -1
- data/test/unit/test_report.rb +1 -1
- data/thinreports.gemspec +11 -14
- metadata +42 -103
- data/lib/thinreports/generator.rb +0 -29
- data/lib/thinreports/generator/base.rb +0 -40
- data/lib/thinreports/generator/configuration.rb +0 -31
- data/lib/thinreports/report/events.rb +0 -32
- data/test/unit/generator/test_base.rb +0 -40
- data/test/unit/generator/test_configuration.rb +0 -21
@@ -1,46 +1,48 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
|
-
module Core
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
4
|
+
module Core
|
5
|
+
module Shape
|
6
|
+
module List
|
7
|
+
class PageState < Basic::Internal
|
8
|
+
attr_reader :rows
|
9
|
+
|
10
|
+
attr_accessor :height
|
11
|
+
attr_accessor :header
|
12
|
+
attr_accessor :no
|
13
|
+
attr_accessor :manager
|
14
|
+
|
15
|
+
def initialize(*args)
|
16
|
+
super(*args)
|
17
|
+
|
18
|
+
@rows = []
|
19
|
+
@height = 0
|
20
|
+
@finalized = false
|
21
|
+
|
22
|
+
@header = nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def style
|
26
|
+
@style ||= Style::Basic.new(format)
|
27
|
+
end
|
28
|
+
|
29
|
+
def finalized?
|
30
|
+
@finalized
|
31
|
+
end
|
32
|
+
|
33
|
+
def finalized!
|
34
|
+
@finalized = true
|
35
|
+
end
|
36
|
+
|
37
|
+
def type_of?(type_name)
|
38
|
+
type_name == List::TYPE_NAME
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Alias to List::PageState.
|
43
|
+
# @see Thinreports::Core::Shape::List::PageState
|
44
|
+
List::Internal = List::PageState
|
38
45
|
end
|
39
46
|
end
|
40
|
-
|
41
|
-
# Alias to List::PageState.
|
42
|
-
# @see Thinreports::Core::Shape::List::PageState
|
43
|
-
List::Internal = List::PageState
|
44
|
-
|
45
47
|
end
|
46
48
|
end
|
@@ -1,33 +1,35 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
|
-
module Core
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
4
|
+
module Core
|
5
|
+
module Shape
|
6
|
+
module List
|
7
|
+
class SectionFormat < Shape::Manager::Format
|
8
|
+
config_reader :height
|
9
|
+
config_reader relative_left: %w[translate x],
|
10
|
+
relative_top: %w[translate y]
|
11
|
+
config_reader :style
|
12
|
+
|
13
|
+
# For compatible 0.8.x format API
|
14
|
+
config_checker true, display: %w[enabled]
|
15
|
+
|
16
|
+
def initialize(*)
|
17
|
+
super
|
18
|
+
initialize_items(attributes['items'])
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def initialize_items(item_schemas)
|
24
|
+
item_schemas.each do |item_schema|
|
25
|
+
id, type = item_schema.values_at 'id', 'type'
|
26
|
+
next if id.empty?
|
27
|
+
|
28
|
+
shapes[id.to_sym] = Core::Shape::Format(type).new(item_schema)
|
29
|
+
end
|
30
|
+
end
|
28
31
|
end
|
29
32
|
end
|
30
33
|
end
|
31
|
-
|
32
34
|
end
|
33
35
|
end
|
@@ -1,47 +1,49 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
|
-
module Core
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
4
|
+
module Core
|
5
|
+
module Shape
|
6
|
+
module List
|
7
|
+
class SectionInterface < Base::Interface
|
8
|
+
include Core::Shape::Manager::Target
|
9
|
+
|
10
|
+
undef_method :list
|
11
|
+
internal_delegators :height
|
12
|
+
|
13
|
+
# @param [Thinreports::Core::Shape::List::Page] parent
|
14
|
+
# @param [Thinreports::Core::Shape::List::SectionFormat] format
|
15
|
+
# @param [Symbol] section_name
|
16
|
+
def initialize(parent, format, section_name)
|
17
|
+
super(parent, format)
|
18
|
+
internal.section_name = section_name
|
19
|
+
|
20
|
+
initialize_manager(format) do |f|
|
21
|
+
Core::Shape::Interface(self, f)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# @param [Thinreports::Core::Shape::List::Page] parent
|
26
|
+
# @return [Thinreports::Core::Shape::List::SectionInterface]
|
27
|
+
def copy(parent)
|
28
|
+
new_sec = super
|
29
|
+
new_sec.internal.section_name = internal.section_name
|
30
|
+
|
31
|
+
manager.shapes.each do |id, shape|
|
32
|
+
new_sec.manager.shapes[id] = shape.copy(new_sec)
|
33
|
+
end
|
34
|
+
new_sec
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
# @param parent (see #initialize)
|
40
|
+
# @param format (see #initialize)
|
41
|
+
# @return [Thinreports::Core::Shape::List::SectionInternal]
|
42
|
+
def init_internal(parent, format)
|
43
|
+
List::SectionInternal.new(parent, format)
|
44
|
+
end
|
32
45
|
end
|
33
|
-
new_sec
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
# @param parent (see #initialize)
|
39
|
-
# @param format (see #initialize)
|
40
|
-
# @return [Thinreports::Core::Shape::List::SectionInternal]
|
41
|
-
def init_internal(parent, format)
|
42
|
-
List::SectionInternal.new(parent, format)
|
43
46
|
end
|
44
47
|
end
|
45
|
-
|
46
48
|
end
|
47
49
|
end
|
@@ -1,29 +1,31 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
|
-
module Core
|
4
|
+
module Core
|
5
|
+
module Shape
|
6
|
+
module List
|
7
|
+
class SectionInternal < Base::Internal
|
8
|
+
format_delegators :height,
|
9
|
+
:relative_left
|
5
10
|
|
6
|
-
|
7
|
-
|
8
|
-
:relative_left
|
11
|
+
# @return [Symbol]
|
12
|
+
attr_accessor :section_name
|
9
13
|
|
10
|
-
|
11
|
-
|
14
|
+
def style
|
15
|
+
@style ||= Style::Base.new(format)
|
16
|
+
end
|
12
17
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
# @param [Numeric] ry
|
18
|
-
def move_top_to(ry)
|
19
|
-
states[:relative_top] = ry
|
20
|
-
end
|
18
|
+
# @param [Numeric] ry
|
19
|
+
def move_top_to(ry)
|
20
|
+
states[:relative_top] = ry
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
# @return [Float]
|
24
|
+
def relative_top
|
25
|
+
states[:relative_top] || 0
|
26
|
+
end
|
27
|
+
end
|
25
28
|
end
|
26
29
|
end
|
27
|
-
|
28
30
|
end
|
29
31
|
end
|
@@ -1,14 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
module Manager
|
7
|
-
end
|
8
|
-
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
require 'thinreports/core/shape/manager/format'
|
13
|
-
require 'thinreports/core/shape/manager/target'
|
14
|
-
require 'thinreports/core/shape/manager/internal'
|
3
|
+
require_relative 'manager/format'
|
4
|
+
require_relative 'manager/target'
|
5
|
+
require_relative 'manager/internal'
|
@@ -1,29 +1,31 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
|
-
module Core
|
4
|
+
module Core
|
5
|
+
module Shape
|
6
|
+
module Manager
|
7
|
+
class Format < Core::Format::Base
|
8
|
+
# @return [Symbol, Integer]
|
9
|
+
attr_reader :identifier
|
5
10
|
|
6
|
-
|
7
|
-
|
8
|
-
|
11
|
+
def initialize(config, id = nil, &block)
|
12
|
+
super(config, &block)
|
13
|
+
@identifier = id || object_id
|
14
|
+
end
|
9
15
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
16
|
+
def find_shape(id)
|
17
|
+
shapes[id]
|
18
|
+
end
|
14
19
|
|
15
|
-
|
16
|
-
|
17
|
-
|
20
|
+
def has_shape?(id)
|
21
|
+
shapes.key?(id)
|
22
|
+
end
|
18
23
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
def shapes
|
24
|
-
@shapes ||= {}
|
24
|
+
def shapes
|
25
|
+
@shapes ||= {}
|
26
|
+
end
|
27
|
+
end
|
25
28
|
end
|
26
29
|
end
|
27
|
-
|
28
30
|
end
|
29
31
|
end
|
@@ -1,104 +1,108 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
|
-
module Core
|
4
|
+
module Core
|
5
|
+
module Shape
|
6
|
+
module Manager
|
7
|
+
class Internal
|
8
|
+
include Utils
|
5
9
|
|
6
|
-
|
7
|
-
|
10
|
+
attr_reader :format
|
11
|
+
attr_reader :shapes
|
12
|
+
attr_reader :lists
|
8
13
|
|
9
|
-
|
10
|
-
|
11
|
-
|
14
|
+
# @param [Thinreports::Core::Manager::Format] format
|
15
|
+
# @param [Proc] init_item_handler
|
16
|
+
def initialize(format, init_item_handler)
|
17
|
+
@format = format
|
18
|
+
@shapes = {}
|
19
|
+
@lists = {}
|
20
|
+
@init_item_handler = init_item_handler
|
21
|
+
end
|
12
22
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@lists = {}
|
19
|
-
@init_item_handler = init_item_handler
|
20
|
-
end
|
23
|
+
# @param [String, Symbol] id
|
24
|
+
# @return [Thinreports::Core::Shape::Basic::Format]
|
25
|
+
def find_format(id)
|
26
|
+
format.find_shape(id.to_sym)
|
27
|
+
end
|
21
28
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
29
|
+
# @param [String, Symbol] id
|
30
|
+
# @param limit (see #valid_type?)
|
31
|
+
def find_item(id, limit = {})
|
32
|
+
id = id.to_sym
|
27
33
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
return nil unless valid_type?(shape.type, limit)
|
35
|
-
shape
|
36
|
-
when sformat = find_format(id)
|
37
|
-
return nil unless valid_type?(sformat.type, limit)
|
38
|
-
shapes[id] = init_item(sformat)
|
39
|
-
else
|
40
|
-
return nil
|
41
|
-
end
|
42
|
-
end
|
34
|
+
if shapes.key?(id)
|
35
|
+
shape = shapes[id]
|
36
|
+
valid_type?(shape.type, limit) ? shape : nil
|
37
|
+
elsif find_format(id)
|
38
|
+
shape_format = find_format(id)
|
39
|
+
return nil unless valid_type?(shape_format.type, limit)
|
43
40
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
41
|
+
shape = init_item(shape_format)
|
42
|
+
shapes[id] = shape
|
43
|
+
|
44
|
+
shape
|
45
|
+
end
|
46
|
+
end
|
48
47
|
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
# @param [String, Symbol] id
|
49
|
+
# @return [Thinreports::Core::Shape::Base::Interface, nil]
|
50
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/PerceivedComplexity
|
51
|
+
def final_shape(id)
|
52
|
+
shape = shapes[id]
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
# When shape was found in registry.
|
55
|
+
if shape
|
56
|
+
return nil unless shape.visible?
|
57
|
+
|
58
|
+
# In the case of TextBlock or ImageBlock.
|
59
|
+
if shape.internal.type_of?(:block)
|
60
|
+
blank_value?(shape.internal.real_value) ? nil : shape
|
61
|
+
else
|
62
|
+
shape
|
63
|
+
end
|
64
|
+
# When shape was not found in registry.
|
65
|
+
elsif format.has_shape?(id)
|
66
|
+
shape_format = find_format(id)
|
67
|
+
return nil unless shape_format.display?
|
68
|
+
|
69
|
+
case shape_format.type
|
70
|
+
# In the case of TextBlock.
|
71
|
+
when TextBlock::TYPE_NAME
|
72
|
+
return nil if !shape_format.has_reference? && blank_value?(shape_format.value)
|
73
|
+
init_item(shape_format)
|
74
|
+
# In the case of ImageBlock, Return the nil constantly.
|
75
|
+
when ImageBlock::TYPE_NAME
|
76
|
+
nil
|
77
|
+
else
|
78
|
+
init_item(shape_format)
|
79
|
+
end
|
80
|
+
end
|
58
81
|
end
|
59
|
-
# When shape was not found in registry.
|
60
|
-
elsif format.has_shape?(id)
|
61
|
-
shape_format = find_format(id)
|
62
|
-
return nil unless shape_format.display?
|
63
82
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
shape_format.has_reference? || !blank_value?(shape_format.value) ? init_item(shape_format) : nil
|
68
|
-
# In the case of ImageBlock, Return the nil constantly.
|
69
|
-
when ImageBlock::TYPE_NAME
|
70
|
-
nil
|
71
|
-
else
|
72
|
-
init_item(shape_format)
|
83
|
+
# @param [Thinreports::Core::Shape::Basic::Format] format
|
84
|
+
def init_item(format)
|
85
|
+
@init_item_handler.call(format)
|
73
86
|
end
|
74
|
-
# In the case of other, Return the nil constantly.
|
75
|
-
else
|
76
|
-
nil
|
77
|
-
end
|
78
|
-
end
|
79
87
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
88
|
+
# @param [String] type
|
89
|
+
# @param [Hash] limit
|
90
|
+
# @option limit [String] :only
|
91
|
+
# @option limit [String] :except
|
92
|
+
# @return [Booldan]
|
93
|
+
def valid_type?(type, limit = {})
|
94
|
+
return true if limit.empty?
|
84
95
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
when only = limit[:only]
|
94
|
-
type == only
|
95
|
-
when except = limit[:except]
|
96
|
-
type != except
|
97
|
-
else
|
98
|
-
raise ArgumentError
|
96
|
+
if limit[:only]
|
97
|
+
type == limit[:only]
|
98
|
+
elsif limit[:except]
|
99
|
+
type != limit[:except]
|
100
|
+
else
|
101
|
+
raise ArgumentError
|
102
|
+
end
|
103
|
+
end
|
99
104
|
end
|
100
105
|
end
|
101
106
|
end
|
102
|
-
|
103
107
|
end
|
104
108
|
end
|