thinreports 0.12.1 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +3 -3
- data/.github/workflows/test.yml +28 -36
- data/.gitignore +1 -1
- data/CHANGELOG.md +19 -1
- data/Gemfile +11 -0
- data/README.md +12 -17
- data/Rakefile +17 -11
- data/lib/thinreports/basic_report/core/errors.rb +62 -0
- data/lib/thinreports/basic_report/core/format/base.rb +91 -0
- data/lib/thinreports/basic_report/core/shape/base/interface.rb +42 -0
- data/lib/thinreports/basic_report/core/shape/base/internal.rb +53 -0
- data/lib/thinreports/basic_report/core/shape/basic/block_format.rb +15 -0
- data/lib/thinreports/basic_report/core/shape/basic/block_interface.rb +34 -0
- data/lib/thinreports/basic_report/core/shape/basic/block_internal.rb +36 -0
- data/lib/thinreports/basic_report/core/shape/basic/format.rb +24 -0
- data/lib/thinreports/basic_report/core/shape/basic/interface.rb +87 -0
- data/lib/thinreports/basic_report/core/shape/basic/internal.rb +28 -0
- data/lib/thinreports/{core → basic_report/core}/shape/basic.rb +6 -4
- data/lib/thinreports/basic_report/core/shape/image_block/format.rb +14 -0
- data/lib/thinreports/basic_report/core/shape/image_block/interface.rb +25 -0
- data/lib/thinreports/basic_report/core/shape/image_block/internal.rb +19 -0
- data/lib/thinreports/{core → basic_report/core}/shape/image_block.rb +6 -4
- data/lib/thinreports/basic_report/core/shape/list/format.rb +92 -0
- data/lib/thinreports/basic_report/core/shape/list/manager.rb +231 -0
- data/lib/thinreports/basic_report/core/shape/list/page.rb +112 -0
- data/lib/thinreports/basic_report/core/shape/list/page_state.rb +50 -0
- data/lib/thinreports/basic_report/core/shape/list/section_format.rb +37 -0
- data/lib/thinreports/basic_report/core/shape/list/section_interface.rb +51 -0
- data/lib/thinreports/basic_report/core/shape/list/section_internal.rb +33 -0
- data/lib/thinreports/{core → basic_report/core}/shape/list.rb +6 -4
- data/lib/thinreports/basic_report/core/shape/manager/format.rb +33 -0
- data/lib/thinreports/basic_report/core/shape/manager/internal.rb +109 -0
- data/lib/thinreports/basic_report/core/shape/manager/target.rb +114 -0
- data/lib/thinreports/basic_report/core/shape/page_number/format.rb +32 -0
- data/lib/thinreports/basic_report/core/shape/page_number/interface.rb +31 -0
- data/lib/thinreports/basic_report/core/shape/page_number/internal.rb +57 -0
- data/lib/thinreports/{core → basic_report/core}/shape/page_number.rb +6 -4
- data/lib/thinreports/basic_report/core/shape/stack_view/format.rb +29 -0
- data/lib/thinreports/basic_report/core/shape/stack_view/interface.rb +19 -0
- data/lib/thinreports/basic_report/core/shape/stack_view/internal.rb +24 -0
- data/lib/thinreports/basic_report/core/shape/stack_view/row_format.rb +41 -0
- data/lib/thinreports/{core → basic_report/core}/shape/stack_view.rb +6 -4
- data/lib/thinreports/basic_report/core/shape/style/base.rb +149 -0
- data/lib/thinreports/basic_report/core/shape/style/basic.rb +24 -0
- data/lib/thinreports/basic_report/core/shape/style/graphic.rb +43 -0
- data/lib/thinreports/basic_report/core/shape/style/text.rb +122 -0
- data/lib/thinreports/basic_report/core/shape/text/format.rb +17 -0
- data/lib/thinreports/basic_report/core/shape/text/interface.rb +20 -0
- data/lib/thinreports/basic_report/core/shape/text/internal.rb +24 -0
- data/lib/thinreports/{core → basic_report/core}/shape/text.rb +6 -4
- data/lib/thinreports/basic_report/core/shape/text_block/format.rb +43 -0
- data/lib/thinreports/basic_report/core/shape/text_block/formatter/basic.rb +41 -0
- data/lib/thinreports/basic_report/core/shape/text_block/formatter/datetime.rb +25 -0
- data/lib/thinreports/basic_report/core/shape/text_block/formatter/number.rb +69 -0
- data/lib/thinreports/basic_report/core/shape/text_block/formatter/padding.rb +27 -0
- data/lib/thinreports/basic_report/core/shape/text_block/formatter.rb +38 -0
- data/lib/thinreports/basic_report/core/shape/text_block/interface.rb +37 -0
- data/lib/thinreports/basic_report/core/shape/text_block/internal.rb +75 -0
- data/lib/thinreports/{core → basic_report/core}/shape/text_block.rb +6 -4
- data/lib/thinreports/basic_report/core/shape.rb +44 -0
- data/lib/thinreports/basic_report/core/utils.rb +47 -0
- data/lib/thinreports/basic_report/generator/pdf/document/draw_shape.rb +108 -0
- data/lib/thinreports/basic_report/generator/pdf/document/draw_template_items.rb +71 -0
- data/lib/thinreports/basic_report/generator/pdf/document/font.rb +90 -0
- data/lib/thinreports/basic_report/generator/pdf/document/graphics/attributes.rb +149 -0
- data/lib/thinreports/basic_report/generator/pdf/document/graphics/basic.rb +137 -0
- data/lib/thinreports/basic_report/generator/pdf/document/graphics/image.rb +99 -0
- data/lib/thinreports/basic_report/generator/pdf/document/graphics/text.rb +180 -0
- data/lib/thinreports/basic_report/generator/pdf/document/graphics.rb +42 -0
- data/lib/thinreports/basic_report/generator/pdf/document/page.rb +96 -0
- data/lib/thinreports/basic_report/generator/pdf/document/parse_color.rb +51 -0
- data/lib/thinreports/basic_report/generator/pdf/document.rb +132 -0
- data/lib/thinreports/basic_report/generator/pdf/drawer/base.rb +50 -0
- data/lib/thinreports/basic_report/generator/pdf/drawer/list.rb +65 -0
- data/lib/thinreports/basic_report/generator/pdf/drawer/list_section.rb +51 -0
- data/lib/thinreports/basic_report/generator/pdf/drawer/page.rb +127 -0
- data/lib/thinreports/basic_report/generator/pdf/prawn_ext/calc_image_dimensions.rb +34 -0
- data/lib/thinreports/basic_report/generator/pdf/prawn_ext/width_of.rb +31 -0
- data/lib/thinreports/basic_report/generator/pdf.rb +66 -0
- data/lib/thinreports/basic_report/layout/base.rb +48 -0
- data/lib/thinreports/basic_report/layout/format.rb +67 -0
- data/lib/thinreports/basic_report/layout/legacy_schema.rb +383 -0
- data/lib/thinreports/basic_report/layout/version.rb +41 -0
- data/lib/thinreports/{layout.rb → basic_report/layout.rb} +6 -4
- data/lib/thinreports/basic_report/report/base.rb +173 -0
- data/lib/thinreports/basic_report/report/internal.rb +107 -0
- data/lib/thinreports/basic_report/report/page.rb +97 -0
- data/lib/thinreports/basic_report/report.rb +26 -0
- data/lib/thinreports/basic_report.rb +15 -0
- data/lib/thinreports/config.rb +1 -1
- data/lib/thinreports/section_report.rb +12 -0
- data/lib/thinreports/version.rb +1 -1
- data/lib/thinreports.rb +2 -13
- data/thinreports.gemspec +3 -7
- metadata +97 -154
- data/gemfiles/prawn-2.2.gemfile +0 -5
- data/gemfiles/prawn-2.3.gemfile +0 -5
- data/gemfiles/prawn-2.4.gemfile +0 -5
- data/lib/thinreports/core/errors.rb +0 -60
- data/lib/thinreports/core/format/base.rb +0 -89
- data/lib/thinreports/core/shape/base/interface.rb +0 -40
- data/lib/thinreports/core/shape/base/internal.rb +0 -51
- data/lib/thinreports/core/shape/basic/block_format.rb +0 -13
- data/lib/thinreports/core/shape/basic/block_interface.rb +0 -32
- data/lib/thinreports/core/shape/basic/block_internal.rb +0 -34
- data/lib/thinreports/core/shape/basic/format.rb +0 -22
- data/lib/thinreports/core/shape/basic/interface.rb +0 -85
- data/lib/thinreports/core/shape/basic/internal.rb +0 -26
- data/lib/thinreports/core/shape/image_block/format.rb +0 -12
- data/lib/thinreports/core/shape/image_block/interface.rb +0 -23
- data/lib/thinreports/core/shape/image_block/internal.rb +0 -17
- data/lib/thinreports/core/shape/list/format.rb +0 -90
- data/lib/thinreports/core/shape/list/manager.rb +0 -229
- data/lib/thinreports/core/shape/list/page.rb +0 -110
- data/lib/thinreports/core/shape/list/page_state.rb +0 -48
- data/lib/thinreports/core/shape/list/section_format.rb +0 -35
- data/lib/thinreports/core/shape/list/section_interface.rb +0 -49
- data/lib/thinreports/core/shape/list/section_internal.rb +0 -31
- data/lib/thinreports/core/shape/manager/format.rb +0 -31
- data/lib/thinreports/core/shape/manager/internal.rb +0 -107
- data/lib/thinreports/core/shape/manager/target.rb +0 -112
- data/lib/thinreports/core/shape/page_number/format.rb +0 -30
- data/lib/thinreports/core/shape/page_number/interface.rb +0 -29
- data/lib/thinreports/core/shape/page_number/internal.rb +0 -55
- data/lib/thinreports/core/shape/stack_view/format.rb +0 -27
- data/lib/thinreports/core/shape/stack_view/interface.rb +0 -17
- data/lib/thinreports/core/shape/stack_view/internal.rb +0 -22
- data/lib/thinreports/core/shape/stack_view/row_format.rb +0 -39
- data/lib/thinreports/core/shape/style/base.rb +0 -146
- data/lib/thinreports/core/shape/style/basic.rb +0 -22
- data/lib/thinreports/core/shape/style/graphic.rb +0 -41
- data/lib/thinreports/core/shape/style/text.rb +0 -120
- data/lib/thinreports/core/shape/text/format.rb +0 -15
- data/lib/thinreports/core/shape/text/interface.rb +0 -18
- data/lib/thinreports/core/shape/text/internal.rb +0 -22
- data/lib/thinreports/core/shape/text_block/format.rb +0 -41
- data/lib/thinreports/core/shape/text_block/formatter/basic.rb +0 -39
- data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +0 -23
- data/lib/thinreports/core/shape/text_block/formatter/number.rb +0 -67
- data/lib/thinreports/core/shape/text_block/formatter/padding.rb +0 -25
- data/lib/thinreports/core/shape/text_block/formatter.rb +0 -34
- data/lib/thinreports/core/shape/text_block/interface.rb +0 -35
- data/lib/thinreports/core/shape/text_block/internal.rb +0 -73
- data/lib/thinreports/core/shape.rb +0 -42
- data/lib/thinreports/core/utils.rb +0 -45
- data/lib/thinreports/generate.rb +0 -11
- data/lib/thinreports/generator/pdf/document/draw_shape.rb +0 -106
- data/lib/thinreports/generator/pdf/document/draw_template_items.rb +0 -69
- data/lib/thinreports/generator/pdf/document/font.rb +0 -88
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +0 -147
- data/lib/thinreports/generator/pdf/document/graphics/basic.rb +0 -135
- data/lib/thinreports/generator/pdf/document/graphics/image.rb +0 -98
- data/lib/thinreports/generator/pdf/document/graphics/text.rb +0 -178
- data/lib/thinreports/generator/pdf/document/graphics.rb +0 -40
- data/lib/thinreports/generator/pdf/document/page.rb +0 -94
- data/lib/thinreports/generator/pdf/document/parse_color.rb +0 -49
- data/lib/thinreports/generator/pdf/document.rb +0 -130
- data/lib/thinreports/generator/pdf/drawer/base.rb +0 -48
- data/lib/thinreports/generator/pdf/drawer/list.rb +0 -63
- data/lib/thinreports/generator/pdf/drawer/list_section.rb +0 -49
- data/lib/thinreports/generator/pdf/drawer/page.rb +0 -125
- data/lib/thinreports/generator/pdf/prawn_ext/calc_image_dimensions.rb +0 -32
- data/lib/thinreports/generator/pdf/prawn_ext/width_of.rb +0 -29
- data/lib/thinreports/generator/pdf.rb +0 -63
- data/lib/thinreports/layout/base.rb +0 -46
- data/lib/thinreports/layout/format.rb +0 -65
- data/lib/thinreports/layout/legacy_schema.rb +0 -381
- data/lib/thinreports/layout/version.rb +0 -39
- data/lib/thinreports/report/base.rb +0 -169
- data/lib/thinreports/report/internal.rb +0 -105
- data/lib/thinreports/report/page.rb +0 -95
- data/lib/thinreports/report.rb +0 -24
- /data/lib/thinreports/{core → basic_report/core}/shape/base.rb +0 -0
- /data/lib/thinreports/{core → basic_report/core}/shape/manager.rb +0 -0
- /data/lib/thinreports/{core → basic_report/core}/shape/style.rb +0 -0
- /data/lib/thinreports/{generator → basic_report/generator}/pdf/prawn_ext.rb +0 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Thinreports
|
4
|
+
module BasicReport
|
5
|
+
module Core
|
6
|
+
module Shape
|
7
|
+
module List
|
8
|
+
class SectionFormat < Shape::Manager::Format
|
9
|
+
config_reader :height
|
10
|
+
config_reader relative_left: %w[translate x],
|
11
|
+
relative_top: %w[translate y]
|
12
|
+
config_reader :style
|
13
|
+
|
14
|
+
# For compatible 0.8.x format API
|
15
|
+
config_checker true, display: %w[enabled]
|
16
|
+
|
17
|
+
def initialize(*)
|
18
|
+
super
|
19
|
+
initialize_items(attributes['items'])
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def initialize_items(item_schemas)
|
25
|
+
item_schemas.each do |item_schema|
|
26
|
+
id, type = item_schema.values_at 'id', 'type'
|
27
|
+
next if id.empty?
|
28
|
+
|
29
|
+
shapes[id.to_sym] = Core::Shape::Format(type).new(item_schema)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Thinreports
|
4
|
+
module BasicReport
|
5
|
+
module Core
|
6
|
+
module Shape
|
7
|
+
module List
|
8
|
+
class SectionInterface < Base::Interface
|
9
|
+
include Core::Shape::Manager::Target
|
10
|
+
|
11
|
+
undef_method :list
|
12
|
+
internal_delegators :height
|
13
|
+
|
14
|
+
# @param [Thinreports::BasicReport::Core::Shape::List::Page] parent
|
15
|
+
# @param [Thinreports::BasicReport::Core::Shape::List::SectionFormat] format
|
16
|
+
# @param [Symbol] section_name
|
17
|
+
def initialize(parent, format, section_name)
|
18
|
+
super(parent, format)
|
19
|
+
internal.section_name = section_name
|
20
|
+
|
21
|
+
initialize_manager(format) do |f|
|
22
|
+
Core::Shape::Interface(self, f)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# @param [Thinreports::BasicReport::Core::Shape::List::Page] parent
|
27
|
+
# @return [Thinreports::BasicReport::Core::Shape::List::SectionInterface]
|
28
|
+
def copy(parent)
|
29
|
+
new_sec = super
|
30
|
+
new_sec.internal.section_name = internal.section_name
|
31
|
+
|
32
|
+
manager.shapes.each do |id, shape|
|
33
|
+
new_sec.manager.shapes[id] = shape.copy(new_sec)
|
34
|
+
end
|
35
|
+
new_sec
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
# @param parent (see #initialize)
|
41
|
+
# @param format (see #initialize)
|
42
|
+
# @return [Thinreports::BasicReport::Core::Shape::List::SectionInternal]
|
43
|
+
def init_internal(parent, format)
|
44
|
+
List::SectionInternal.new(parent, format)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Thinreports
|
4
|
+
module BasicReport
|
5
|
+
module Core
|
6
|
+
module Shape
|
7
|
+
module List
|
8
|
+
class SectionInternal < Base::Internal
|
9
|
+
format_delegators :height,
|
10
|
+
:relative_left
|
11
|
+
|
12
|
+
# @return [Symbol]
|
13
|
+
attr_accessor :section_name
|
14
|
+
|
15
|
+
def style
|
16
|
+
@style ||= Style::Base.new(format)
|
17
|
+
end
|
18
|
+
|
19
|
+
# @param [Numeric] ry
|
20
|
+
def move_top_to(ry)
|
21
|
+
states[:relative_top] = ry
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [Float]
|
25
|
+
def relative_top
|
26
|
+
states[:relative_top] || 0
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Thinreports
|
4
|
+
module BasicReport
|
5
|
+
module Core
|
6
|
+
module Shape
|
7
|
+
module Manager
|
8
|
+
class Format < Core::Format::Base
|
9
|
+
# @return [Symbol, Integer]
|
10
|
+
attr_reader :identifier
|
11
|
+
|
12
|
+
def initialize(config, id = nil, &block)
|
13
|
+
super(config, &block)
|
14
|
+
@identifier = id || object_id
|
15
|
+
end
|
16
|
+
|
17
|
+
def find_shape(id)
|
18
|
+
shapes[id]
|
19
|
+
end
|
20
|
+
|
21
|
+
def has_shape?(id)
|
22
|
+
shapes.key?(id)
|
23
|
+
end
|
24
|
+
|
25
|
+
def shapes
|
26
|
+
@shapes ||= {}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Thinreports
|
4
|
+
module BasicReport
|
5
|
+
module Core
|
6
|
+
module Shape
|
7
|
+
module Manager
|
8
|
+
class Internal
|
9
|
+
include Utils
|
10
|
+
|
11
|
+
attr_reader :format
|
12
|
+
attr_reader :shapes
|
13
|
+
attr_reader :lists
|
14
|
+
|
15
|
+
# @param [Thinreports::BasicReport::Core::Manager::Format] format
|
16
|
+
# @param [Proc] init_item_handler
|
17
|
+
def initialize(format, init_item_handler)
|
18
|
+
@format = format
|
19
|
+
@shapes = {}
|
20
|
+
@lists = {}
|
21
|
+
@init_item_handler = init_item_handler
|
22
|
+
end
|
23
|
+
|
24
|
+
# @param [String, Symbol] id
|
25
|
+
# @return [Thinreports::BasicReport::Core::Shape::Basic::Format]
|
26
|
+
def find_format(id)
|
27
|
+
format.find_shape(id.to_sym)
|
28
|
+
end
|
29
|
+
|
30
|
+
# @param [String, Symbol] id
|
31
|
+
# @param limit (see #valid_type?)
|
32
|
+
def find_item(id, limit = {})
|
33
|
+
id = id.to_sym
|
34
|
+
|
35
|
+
if shapes.key?(id)
|
36
|
+
shape = shapes[id]
|
37
|
+
valid_type?(shape.type, limit) ? shape : nil
|
38
|
+
elsif find_format(id)
|
39
|
+
shape_format = find_format(id)
|
40
|
+
return nil unless valid_type?(shape_format.type, limit)
|
41
|
+
|
42
|
+
shape = init_item(shape_format)
|
43
|
+
shapes[id] = shape
|
44
|
+
|
45
|
+
shape
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# @param [String, Symbol] id
|
50
|
+
# @return [Thinreports::BasicReport::Core::Shape::Base::Interface, nil]
|
51
|
+
def final_shape(id)
|
52
|
+
shape = shapes[id]
|
53
|
+
|
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
|
81
|
+
end
|
82
|
+
|
83
|
+
# @param [Thinreports::BasicReport::Core::Shape::Basic::Format] format
|
84
|
+
def init_item(format)
|
85
|
+
@init_item_handler.call(format)
|
86
|
+
end
|
87
|
+
|
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?
|
95
|
+
|
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
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Thinreports
|
4
|
+
module BasicReport
|
5
|
+
module Core
|
6
|
+
module Shape
|
7
|
+
module Manager
|
8
|
+
module Target
|
9
|
+
include Utils
|
10
|
+
|
11
|
+
attr_reader :manager
|
12
|
+
|
13
|
+
# @example
|
14
|
+
# item(:title).value('Title').style(:fill, 'red')
|
15
|
+
#
|
16
|
+
# item(:title) do
|
17
|
+
# value('Title')
|
18
|
+
# style(:fill, 'red')
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# item(:title) do |t|
|
22
|
+
# t.value('Title')
|
23
|
+
# t.style(:fill, 'red')
|
24
|
+
# end
|
25
|
+
# item(:list) # => Error: UnknownItemId
|
26
|
+
# item(:unknown_id) # => Error: UnknownItemId
|
27
|
+
# @param [String, Symbol] id
|
28
|
+
# @yield [item,]
|
29
|
+
# @yieldparam [Thinreports::BasicReport::Core::Shape::Base::Interface] item
|
30
|
+
# @raise [Thinreports::BasicReport::Errors::UnknownItemId]
|
31
|
+
# @return [Thinreports::BasicReport::Core::Shape::Base::Interface]
|
32
|
+
def item(id, &block)
|
33
|
+
shape = find_item(id, except: Core::Shape::List::TYPE_NAME)
|
34
|
+
|
35
|
+
raise Thinreports::BasicReport::Errors::UnknownItemId, id unless shape
|
36
|
+
|
37
|
+
call_block_in(shape, &block)
|
38
|
+
end
|
39
|
+
|
40
|
+
# @example
|
41
|
+
# page[:text_block].style(:bold, true)
|
42
|
+
# page[:rect].style(:border_color, 'red')
|
43
|
+
#
|
44
|
+
# page[:list] # => Error: UnknownItemId
|
45
|
+
# page[:unknown_id] # => Error: UnknownItemId
|
46
|
+
# @param [String, Symbol] id
|
47
|
+
# @return [Thinreports::BasicReport::Core::Shape::Base::Interface]
|
48
|
+
def [](id)
|
49
|
+
item(id)
|
50
|
+
end
|
51
|
+
|
52
|
+
# @example
|
53
|
+
# page[:text_block] = 'Title'
|
54
|
+
# page[:image_block] = '/path/to/image.png'
|
55
|
+
# page[:list] = 'value' # => Error: UnknownItemId
|
56
|
+
# page[:ellipse] = 'value' # => Error: NoMethodError #value
|
57
|
+
# page[:unknown_id] = 'value' # => Error: UnknownItemId
|
58
|
+
# @param [String, Symbol] id
|
59
|
+
# @param [Object] value
|
60
|
+
def []=(id, value)
|
61
|
+
item(id).value = value
|
62
|
+
end
|
63
|
+
|
64
|
+
# @example
|
65
|
+
# page.values text_block: 'value',
|
66
|
+
# image_block: '/path/to/image.png'
|
67
|
+
# @param [Hash] item_values
|
68
|
+
def values(item_values)
|
69
|
+
item_values.each { |id, val| item(id).value(val) }
|
70
|
+
end
|
71
|
+
|
72
|
+
# @param [Symbol, String] id
|
73
|
+
# @return [Boolean]
|
74
|
+
def item_exists?(id)
|
75
|
+
!manager.find_format(id).nil?
|
76
|
+
end
|
77
|
+
alias exists? item_exists?
|
78
|
+
|
79
|
+
# @example
|
80
|
+
# report.list.add_row do |row|
|
81
|
+
# row.item(:price).value(1000)
|
82
|
+
# end
|
83
|
+
#
|
84
|
+
# report.list(:list_id) # => List
|
85
|
+
# report.list(:text_block_id) # => raises UnknownItemId
|
86
|
+
# @see #item
|
87
|
+
def list(id = nil, &block)
|
88
|
+
shape = find_item(id ||= :default, only: Core::Shape::List::TYPE_NAME)
|
89
|
+
|
90
|
+
raise Thinreports::BasicReport::Errors::UnknownItemId.new(id, 'List') unless shape
|
91
|
+
|
92
|
+
manager.lists[id.to_sym] ||= shape
|
93
|
+
call_block_in(shape, &block)
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
# @param format (see Thinreports::BasicReport::Core::Shape::Manager::Internal#initialize)
|
99
|
+
# @yield [format] Handler for initialize item.
|
100
|
+
# @yieldparam [Thinreports::BasicReport::Core::Shape::Basic::Format] format
|
101
|
+
def initialize_manager(format, &block)
|
102
|
+
@manager = Manager::Internal.new(format, block)
|
103
|
+
end
|
104
|
+
|
105
|
+
# @see Thinreports::BasicReport::Core::Shape::Manager::Internal#find_item
|
106
|
+
def find_item(id, limit = {})
|
107
|
+
manager.find_item(id, limit)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Thinreports
|
4
|
+
module BasicReport
|
5
|
+
module Core
|
6
|
+
module Shape
|
7
|
+
module PageNumber
|
8
|
+
class Format < Basic::Format
|
9
|
+
config_reader :target
|
10
|
+
config_reader default_format: %w[format]
|
11
|
+
|
12
|
+
# For saving compatible 0.8.x format API
|
13
|
+
config_reader overflow: %w[style overflow]
|
14
|
+
|
15
|
+
def id
|
16
|
+
@id ||= blank_value?(read('id')) ? self.class.next_default_id : read('id')
|
17
|
+
end
|
18
|
+
|
19
|
+
def for_report?
|
20
|
+
blank_value?(target)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.next_default_id
|
24
|
+
@id_counter ||= 0
|
25
|
+
"__pageno#{@id_counter += 1}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Thinreports
|
4
|
+
module BasicReport
|
5
|
+
module Core
|
6
|
+
module Shape
|
7
|
+
module PageNumber
|
8
|
+
class Interface < Basic::Interface
|
9
|
+
internal_delegators :reset_format
|
10
|
+
|
11
|
+
def format(*args)
|
12
|
+
if args.empty?
|
13
|
+
internal.read_format
|
14
|
+
else
|
15
|
+
internal.write_format(args.first)
|
16
|
+
self
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# @see Thinreports::BasicReport::Core::Shape::Base::Interface#init_internal
|
23
|
+
def init_internal(parent, format)
|
24
|
+
PageNumber::Internal.new(parent, format)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Thinreports
|
4
|
+
module BasicReport
|
5
|
+
module Core
|
6
|
+
module Shape
|
7
|
+
module PageNumber
|
8
|
+
class Internal < Basic::Internal
|
9
|
+
format_delegators :box, :for_report?
|
10
|
+
|
11
|
+
def read_format
|
12
|
+
states.key?(:format) ? states[:format] : format.default_format.dup
|
13
|
+
end
|
14
|
+
|
15
|
+
def reset_format
|
16
|
+
states.delete(:format)
|
17
|
+
end
|
18
|
+
|
19
|
+
def write_format(format)
|
20
|
+
states[:format] = format.to_s
|
21
|
+
end
|
22
|
+
|
23
|
+
def build_format(page_no, page_count)
|
24
|
+
return '' if blank_value?(read_format)
|
25
|
+
|
26
|
+
if start_page_number > 1
|
27
|
+
page_no += start_page_number - 1
|
28
|
+
page_count += start_page_number - 1
|
29
|
+
end
|
30
|
+
|
31
|
+
read_format.dup.tap do |f|
|
32
|
+
f.gsub! '{page}', page_no.to_s
|
33
|
+
f.gsub! '{total}', page_count.to_s
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def style
|
38
|
+
@style ||= PageNumber::Style.new(format)
|
39
|
+
end
|
40
|
+
|
41
|
+
def type_of?(type_name)
|
42
|
+
type_name == PageNumber::TYPE_NAME
|
43
|
+
end
|
44
|
+
|
45
|
+
def start_page_number
|
46
|
+
for_report? ? parent.report.start_page_number : 1
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class Style < Style::Text
|
51
|
+
accessible_styles.delete :valign
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
|
-
module
|
5
|
-
module
|
6
|
-
module
|
7
|
-
|
4
|
+
module BasicReport
|
5
|
+
module Core
|
6
|
+
module Shape
|
7
|
+
module PageNumber
|
8
|
+
TYPE_NAME = 'page-number'
|
9
|
+
end
|
8
10
|
end
|
9
11
|
end
|
10
12
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Thinreports
|
4
|
+
module BasicReport
|
5
|
+
module Core
|
6
|
+
module Shape
|
7
|
+
module StackView
|
8
|
+
class Format < Basic::Format
|
9
|
+
attr_reader :rows
|
10
|
+
|
11
|
+
def initialize(*)
|
12
|
+
super
|
13
|
+
initialize_rows
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def initialize_rows
|
19
|
+
@rows = []
|
20
|
+
attributes['rows'].each do |row|
|
21
|
+
@rows << StackView::RowFormat.new(row)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Thinreports
|
4
|
+
module BasicReport
|
5
|
+
module Core
|
6
|
+
module Shape
|
7
|
+
module StackView
|
8
|
+
class Interface < Basic::Interface
|
9
|
+
private
|
10
|
+
|
11
|
+
def init_internal(parent, format)
|
12
|
+
StackView::Internal.new(parent, format)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Thinreports
|
4
|
+
module BasicReport
|
5
|
+
module Core
|
6
|
+
module Shape
|
7
|
+
module StackView
|
8
|
+
class Internal < Basic::Internal
|
9
|
+
def initialize(parent, format)
|
10
|
+
super
|
11
|
+
@rows = []
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_accessor :rows
|
15
|
+
|
16
|
+
def type_of?(type_name)
|
17
|
+
type_name == StackView::TYPE_NAME
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Thinreports
|
4
|
+
module BasicReport
|
5
|
+
module Core
|
6
|
+
module Shape
|
7
|
+
module StackView
|
8
|
+
class RowFormat < Core::Format::Base
|
9
|
+
config_reader :id
|
10
|
+
config_reader :height
|
11
|
+
config_checker true, :display
|
12
|
+
config_checker true, auto_stretch: 'auto-stretch'
|
13
|
+
|
14
|
+
attr_reader :items
|
15
|
+
|
16
|
+
def initialize(*)
|
17
|
+
super
|
18
|
+
@items = []
|
19
|
+
@item_with_ids = {}
|
20
|
+
initialize_items(attributes['items'])
|
21
|
+
end
|
22
|
+
|
23
|
+
def find_item(id)
|
24
|
+
@item_with_ids[id.to_sym]
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def initialize_items(item_schemas)
|
30
|
+
item_schemas.each do |item_schema|
|
31
|
+
item = Core::Shape::Format(item_schema['type']).new(item_schema)
|
32
|
+
@items << item
|
33
|
+
@item_with_ids[item.id.to_sym] = item unless item.id.empty?
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Thinreports
|
4
|
-
module
|
5
|
-
module
|
6
|
-
module
|
7
|
-
|
4
|
+
module BasicReport
|
5
|
+
module Core
|
6
|
+
module Shape
|
7
|
+
module StackView
|
8
|
+
TYPE_NAME = 'stack-view'.freeze
|
9
|
+
end
|
8
10
|
end
|
9
11
|
end
|
10
12
|
end
|