thinreports 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +11 -0
- data/.github/workflows/test.yml +31 -40
- data/.gitignore +1 -1
- data/CHANGELOG.md +25 -1
- data/Gemfile +11 -0
- data/{MIT-LICENSE → LICENSE.txt} +2 -0
- data/README.md +50 -66
- 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/builder/stack_view_builder.rb +0 -2
- 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 +99 -157
- data/Dockerfile +0 -12
- 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/section_report/pdf/renderer/headers_renderer.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,112 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Thinreports
|
|
4
|
+
module BasicReport
|
|
5
|
+
module Core
|
|
6
|
+
module Shape
|
|
7
|
+
module List
|
|
8
|
+
class Page < Basic::Interface
|
|
9
|
+
extend Forwardable
|
|
10
|
+
|
|
11
|
+
attr_reader :manager
|
|
12
|
+
|
|
13
|
+
# @param [Thinreports::BasicReport::Report::Page] parent
|
|
14
|
+
# @param [Thinreports::BasicReport::Core::Shape::Basic::Format] format
|
|
15
|
+
# @param [Thinreports::BasicReport::Core::Shape::List::PageState] internal (nil)
|
|
16
|
+
# @param [Thinreports::BasicReport::Core::Shape::List::Manager] manager (nil)
|
|
17
|
+
def initialize(parent, format, internal = nil, manager = nil)
|
|
18
|
+
super(parent, format, internal)
|
|
19
|
+
|
|
20
|
+
@manager =
|
|
21
|
+
if manager
|
|
22
|
+
manager.switch_current!(self)
|
|
23
|
+
else
|
|
24
|
+
List::Manager.new(self)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Set a reference to List::PageState List::Manager
|
|
28
|
+
self.internal.manager = self.manager
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# @see Thinreports::BasicReport::Core::Shape::List::Manager#build_header
|
|
32
|
+
def_delegator :manager, :build_header, :header
|
|
33
|
+
|
|
34
|
+
def on_page_finalize(&block)
|
|
35
|
+
manager.page_finalize_handler = block
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# @yield [page_footer]
|
|
39
|
+
# @yieldparam [Thinreports::BasicReport::Core::Shape::List::SectionInterface] page_footer
|
|
40
|
+
def on_page_footer_insert(&block)
|
|
41
|
+
manager.page_footer_handler = block
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# @yield [footer]
|
|
45
|
+
# @yieldparam [Thinreports::BasicReport::Core::Shape::List::SectionInterface] footer
|
|
46
|
+
# @return [Thinreports::BasicReport::Core::Shape::List::SectionInterface]
|
|
47
|
+
def on_footer_insert(&block)
|
|
48
|
+
manager.footer_handler = block
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# @param [Hash] values ({})
|
|
52
|
+
# @yield [row,]
|
|
53
|
+
# @yieldparam [Thinreports::BasicReport::Core::Shape::List::SectionInterface] row
|
|
54
|
+
# @return [Boolean]
|
|
55
|
+
def add_row(values = {}, &block)
|
|
56
|
+
manager.add_detail(values, &block)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# If enabled, the auto-page-break of the list will force a page break
|
|
60
|
+
# at the time this method is called. Otherwise, this list will be finalized.
|
|
61
|
+
def page_break
|
|
62
|
+
if manager.auto_page_break?
|
|
63
|
+
manager.change_new_page
|
|
64
|
+
else
|
|
65
|
+
manager.finalize_page
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
alias finalize page_break
|
|
69
|
+
|
|
70
|
+
# @return [Boolean] Returns true if list has overflowed
|
|
71
|
+
# when `list#add_row` is called at the next time.
|
|
72
|
+
def overflow?
|
|
73
|
+
manager.overflow_with?(:detail)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# @param [Thinreports::BasicReport::Report::Page] new_parent
|
|
77
|
+
# @return [Thinreports::BasicReport::Core::Shape::List::Page]
|
|
78
|
+
def copy(new_parent)
|
|
79
|
+
if manager.auto_page_break?
|
|
80
|
+
new_list = self.class.new(new_parent, internal.format,
|
|
81
|
+
nil, manager)
|
|
82
|
+
else
|
|
83
|
+
manager.finalize
|
|
84
|
+
|
|
85
|
+
new_list = self.class.new(new_parent, internal.format,
|
|
86
|
+
internal.copy(new_parent), manager)
|
|
87
|
+
internal.rows.each do |row|
|
|
88
|
+
new_list.internal.rows << row.copy(new_list)
|
|
89
|
+
end
|
|
90
|
+
new_list.internal.finalized!
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
new_list.internal.header = internal.header.copy(new_list) if internal.format.has_header?
|
|
94
|
+
new_list
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
private
|
|
98
|
+
|
|
99
|
+
# @see Thinreports::BasicReport::Core::Shape::Base::Interface#init_internal
|
|
100
|
+
def init_internal(parent, format)
|
|
101
|
+
List::PageState.new(parent, format)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Alias to List::Page.
|
|
106
|
+
# @see Thinreports::BasicReport::Core::Shape::List::Page
|
|
107
|
+
List::Interface = List::Page
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Thinreports
|
|
4
|
+
module BasicReport
|
|
5
|
+
module Core
|
|
6
|
+
module Shape
|
|
7
|
+
module List
|
|
8
|
+
class PageState < Basic::Internal
|
|
9
|
+
attr_reader :rows
|
|
10
|
+
|
|
11
|
+
attr_accessor :height
|
|
12
|
+
attr_accessor :header
|
|
13
|
+
attr_accessor :no
|
|
14
|
+
attr_accessor :manager
|
|
15
|
+
|
|
16
|
+
def initialize(*args)
|
|
17
|
+
super(*args)
|
|
18
|
+
|
|
19
|
+
@rows = []
|
|
20
|
+
@height = 0
|
|
21
|
+
@finalized = false
|
|
22
|
+
|
|
23
|
+
@header = nil
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def style
|
|
27
|
+
@style ||= Style::Basic.new(format)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def finalized?
|
|
31
|
+
@finalized
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def finalized!
|
|
35
|
+
@finalized = true
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def type_of?(type_name)
|
|
39
|
+
type_name == List::TYPE_NAME
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Alias to List::PageState.
|
|
44
|
+
# @see Thinreports::BasicReport::Core::Shape::List::PageState
|
|
45
|
+
List::Internal = List::PageState
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -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
|