thinreports 0.7.6 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -5
- data/.travis.yml +8 -4
- data/CHANGELOG.md +220 -0
- data/Gemfile +2 -9
- data/MIT-LICENSE +1 -1
- data/README.md +286 -0
- data/Rakefile +38 -8
- data/examples/character_spacing/character_spacing.rb +8 -0
- data/examples/character_spacing/character_spacing.tlf +1 -0
- data/examples/dynamic_image/dynamic_image.rb +31 -0
- data/examples/dynamic_image/dynamic_image.tlf +1 -0
- data/examples/dynamic_style/dynamic_style.rb +150 -0
- data/examples/dynamic_style/dynamic_style.tlf +1 -0
- data/examples/dynamic_style/dynamic_style_in_list.tlf +1 -0
- data/examples/eudc/eudc.rb +20 -0
- data/examples/eudc/eudc.tlf +1 -0
- data/examples/helper.rb +50 -0
- data/examples/hidden_shapes/hidden_shapes.rb +9 -0
- data/examples/hidden_shapes/hidden_shapes.tlf +1 -0
- data/examples/list_events/list_events.rb +59 -0
- data/examples/list_events/list_events_0_7_7.tlf +1 -0
- data/examples/list_events/list_events_0_8.tlf +1 -0
- data/examples/list_manual_generation/list_manual_generation.rb +22 -0
- data/examples/list_manual_generation/list_manual_generation.tlf +1 -0
- data/examples/list_page_number/list_page_number.rb +17 -0
- data/examples/list_page_number/list_page_number.tlf +1 -0
- data/examples/page_number/page_number.rb +33 -0
- data/examples/page_number/page_number.tlf +1 -0
- data/examples/password_setting/password_setting.rb +10 -0
- data/examples/password_setting/password_setting.tlf +1 -0
- data/examples/report_callbacks/report_callbacks.rb +31 -0
- data/examples/report_callbacks/report_callbacks.tlf +1 -0
- data/examples/single_line_tblock/single_line_tblock.rb +13 -0
- data/examples/single_line_tblock/single_line_tblock.tlf +1 -0
- data/examples/tblock_overflow/tblock_overflow.rb +20 -0
- data/examples/tblock_overflow/tblock_overflow.tlf +1 -0
- data/examples/tblock_styles/font_size.tlf +1 -0
- data/examples/tblock_styles/tblock_styles.rb +43 -0
- data/examples/tblock_styles/tblock_styles.tlf +1 -0
- data/examples/text_align/text_align.rb +8 -0
- data/examples/text_align/text_align.tlf +1 -0
- data/examples/typeB_page_size/B4_ISO.tlf +1 -0
- data/examples/typeB_page_size/B4_JIS.tlf +1 -0
- data/examples/typeB_page_size/typeB_page_size.rb +17 -0
- data/examples/word_wrap/word_wrap.rb +26 -0
- data/examples/word_wrap/word_wrap.tlf +1 -0
- data/lib/thinreports/config.rb +30 -10
- data/lib/thinreports/core/errors.rb +23 -20
- data/lib/thinreports/core/events.rb +18 -19
- data/lib/thinreports/core/format/base.rb +20 -25
- data/lib/thinreports/core/format/builder.rb +19 -27
- data/lib/thinreports/core/shape/base/interface.rb +15 -15
- data/lib/thinreports/core/shape/base/internal.rb +15 -20
- data/lib/thinreports/core/shape/base.rb +4 -5
- data/lib/thinreports/core/shape/basic/block_format.rb +3 -4
- data/lib/thinreports/core/shape/basic/block_interface.rb +9 -4
- data/lib/thinreports/core/shape/basic/block_internal.rb +9 -10
- data/lib/thinreports/core/shape/basic/format.rb +11 -10
- data/lib/thinreports/core/shape/basic/interface.rb +3 -3
- data/lib/thinreports/core/shape/basic/internal.rb +9 -6
- data/lib/thinreports/core/shape/basic.rb +1 -1
- data/lib/thinreports/core/shape/image_block/format.rb +5 -6
- data/lib/thinreports/core/shape/image_block/interface.rb +9 -7
- data/lib/thinreports/core/shape/image_block/internal.rb +5 -6
- data/lib/thinreports/core/shape/image_block.rb +1 -1
- data/lib/thinreports/core/shape/list/configuration.rb +37 -16
- data/lib/thinreports/core/shape/list/events.rb +11 -11
- data/lib/thinreports/core/shape/list/format.rb +27 -28
- data/lib/thinreports/core/shape/list/manager.rb +135 -95
- data/lib/thinreports/core/shape/list/page.rb +57 -51
- data/lib/thinreports/core/shape/list/page_state.rb +19 -17
- data/lib/thinreports/core/shape/list/section_format.rb +14 -15
- data/lib/thinreports/core/shape/list/section_interface.rb +15 -16
- data/lib/thinreports/core/shape/list/section_internal.rb +7 -8
- data/lib/thinreports/core/shape/list/store.rb +10 -11
- data/lib/thinreports/core/shape/list.rb +1 -1
- data/lib/thinreports/core/shape/manager/format.rb +10 -11
- data/lib/thinreports/core/shape/manager/internal.rb +22 -21
- data/lib/thinreports/core/shape/manager/target.rb +63 -34
- data/lib/thinreports/core/shape/manager.rb +1 -1
- data/lib/thinreports/core/shape/page_number/format.rb +25 -0
- data/lib/thinreports/core/shape/page_number/interface.rb +27 -0
- data/lib/thinreports/core/shape/page_number/internal.rb +57 -0
- data/lib/thinreports/core/shape/page_number.rb +15 -0
- data/lib/thinreports/core/shape/style/base.rb +29 -29
- data/lib/thinreports/core/shape/style/basic.rb +1 -1
- data/lib/thinreports/core/shape/style/graphic.rb +10 -25
- data/lib/thinreports/core/shape/style/text.rb +41 -31
- data/lib/thinreports/core/shape/style.rb +1 -1
- data/lib/thinreports/core/shape/text/format.rb +8 -9
- data/lib/thinreports/core/shape/text/interface.rb +2 -2
- data/lib/thinreports/core/shape/text/internal.rb +6 -7
- data/lib/thinreports/core/shape/text.rb +1 -1
- data/lib/thinreports/core/shape/text_block/format.rb +17 -17
- data/lib/thinreports/core/shape/text_block/formatter/basic.rb +13 -12
- data/lib/thinreports/core/shape/text_block/formatter/datetime.rb +8 -9
- data/lib/thinreports/core/shape/text_block/formatter/number.rb +11 -12
- data/lib/thinreports/core/shape/text_block/formatter/padding.rb +9 -32
- data/lib/thinreports/core/shape/text_block/formatter.rb +7 -8
- data/lib/thinreports/core/shape/text_block/interface.rb +2 -2
- data/lib/thinreports/core/shape/text_block/internal.rb +19 -20
- data/lib/thinreports/core/shape/text_block.rb +1 -1
- data/lib/thinreports/core/shape.rb +11 -13
- data/lib/thinreports/core/utils.rb +33 -32
- data/lib/thinreports/generator/base.rb +15 -24
- data/lib/thinreports/generator/configuration.rb +10 -9
- data/lib/thinreports/generator/pdf/configuration.rb +11 -6
- data/lib/thinreports/generator/pdf/document/draw_shape.rb +41 -32
- data/lib/thinreports/generator/pdf/document/font.rb +53 -44
- data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +34 -25
- data/lib/thinreports/generator/pdf/document/graphics/basic.rb +25 -25
- data/lib/thinreports/generator/pdf/document/graphics/image.rb +15 -15
- data/lib/thinreports/generator/pdf/document/graphics/text.rb +43 -41
- data/lib/thinreports/generator/pdf/document/graphics.rb +8 -9
- data/lib/thinreports/generator/pdf/document/page.rb +37 -23
- data/lib/thinreports/generator/pdf/document/parse_color.rb +9 -10
- data/lib/thinreports/generator/pdf/document/parse_svg.rb +14 -15
- data/lib/thinreports/generator/pdf/document.rb +28 -28
- data/lib/thinreports/generator/pdf/drawer/base.rb +16 -22
- data/lib/thinreports/generator/pdf/drawer/list.rb +39 -21
- data/lib/thinreports/generator/pdf/drawer/list_section.rb +17 -18
- data/lib/thinreports/generator/pdf/drawer/page.rb +37 -26
- data/lib/thinreports/generator/pdf/prawn_ext.rb +18 -17
- data/lib/thinreports/generator/pdf.rb +28 -31
- data/lib/thinreports/generator.rb +6 -8
- data/lib/thinreports/layout/base.rb +24 -36
- data/lib/thinreports/layout/configuration.rb +11 -9
- data/lib/thinreports/layout/format.rb +26 -31
- data/lib/thinreports/layout/version.rb +8 -9
- data/lib/thinreports/layout.rb +2 -2
- data/lib/thinreports/report/base.rb +117 -109
- data/lib/thinreports/report/events.rb +5 -5
- data/lib/thinreports/report/internal.rb +48 -38
- data/lib/thinreports/{core → report}/page.rb +42 -32
- data/lib/thinreports/report.rb +10 -14
- data/lib/thinreports/version.rb +2 -3
- data/lib/thinreports.rb +14 -2
- data/test/data/font.ttf +0 -0
- data/test/data/layout_block.tlf +1 -0
- data/test/data/layout_list.tlf +1 -0
- data/test/data/layout_list_noheader.tlf +1 -0
- data/test/data/layout_text1.tlf +1 -0
- data/test/data/layout_text2.tlf +1 -0
- data/test/test_helper.rb +74 -0
- data/test/tmp/.gitkeep +0 -0
- data/test/unit/core/format/test_base.rb +14 -14
- data/test/unit/core/format/test_builder.rb +20 -25
- data/test/unit/core/shape/base/test_internal.rb +34 -37
- data/test/unit/core/shape/basic/test_basic_format.rb +4 -4
- data/test/unit/core/shape/basic/test_basic_interface.rb +15 -13
- data/test/unit/core/shape/basic/test_basic_internal.rb +19 -16
- data/test/unit/core/shape/basic/test_format.rb +4 -4
- data/test/unit/core/shape/basic/test_interface.rb +36 -46
- data/test/unit/core/shape/basic/test_internal.rb +29 -18
- data/test/unit/core/shape/image_block/test_format.rb +5 -5
- data/test/unit/core/shape/image_block/test_interface.rb +17 -16
- data/test/unit/core/shape/image_block/test_internal.rb +19 -16
- data/test/unit/core/shape/list/test_configuration.rb +50 -33
- data/test/unit/core/shape/list/test_events.rb +7 -7
- data/test/unit/core/shape/list/test_format.rb +16 -18
- data/test/unit/core/shape/list/test_manager.rb +15 -5
- data/test/unit/core/shape/list/test_page.rb +80 -22
- data/test/unit/core/shape/list/test_page_state.rb +13 -13
- data/test/unit/core/shape/list/test_section_format.rb +16 -17
- data/test/unit/core/shape/list/test_section_interface.rb +30 -22
- data/test/unit/core/shape/list/test_section_internal.rb +21 -19
- data/test/unit/core/shape/list/test_store.rb +7 -7
- data/test/unit/core/shape/manager/test_format.rb +11 -15
- data/test/unit/core/shape/manager/test_internal.rb +9 -9
- data/test/unit/core/shape/manager/test_target.rb +85 -57
- data/test/unit/core/shape/page_number/test_format.rb +73 -0
- data/test/unit/core/shape/page_number/test_interface.rb +33 -0
- data/test/unit/core/shape/page_number/test_internal.rb +81 -0
- data/test/unit/core/shape/styles/test_base.rb +9 -9
- data/test/unit/core/shape/styles/test_basic.rb +5 -5
- data/test/unit/core/shape/styles/test_graphic.rb +19 -33
- data/test/unit/core/shape/styles/test_text.rb +29 -7
- data/test/unit/core/shape/text/test_format.rb +6 -6
- data/test/unit/core/shape/text/test_internal.rb +11 -12
- data/test/unit/core/shape/text_block/formatter/test_basic.rb +16 -16
- data/test/unit/core/shape/text_block/formatter/test_datetime.rb +22 -20
- data/test/unit/core/shape/text_block/formatter/test_number.rb +34 -34
- data/test/unit/core/shape/text_block/formatter/test_padding.rb +44 -44
- data/test/unit/core/shape/text_block/test_format.rb +13 -8
- data/test/unit/core/shape/text_block/test_formatter.rb +17 -17
- data/test/unit/core/shape/text_block/test_interface.rb +37 -20
- data/test/unit/core/shape/text_block/test_internal.rb +38 -38
- data/test/unit/core/test_events.rb +10 -8
- data/test/unit/core/test_shape.rb +11 -7
- data/test/unit/core/test_utils.rb +68 -0
- data/test/unit/generator/pdf/document/graphics/test_attributes.rb +10 -4
- data/test/unit/generator/pdf/document/graphics/test_text.rb +60 -53
- data/test/unit/generator/pdf/document/test_draw_shape.rb +14 -6
- data/test/unit/generator/pdf/document/test_font.rb +79 -58
- data/test/unit/generator/pdf/document/test_graphics.rb +18 -19
- data/test/unit/generator/pdf/document/test_page.rb +68 -43
- data/test/unit/generator/pdf/document/test_parse_color.rb +5 -5
- data/test/unit/generator/pdf/test_configuration.rb +16 -9
- data/test/unit/generator/pdf/test_document.rb +8 -16
- data/test/unit/generator/test_base.rb +31 -42
- data/test/unit/generator/test_configuration.rb +6 -6
- data/test/unit/generator/test_pdf.rb +15 -21
- data/test/unit/layout/test_base.rb +34 -79
- data/test/unit/layout/test_configuration.rb +12 -37
- data/test/unit/layout/test_format.rb +36 -39
- data/test/unit/layout/test_version.rb +4 -4
- data/test/unit/report/test_base.rb +160 -192
- data/test/unit/report/test_events.rb +4 -4
- data/test/unit/report/test_internal.rb +102 -82
- data/test/unit/test_config.rb +31 -12
- data/test/unit/test_layout.rb +7 -7
- data/test/unit/test_report.rb +12 -24
- data/thinreports.gemspec +23 -26
- metadata +118 -181
- data/.yardopts +0 -1
- data/LICENSE +0 -1
- data/README.rdoc +0 -167
- data/doc/yardoc_templates/default/layout/html/footer.erb +0 -10
- data/lib/thinreports/core/ext/array.rb +0 -19
- data/lib/thinreports/core/ext/hash.rb +0 -19
- data/lib/thinreports/core/ext/object.rb +0 -25
- data/lib/thinreports/core/ext.rb +0 -5
- data/lib/thinreports/core/format.rb +0 -14
- data/lib/thinreports/core/ordered_hash.rb +0 -39
- data/lib/thinreports/core.rb +0 -20
- data/lib/thinreports/generator/pdf/drawer.rb +0 -16
- data/tasks/doc.rake +0 -13
- data/tasks/test.rake +0 -56
- data/test/benchmark/basic_estimate.tlf +0 -1
- data/test/benchmark/bench_basic_estimate.rb +0 -95
- data/test/case/character_spacing/character_spacing.rb +0 -7
- data/test/case/character_spacing/character_spacing.tlf +0 -1
- data/test/case/dynamic_image/dynamic_image.rb +0 -41
- data/test/case/dynamic_image/dynamic_image.tlf +0 -1
- data/test/case/dynamic_style/dynamic_style.rb +0 -154
- data/test/case/dynamic_style/dynamic_style.tlf +0 -1
- data/test/case/dynamic_style/dynamic_style_in_list.tlf +0 -1
- data/test/case/eudc/eudc.rb +0 -20
- data/test/case/eudc/eudc.tlf +0 -1
- data/test/case/helper.rb +0 -29
- data/test/case/hidden_shapes/hidden_shapes.rb +0 -13
- data/test/case/hidden_shapes/hidden_shapes.tlf +0 -1
- data/test/case/list_events/list_events.rb +0 -32
- data/test/case/list_events/list_events.tlf +0 -1
- data/test/case/list_header_inheriting/list_header_inheriting.rb +0 -17
- data/test/case/list_header_inheriting/list_header_inheriting.tlf +0 -1
- data/test/case/list_manual_generation/list_manual_generation.rb +0 -22
- data/test/case/list_manual_generation/list_manual_generation.tlf +0 -1
- data/test/case/single_line_tblock/single_line_tblock.rb +0 -15
- data/test/case/single_line_tblock/single_line_tblock.tlf +0 -1
- data/test/case/tblock_overflow/tblock_overflow.rb +0 -20
- data/test/case/tblock_overflow/tblock_overflow.tlf +0 -1
- data/test/case/tblock_styles/tblock_styles.rb +0 -27
- data/test/case/tblock_styles/tblock_styles.tlf +0 -1
- data/test/case/text_align/text_align.rb +0 -9
- data/test/case/text_align/text_align.tlf +0 -1
- data/test/unit/core/ext/array_spec.rb +0 -29
- data/test/unit/core/ext/hash_spec.rb +0 -29
- data/test/unit/core/ext/object_spec.rb +0 -30
- data/test/unit/core/ordered_hash_spec.rb +0 -51
- data/test/unit/core/shape/base/test_interface.rb +0 -52
- data/test/unit/core/utils_spec.rb +0 -56
- data/test/unit/data/basic_layout1.tlf +0 -1
- data/test/unit/data/basic_layout2.tlf +0 -1
- data/test/unit/data/basic_list_layout.tlf +0 -1
- data/test/unit/data/basic_list_noheader_layout.tlf +0 -1
- data/test/unit/helper.rb +0 -65
- /data/{test/case → examples}/dynamic_image/img200x100.png +0 -0
- /data/{test/case → examples}/dynamic_image/img50x50.png +0 -0
- /data/{test/case → examples}/dynamic_style/image.png +0 -0
- /data/{test/case → examples}/eudc/eudc.ttf +0 -0
- /data/{resources/fonts → fonts}/IPA_Font_License_Agreement_v1.0.txt +0 -0
- /data/{resources/fonts → fonts}/ipag.ttf +0 -0
- /data/{resources/fonts → fonts}/ipagp.ttf +0 -0
- /data/{resources/fonts → fonts}/ipam.ttf +0 -0
- /data/{resources/fonts → fonts}/ipamp.ttf +0 -0
@@ -1,48 +1,47 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module Thinreports
|
4
4
|
module Core::Shape
|
5
|
-
|
5
|
+
|
6
6
|
class List::SectionInterface < Base::Interface
|
7
7
|
include Core::Shape::Manager::Target
|
8
|
-
|
8
|
+
|
9
9
|
undef_method :list
|
10
10
|
internal_delegators :height
|
11
|
-
|
12
|
-
# @param [
|
13
|
-
# @param [
|
11
|
+
|
12
|
+
# @param [Thinreports::Core::Shape::List::Page] parent
|
13
|
+
# @param [Thinreports::Core::Shape::List::SectionFormat] format
|
14
14
|
# @param [Symbol] section_name
|
15
15
|
def initialize(parent, format, section_name)
|
16
16
|
super(parent, format)
|
17
17
|
internal.section_name = section_name
|
18
|
-
|
18
|
+
|
19
19
|
initialize_manager(format) do |f|
|
20
20
|
Core::Shape::Interface(self, f)
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
24
|
-
# @param [
|
25
|
-
# @return [
|
26
|
-
# @private
|
23
|
+
|
24
|
+
# @param [Thinreports::Core::Shape::List::Page] parent
|
25
|
+
# @return [Thinreports::Core::Shape::List::SectionInterface]
|
27
26
|
def copy(parent)
|
28
27
|
new_sec = super
|
29
28
|
new_sec.internal.section_name = internal.section_name
|
30
|
-
|
29
|
+
|
31
30
|
manager.shapes.each do |id, shape|
|
32
31
|
new_sec.manager.shapes[id] = shape.copy(new_sec)
|
33
32
|
end
|
34
33
|
new_sec
|
35
34
|
end
|
36
|
-
|
35
|
+
|
37
36
|
private
|
38
|
-
|
37
|
+
|
39
38
|
# @param parent (see #initialize)
|
40
39
|
# @param format (see #initialize)
|
41
|
-
# @return [
|
40
|
+
# @return [Thinreports::Core::Shape::List::SectionInternal]
|
42
41
|
def init_internal(parent, format)
|
43
42
|
List::SectionInternal.new(parent, format)
|
44
43
|
end
|
45
44
|
end
|
46
|
-
|
45
|
+
|
47
46
|
end
|
48
47
|
end
|
@@ -1,33 +1,32 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module Thinreports
|
4
4
|
module Core::Shape
|
5
|
-
|
6
|
-
# @private
|
5
|
+
|
7
6
|
class List::SectionInternal < Base::Internal
|
8
7
|
format_delegators :height,
|
9
8
|
:relative_left,
|
10
9
|
:relative_top,
|
11
10
|
:svg_tag
|
12
|
-
|
11
|
+
|
13
12
|
# @return [Symbol]
|
14
13
|
attr_accessor :section_name
|
15
|
-
|
14
|
+
|
16
15
|
def style
|
17
16
|
@style ||= Style::Base.new(format)
|
18
17
|
end
|
19
|
-
|
18
|
+
|
20
19
|
# @param [Numeric] ry
|
21
20
|
def move_top_to(ry)
|
22
21
|
states[:relative_top] = ry
|
23
22
|
end
|
24
|
-
|
23
|
+
|
25
24
|
# @return [Array<Numeric>]
|
26
25
|
def relative_position
|
27
26
|
[relative_left,
|
28
27
|
relative_top + (states[:relative_top] || 0)]
|
29
28
|
end
|
30
29
|
end
|
31
|
-
|
30
|
+
|
32
31
|
end
|
33
32
|
end
|
@@ -1,34 +1,33 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module Thinreports
|
4
4
|
module Core::Shape
|
5
|
-
|
5
|
+
|
6
6
|
class List::Store < ::Struct
|
7
|
-
|
7
|
+
include Utils
|
8
|
+
|
8
9
|
def self.init(attrs)
|
9
10
|
new(attrs).new
|
10
11
|
end
|
11
|
-
|
12
|
-
# @private
|
12
|
+
|
13
13
|
def self.new(attrs)
|
14
14
|
super(*attrs.keys) do
|
15
15
|
@default_values = attrs.values
|
16
|
-
|
16
|
+
|
17
17
|
def self.default_values
|
18
|
-
@default_values
|
18
|
+
deep_copy(@default_values)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def initialize
|
24
24
|
super(*self.class.default_values)
|
25
25
|
end
|
26
|
-
|
27
|
-
# @private
|
26
|
+
|
28
27
|
def copy
|
29
28
|
self.class.new
|
30
29
|
end
|
31
30
|
end
|
32
|
-
|
31
|
+
|
33
32
|
end
|
34
33
|
end
|
@@ -1,28 +1,27 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module Thinreports
|
4
4
|
module Core::Shape
|
5
|
-
|
6
|
-
# @private
|
5
|
+
|
7
6
|
class Manager::Format < Core::Format::Base
|
8
7
|
# @return [Symbol, Integer]
|
9
8
|
attr_reader :identifier
|
10
|
-
|
11
|
-
config_reader :
|
12
|
-
|
9
|
+
|
10
|
+
config_reader layout: %w( svg )
|
11
|
+
|
13
12
|
def initialize(config, id = nil, &block)
|
14
13
|
super(config, &block)
|
15
14
|
@identifier = id || self.object_id
|
16
15
|
end
|
17
|
-
|
16
|
+
|
18
17
|
def find_shape(id)
|
19
18
|
shapes[id]
|
20
19
|
end
|
21
|
-
|
20
|
+
|
22
21
|
def shapes
|
23
|
-
@shapes ||=
|
22
|
+
@shapes ||= {}
|
24
23
|
end
|
25
24
|
end
|
26
|
-
|
25
|
+
|
27
26
|
end
|
28
|
-
end
|
27
|
+
end
|
@@ -1,15 +1,16 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module Thinreports
|
4
4
|
module Core::Shape
|
5
|
-
|
6
|
-
# @private
|
5
|
+
|
7
6
|
class Manager::Internal
|
7
|
+
include Utils
|
8
|
+
|
8
9
|
attr_reader :format
|
9
10
|
attr_reader :shapes
|
10
11
|
attr_reader :lists
|
11
|
-
|
12
|
-
# @param [
|
12
|
+
|
13
|
+
# @param [Thinreports::Core::Manager::Format] format
|
13
14
|
# @param [Proc] init_item_handler
|
14
15
|
def initialize(format, init_item_handler)
|
15
16
|
@format = format
|
@@ -17,13 +18,13 @@ module ThinReports
|
|
17
18
|
@lists = {}
|
18
19
|
@init_item_handler = init_item_handler
|
19
20
|
end
|
20
|
-
|
21
|
+
|
21
22
|
# @param [String, Symbol] id
|
22
|
-
# @return [
|
23
|
+
# @return [Thinreports::Core::Shape::Basic::Format]
|
23
24
|
def find_format(id)
|
24
25
|
format.find_shape(id.to_sym)
|
25
26
|
end
|
26
|
-
|
27
|
+
|
27
28
|
# @param [String, Symbol] id
|
28
29
|
# @param limit (see #valid_type?)
|
29
30
|
def find_item(id, limit = {})
|
@@ -39,28 +40,28 @@ module ThinReports
|
|
39
40
|
return nil
|
40
41
|
end
|
41
42
|
end
|
42
|
-
|
43
|
+
|
43
44
|
# @param [String, Symbol] id
|
44
|
-
# @return [
|
45
|
+
# @return [Thinreports::Core::Shape::Base::Interface, nil]
|
45
46
|
def final_shape(id)
|
46
47
|
# When shape was found in registry.
|
47
48
|
if shape = shapes[id]
|
48
49
|
return nil unless shape.visible?
|
49
|
-
|
50
|
+
|
50
51
|
# In the case of TextBlock or ImageBlock.
|
51
52
|
if shape.internal.type_of?(:block)
|
52
|
-
shape.internal.real_value
|
53
|
+
blank_value?(shape.internal.real_value) ? nil : shape
|
53
54
|
else
|
54
55
|
shape
|
55
56
|
end
|
56
57
|
# When shape was not found in registry.
|
57
58
|
elsif f = find_format(id)
|
58
59
|
return nil unless f.display?
|
59
|
-
|
60
|
+
|
60
61
|
case f.type
|
61
62
|
# In the case of TextBlock.
|
62
63
|
when TextBlock::TYPE_NAME
|
63
|
-
f.has_reference? || !f.value
|
64
|
+
f.has_reference? || !blank_value?(f.value) ? init_item(f) : nil
|
64
65
|
# In the case of ImageBlock, Return the nil constantly.
|
65
66
|
when ImageBlock::TYPE_NAME
|
66
67
|
nil
|
@@ -72,16 +73,16 @@ module ThinReports
|
|
72
73
|
nil
|
73
74
|
end
|
74
75
|
end
|
75
|
-
|
76
|
-
# @param [
|
76
|
+
|
77
|
+
# @param [Thinreports::Core::Shape::Basic::Format] format
|
77
78
|
def init_item(format)
|
78
79
|
@init_item_handler.call(format)
|
79
80
|
end
|
80
|
-
|
81
|
+
|
81
82
|
# @param [String] type
|
82
83
|
# @param [Hash] limit
|
83
|
-
# @option [String] :only
|
84
|
-
# @option [String] :except
|
84
|
+
# @option limit [String] :only
|
85
|
+
# @option limit [String] :except
|
85
86
|
# @return [Booldan]
|
86
87
|
def valid_type?(type, limit = {})
|
87
88
|
return true if limit.empty?
|
@@ -95,6 +96,6 @@ module ThinReports
|
|
95
96
|
end
|
96
97
|
end
|
97
98
|
end
|
98
|
-
|
99
|
+
|
99
100
|
end
|
100
|
-
end
|
101
|
+
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module Thinreports
|
4
4
|
module Core::Shape
|
5
|
-
|
5
|
+
|
6
6
|
module Manager::Target
|
7
|
-
|
7
|
+
include Utils
|
8
|
+
|
8
9
|
attr_reader :manager
|
9
|
-
|
10
|
+
|
10
11
|
# @example
|
11
12
|
# item(:title).value('Title').style(:fill, 'red')
|
12
13
|
#
|
@@ -14,72 +15,100 @@ module ThinReports
|
|
14
15
|
# value('Title')
|
15
16
|
# style(:fill, 'red')
|
16
17
|
# end
|
17
|
-
#
|
18
|
+
#
|
18
19
|
# item(:title) do |t|
|
19
20
|
# t.value('Title')
|
20
21
|
# t.style(:fill, 'red')
|
21
22
|
# end
|
23
|
+
# item(:list) # => Error: UnknownItemId
|
24
|
+
# item(:unknown_id) # => Error: UnknownItemId
|
22
25
|
# @param [String, Symbol] id
|
23
26
|
# @yield [item,]
|
24
|
-
# @yieldparam [
|
25
|
-
# @raise [
|
26
|
-
# @return [
|
27
|
+
# @yieldparam [Thinreports::Core::Shape::Base::Interface] item
|
28
|
+
# @raise [Thinreports::Errors::UnknownItemId]
|
29
|
+
# @return [Thinreports::Core::Shape::Base::Interface]
|
27
30
|
def item(id, &block)
|
28
|
-
shape = find_item(id, :
|
29
|
-
|
31
|
+
shape = find_item(id, except: Core::Shape::List::TYPE_NAME)
|
32
|
+
|
30
33
|
unless shape
|
31
|
-
raise
|
34
|
+
raise Thinreports::Errors::UnknownItemId.new(id)
|
32
35
|
else
|
33
|
-
|
36
|
+
call_block_in(shape, &block)
|
34
37
|
end
|
35
38
|
end
|
36
|
-
|
37
|
-
# @
|
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::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
|
38
68
|
def values(item_values)
|
39
69
|
item_values.each {|id, val| item(id).value(val)}
|
40
70
|
end
|
41
|
-
|
42
|
-
# @deprecated Please use the #values method instead.
|
43
|
-
# @see #values
|
44
|
-
def items(*args)
|
45
|
-
warn '[DEPRECATION] The #items method is deprecated. ' +
|
46
|
-
'Please use the #values method instead.'
|
47
|
-
values(*args)
|
48
|
-
end
|
49
|
-
|
71
|
+
|
50
72
|
# @param [Symbol, String] id
|
51
73
|
# @return [Boolean]
|
52
74
|
def item_exists?(id)
|
53
75
|
!!manager.find_format(id)
|
54
76
|
end
|
55
77
|
alias_method :exists?, :item_exists?
|
56
|
-
|
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
|
57
86
|
# @see #item
|
58
87
|
def list(id = nil, &block)
|
59
|
-
shape = find_item(id ||= :default, :
|
88
|
+
shape = find_item(id ||= :default, only: Core::Shape::List::TYPE_NAME)
|
60
89
|
|
61
90
|
unless shape
|
62
|
-
raise
|
91
|
+
raise Thinreports::Errors::UnknownItemId.new(id, 'List')
|
63
92
|
else
|
64
93
|
manager.lists[id.to_sym] ||= shape
|
65
|
-
|
94
|
+
call_block_in(shape, &block)
|
66
95
|
end
|
67
96
|
end
|
68
97
|
|
69
98
|
private
|
70
|
-
|
71
|
-
# @param format (see
|
99
|
+
|
100
|
+
# @param format (see Thinreports::Core::Shape::Manager::Internal#initialize)
|
72
101
|
# @yield [format] Handler for initialize item.
|
73
|
-
# @yieldparam [
|
102
|
+
# @yieldparam [Thinreports::Core::Shape::Basic::Format] format
|
74
103
|
def initialize_manager(format, &block)
|
75
104
|
@manager = Manager::Internal.new(format, block)
|
76
105
|
end
|
77
|
-
|
78
|
-
# @see
|
106
|
+
|
107
|
+
# @see Thinreports::Core::Shape::Manager::Internal#find_item
|
79
108
|
def find_item(id, limit = {})
|
80
109
|
manager.find_item(id, limit)
|
81
110
|
end
|
82
111
|
end
|
83
|
-
|
112
|
+
|
84
113
|
end
|
85
|
-
end
|
114
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Thinreports
|
4
|
+
module Core::Shape
|
5
|
+
|
6
|
+
class PageNumber::Format < Basic::Format
|
7
|
+
config_reader :overflow, :target, :box
|
8
|
+
config_reader default_format: %w( format )
|
9
|
+
|
10
|
+
def id
|
11
|
+
unless @id
|
12
|
+
@id = read('id')
|
13
|
+
@id = self.class.next_default_id if blank_value?(@id)
|
14
|
+
end
|
15
|
+
@id
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.next_default_id
|
19
|
+
@id_counter ||= 0
|
20
|
+
"__pageno#{@id_counter += 1}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Thinreports
|
4
|
+
module Core::Shape
|
5
|
+
|
6
|
+
class PageNumber::Interface < Basic::Interface
|
7
|
+
internal_delegators :reset_format
|
8
|
+
|
9
|
+
def format(*args)
|
10
|
+
if args.empty?
|
11
|
+
internal.read_format
|
12
|
+
else
|
13
|
+
internal.write_format(args.first)
|
14
|
+
self
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
# @see Thinreports::Core::Shape::Base::Interface#init_internal
|
21
|
+
def init_internal(parent, format)
|
22
|
+
PageNumber::Internal.new(parent, format)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Thinreports
|
4
|
+
module Core::Shape
|
5
|
+
|
6
|
+
class PageNumber::Internal < Basic::Internal
|
7
|
+
format_delegators :box
|
8
|
+
|
9
|
+
def read_format
|
10
|
+
states.key?(:format) ? states[:format] : format.default_format.dup
|
11
|
+
end
|
12
|
+
|
13
|
+
def reset_format
|
14
|
+
states.delete(:format)
|
15
|
+
end
|
16
|
+
|
17
|
+
def write_format(format)
|
18
|
+
states[:format] = format.to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
def build_format(page_no, page_count)
|
22
|
+
return '' if blank_value?(read_format)
|
23
|
+
|
24
|
+
if start_page_number > 1
|
25
|
+
page_no += start_page_number - 1
|
26
|
+
page_count += start_page_number - 1
|
27
|
+
end
|
28
|
+
|
29
|
+
read_format.dup.tap do |f|
|
30
|
+
f.gsub! '{page}', page_no.to_s
|
31
|
+
f.gsub! '{total}', page_count.to_s
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def style
|
36
|
+
@style ||= PageNumber::Style.new(format)
|
37
|
+
end
|
38
|
+
|
39
|
+
def for_report?
|
40
|
+
blank_value?(format.target)
|
41
|
+
end
|
42
|
+
|
43
|
+
def type_of?(type_name)
|
44
|
+
type_name == :pageno
|
45
|
+
end
|
46
|
+
|
47
|
+
def start_page_number
|
48
|
+
for_report? ? parent.report.start_page_number : 1
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class PageNumber::Style < Style::Text
|
53
|
+
accessible_styles.delete :valign
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Thinreports
|
4
|
+
module Core::Shape
|
5
|
+
|
6
|
+
module PageNumber
|
7
|
+
TYPE_NAME = 's-pageno'
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'thinreports/core/shape/page_number/format'
|
14
|
+
require 'thinreports/core/shape/page_number/internal'
|
15
|
+
require 'thinreports/core/shape/page_number/interface'
|