thinreports 0.6.0.pre3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. data/.yardopts +1 -0
  2. data/README.rdoc +100 -0
  3. data/Rakefile +10 -0
  4. data/doc/yardoc_templates/default/layout/html/footer.erb +10 -0
  5. data/lib/thinreports.rb +11 -0
  6. data/lib/thinreports/core.rb +20 -0
  7. data/lib/thinreports/core/errors.rb +58 -0
  8. data/lib/thinreports/core/events.rb +71 -0
  9. data/lib/thinreports/core/ext.rb +5 -0
  10. data/lib/thinreports/core/ext/array.rb +19 -0
  11. data/lib/thinreports/core/ext/hash.rb +19 -0
  12. data/lib/thinreports/core/ext/object.rb +25 -0
  13. data/lib/thinreports/core/format.rb +14 -0
  14. data/lib/thinreports/core/format/base.rb +93 -0
  15. data/lib/thinreports/core/format/builder.rb +65 -0
  16. data/lib/thinreports/core/ordered_hash.rb +39 -0
  17. data/lib/thinreports/core/page.rb +91 -0
  18. data/lib/thinreports/core/shape.rb +53 -0
  19. data/lib/thinreports/core/shape/base.rb +16 -0
  20. data/lib/thinreports/core/shape/base/interface.rb +38 -0
  21. data/lib/thinreports/core/shape/base/internal.rb +60 -0
  22. data/lib/thinreports/core/shape/basic.rb +15 -0
  23. data/lib/thinreports/core/shape/basic/format.rb +26 -0
  24. data/lib/thinreports/core/shape/basic/interface.rb +57 -0
  25. data/lib/thinreports/core/shape/basic/internal.rb +29 -0
  26. data/lib/thinreports/core/shape/list.rb +25 -0
  27. data/lib/thinreports/core/shape/list/configuration.rb +33 -0
  28. data/lib/thinreports/core/shape/list/events.rb +30 -0
  29. data/lib/thinreports/core/shape/list/format.rb +72 -0
  30. data/lib/thinreports/core/shape/list/manager.rb +209 -0
  31. data/lib/thinreports/core/shape/list/page.rb +118 -0
  32. data/lib/thinreports/core/shape/list/page_state.rb +40 -0
  33. data/lib/thinreports/core/shape/list/section_format.rb +32 -0
  34. data/lib/thinreports/core/shape/list/section_interface.rb +48 -0
  35. data/lib/thinreports/core/shape/list/section_internal.rb +29 -0
  36. data/lib/thinreports/core/shape/list/store.rb +34 -0
  37. data/lib/thinreports/core/shape/manager.rb +14 -0
  38. data/lib/thinreports/core/shape/manager/format.rb +28 -0
  39. data/lib/thinreports/core/shape/manager/internal.rb +87 -0
  40. data/lib/thinreports/core/shape/manager/target.rb +85 -0
  41. data/lib/thinreports/core/shape/tblock.rb +16 -0
  42. data/lib/thinreports/core/shape/tblock/format.rb +36 -0
  43. data/lib/thinreports/core/shape/tblock/formatter.rb +32 -0
  44. data/lib/thinreports/core/shape/tblock/formatter/basic.rb +38 -0
  45. data/lib/thinreports/core/shape/tblock/formatter/datetime.rb +21 -0
  46. data/lib/thinreports/core/shape/tblock/formatter/number.rb +49 -0
  47. data/lib/thinreports/core/shape/tblock/formatter/padding.rb +43 -0
  48. data/lib/thinreports/core/shape/tblock/interface.rb +52 -0
  49. data/lib/thinreports/core/shape/tblock/internal.rb +70 -0
  50. data/lib/thinreports/core/shape/text.rb +15 -0
  51. data/lib/thinreports/core/shape/text/format.rb +25 -0
  52. data/lib/thinreports/core/shape/text/interface.rb +16 -0
  53. data/lib/thinreports/core/shape/text/internal.rb +17 -0
  54. data/lib/thinreports/core/utils.rb +48 -0
  55. data/lib/thinreports/generator.rb +30 -0
  56. data/lib/thinreports/generator/base.rb +49 -0
  57. data/lib/thinreports/generator/pdf.rb +63 -0
  58. data/lib/thinreports/generator/pdf/document.rb +171 -0
  59. data/lib/thinreports/generator/pdf/document/draw_shape.rb +74 -0
  60. data/lib/thinreports/generator/pdf/document/font.rb +59 -0
  61. data/lib/thinreports/generator/pdf/document/graphics.rb +42 -0
  62. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +92 -0
  63. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +132 -0
  64. data/lib/thinreports/generator/pdf/document/graphics/image.rb +51 -0
  65. data/lib/thinreports/generator/pdf/document/graphics/text.rb +130 -0
  66. data/lib/thinreports/generator/pdf/document/parse_color.rb +51 -0
  67. data/lib/thinreports/generator/pdf/document/parse_svg.rb +102 -0
  68. data/lib/thinreports/generator/pdf/drawer.rb +16 -0
  69. data/lib/thinreports/generator/pdf/drawer/base.rb +56 -0
  70. data/lib/thinreports/generator/pdf/drawer/list.rb +39 -0
  71. data/lib/thinreports/generator/pdf/drawer/list_section.rb +46 -0
  72. data/lib/thinreports/generator/pdf/drawer/page.rb +101 -0
  73. data/lib/thinreports/generator/pdf/prawn_ext.rb +36 -0
  74. data/lib/thinreports/generator/pxd.rb +75 -0
  75. data/lib/thinreports/generator/pxd/helper.rb +33 -0
  76. data/lib/thinreports/generator/pxd/list_renderer.rb +58 -0
  77. data/lib/thinreports/generator/pxd/page_renderer.rb +75 -0
  78. data/lib/thinreports/layout.rb +17 -0
  79. data/lib/thinreports/layout/base.rb +78 -0
  80. data/lib/thinreports/layout/configuration.rb +27 -0
  81. data/lib/thinreports/layout/format.rb +77 -0
  82. data/lib/thinreports/layout/version.rb +43 -0
  83. data/lib/thinreports/report.rb +31 -0
  84. data/lib/thinreports/report/base.rb +160 -0
  85. data/lib/thinreports/report/events.rb +32 -0
  86. data/lib/thinreports/report/internal.rb +131 -0
  87. data/resources/fonts/IPA_Font_License_Agreement_v1.0.txt +117 -0
  88. data/resources/fonts/ipag.ttf +0 -0
  89. data/resources/fonts/ipagp.ttf +0 -0
  90. data/resources/fonts/ipam.ttf +0 -0
  91. data/resources/fonts/ipamp.ttf +0 -0
  92. data/tasks/clean.rake +6 -0
  93. data/tasks/doc.rake +13 -0
  94. data/tasks/test.rake +18 -0
  95. data/test/unit/core/ext/array_spec.rb +29 -0
  96. data/test/unit/core/ext/hash_spec.rb +29 -0
  97. data/test/unit/core/ext/object_spec.rb +30 -0
  98. data/test/unit/core/format/test_base.rb +148 -0
  99. data/test/unit/core/format/test_builder.rb +114 -0
  100. data/test/unit/core/ordered_hash_spec.rb +51 -0
  101. data/test/unit/core/shape/base/test_interface.rb +52 -0
  102. data/test/unit/core/shape/base/test_internal.rb +109 -0
  103. data/test/unit/core/shape/basic/test_format.rb +59 -0
  104. data/test/unit/core/shape/basic/test_interface.rb +70 -0
  105. data/test/unit/core/shape/basic/test_internal.rb +42 -0
  106. data/test/unit/core/shape/list/test_configuration.rb +52 -0
  107. data/test/unit/core/shape/list/test_events.rb +28 -0
  108. data/test/unit/core/shape/list/test_format.rb +71 -0
  109. data/test/unit/core/shape/list/test_page.rb +10 -0
  110. data/test/unit/core/shape/list/test_page_state.rb +31 -0
  111. data/test/unit/core/shape/list/test_section_format.rb +46 -0
  112. data/test/unit/core/shape/list/test_section_interface.rb +52 -0
  113. data/test/unit/core/shape/list/test_section_internal.rb +30 -0
  114. data/test/unit/core/shape/list/test_store.rb +41 -0
  115. data/test/unit/core/shape/manager/test_format.rb +40 -0
  116. data/test/unit/core/shape/manager/test_internal.rb +137 -0
  117. data/test/unit/core/shape/manager/test_target.rb +109 -0
  118. data/test/unit/core/shape/tblock/formatter/test_basic.rb +24 -0
  119. data/test/unit/core/shape/tblock/formatter/test_datetime.rb +47 -0
  120. data/test/unit/core/shape/tblock/formatter/test_number.rb +76 -0
  121. data/test/unit/core/shape/tblock/formatter/test_padding.rb +72 -0
  122. data/test/unit/core/shape/tblock/test_format.rb +125 -0
  123. data/test/unit/core/shape/tblock/test_formatter.rb +28 -0
  124. data/test/unit/core/shape/tblock/test_interface.rb +40 -0
  125. data/test/unit/core/shape/tblock/test_internal.rb +139 -0
  126. data/test/unit/core/shape/text/test_format.rb +73 -0
  127. data/test/unit/core/shape/text/test_internal.rb +21 -0
  128. data/test/unit/core/test_events.rb +91 -0
  129. data/test/unit/core/test_shape.rb +35 -0
  130. data/test/unit/core/utils_spec.rb +56 -0
  131. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +103 -0
  132. data/test/unit/generator/pdf/document/test_font.rb +54 -0
  133. data/test/unit/generator/pdf/document/test_graphics.rb +43 -0
  134. data/test/unit/generator/pdf/document/test_parse_color.rb +30 -0
  135. data/test/unit/generator/test_base.rb +51 -0
  136. data/test/unit/helper.rb +37 -0
  137. data/test/unit/layout/test_base.rb +92 -0
  138. data/test/unit/layout/test_configuration.rb +46 -0
  139. data/test/unit/layout/test_format.rb +104 -0
  140. data/test/unit/layout/test_version.rb +62 -0
  141. data/test/unit/report/test_base.rb +187 -0
  142. data/test/unit/report/test_events.rb +22 -0
  143. data/test/unit/report/test_internal.rb +234 -0
  144. data/test/unit/test_layout.rb +12 -0
  145. data/test/unit/test_report.rb +30 -0
  146. metadata +218 -0
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+
3
+ module ThinReports
4
+ module Core::Shape
5
+
6
+ # @private
7
+ class List::PageState < Basic::Internal
8
+ attr_reader :rows
9
+ attr_accessor :height
10
+ attr_accessor :header
11
+
12
+ def initialize(*args)
13
+ super(*args)
14
+
15
+ @rows = []
16
+ @header = nil
17
+ @height = 0
18
+ @finalized = false
19
+ end
20
+
21
+ def finalized?
22
+ @finalized
23
+ end
24
+
25
+ def finalized!
26
+ @finalized = true
27
+ end
28
+
29
+ def type_of?(type_name)
30
+ type_name == :list
31
+ end
32
+ end
33
+
34
+ # Alias to List::PageState.
35
+ # @see ThinReports::Core::Shape::List::PageState
36
+ # @private
37
+ List::Internal = List::PageState
38
+
39
+ end
40
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+
3
+ module ThinReports
4
+ module Core::Shape
5
+
6
+ # @private
7
+ class List::SectionFormat < Manager::Format
8
+ config_reader :height
9
+ config_reader :relative_left => %w( translate x ),
10
+ :relative_top => %w( translate y )
11
+
12
+ config_reader :layout => %w( svg content ),
13
+ :svg_tag => %w( svg tag ),
14
+ :svg_attrs => %w( svg attrs )
15
+
16
+ class << self
17
+ private
18
+
19
+ def build_internal(raw_format)
20
+ new(raw_format) do |f|
21
+ build_layout(f, :level => 2) do |type, shape_format|
22
+ Core::Shape::Format(type).build(shape_format)
23
+ end
24
+ clean(f.layout)
25
+ end
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,48 @@
1
+ # coding: utf-8
2
+
3
+ module ThinReports
4
+ module Core::Shape
5
+
6
+ class List::SectionInterface < Base::Interface
7
+ include Core::Shape::Manager::Target
8
+
9
+ undef_method :list
10
+ internal_delegators :height
11
+
12
+ # @param [ThinReports::Core::Shape::List::Page] parent
13
+ # @param [ThinReports::Core::Shape::List::SectionFormat] format
14
+ # @param [Symbol] section_name
15
+ def initialize(parent, format, section_name)
16
+ super(parent, format)
17
+ internal.section_name = section_name
18
+
19
+ initialize_manager(format) do |f|
20
+ Core::Shape::Interface(self, f)
21
+ end
22
+ end
23
+
24
+ # @param [ThinReports::Core::Shape::List::Page] parent
25
+ # @return [ThinReports::Core::Shape::List::SectionInterface]
26
+ # @private
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
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+
3
+ module ThinReports
4
+ module Core::Shape
5
+
6
+ # @private
7
+ class List::SectionInternal < Base::Internal
8
+ format_delegators :height,
9
+ :relative_left,
10
+ :relative_top,
11
+ :svg_tag
12
+
13
+ # @return [Symbol]
14
+ attr_accessor :section_name
15
+
16
+ # @param [Numeric] ry
17
+ def move_top_to(ry)
18
+ states[:relative_top] = ry
19
+ end
20
+
21
+ # @return [Array<Numeric>]
22
+ def relative_position
23
+ [relative_left,
24
+ relative_top + (states[:relative_top] || 0)]
25
+ end
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+
3
+ module ThinReports
4
+ module Core::Shape
5
+
6
+ class List::Store < ::Struct
7
+ # @private
8
+ def self.init(attrs)
9
+ new(attrs).new
10
+ end
11
+
12
+ # @private
13
+ def self.new(attrs)
14
+ super(*attrs.keys) do
15
+ @default_values = attrs.values
16
+
17
+ def self.default_values
18
+ @default_values.simple_deep_copy
19
+ end
20
+ end
21
+ end
22
+
23
+ def initialize
24
+ super(*self.class.default_values)
25
+ end
26
+
27
+ # @private
28
+ def copy
29
+ self.class.new
30
+ end
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,14 @@
1
+ # coding: utf-8
2
+
3
+ module ThinReports
4
+ module Core::Shape
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'
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+
3
+ module ThinReports
4
+ module Core::Shape
5
+
6
+ # @private
7
+ class Manager::Format < Core::Format::Base
8
+ # @return [Symbol, Integer]
9
+ attr_reader :identifier
10
+
11
+ config_reader :layout => %w( svg )
12
+
13
+ def initialize(config, id = nil, &block)
14
+ super(config, &block)
15
+ @identifier = id || self.object_id
16
+ end
17
+
18
+ def find_shape(id)
19
+ shapes && shapes[id]
20
+ end
21
+
22
+ def shapes
23
+ @shapes ||= ThinReports::Core::OrderedHash.new
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,87 @@
1
+ # coding: utf-8
2
+
3
+ module ThinReports
4
+ module Core::Shape
5
+
6
+ # @private
7
+ class Manager::Internal
8
+ attr_reader :format
9
+ attr_reader :shapes
10
+ attr_reader :lists
11
+
12
+ # @param [ThinReports::Core::Manager::Format] format
13
+ # @param [Proc] init_item_handler
14
+ def initialize(format, init_item_handler)
15
+ @format = format
16
+ @shapes = {}
17
+ @lists = {}
18
+ @init_item_handler = init_item_handler
19
+ end
20
+
21
+ # @param [String, Symbol] id
22
+ # @return [ThinReports::Core::Shape::Basic::Format]
23
+ def find_format(id)
24
+ format.find_shape(id.to_sym)
25
+ end
26
+
27
+ # @param [String, Symbol] id
28
+ # @param limit (see #valid_type?)
29
+ def find_item(id, limit = {})
30
+ id = id.to_sym
31
+ case
32
+ when shape = shapes[id]
33
+ return nil unless valid_type?(shape.type, limit)
34
+ shape
35
+ when sformat = find_format(id)
36
+ return nil unless valid_type?(sformat.type, limit)
37
+ shapes[id] = init_item(sformat)
38
+ else
39
+ return nil
40
+ end
41
+ end
42
+
43
+ # @param [String, Symbol] id
44
+ # @return [ThinReports::Core::Shape::Base::Interface, nil]
45
+ def final_shape(id)
46
+ if shape = shapes[id]
47
+ return shape.visible? ? shape : nil
48
+ end
49
+
50
+ sformat = find_format(id)
51
+ if sformat.display?
52
+ case sformat.type
53
+ when Tblock::TYPE_NAME
54
+ if sformat.has_reference? || !sformat.value.blank?
55
+ init_item(sformat)
56
+ end
57
+ else
58
+ init_item(sformat)
59
+ end
60
+ end
61
+ end
62
+
63
+ # @param [ThinReports::Core::Shape::Basic::Format] format
64
+ def init_item(format)
65
+ @init_item_handler.call(format)
66
+ end
67
+
68
+ # @param [String] type
69
+ # @param [Hash] limit
70
+ # @option [String] :only
71
+ # @option [String] :except
72
+ # @return [Booldan]
73
+ def valid_type?(type, limit = {})
74
+ return true if limit.empty?
75
+ case
76
+ when only = limit[:only]
77
+ type == only
78
+ when except = limit[:except]
79
+ type != except
80
+ else
81
+ raise ArgumentError
82
+ end
83
+ end
84
+ end
85
+
86
+ end
87
+ end
@@ -0,0 +1,85 @@
1
+ # coding: utf-8
2
+
3
+ module ThinReports
4
+ module Core::Shape
5
+
6
+ module Manager::Target
7
+ # @private
8
+ attr_reader :manager
9
+
10
+ # @example
11
+ # item(:title).value('Title').style(:fill, 'red')
12
+ #
13
+ # item(:title) do
14
+ # value('Title')
15
+ # style(:fill, 'red')
16
+ # end
17
+ #
18
+ # item(:title) do |t|
19
+ # t.value('Title')
20
+ # t.style(:fill, 'red')
21
+ # end
22
+ # @param [String, Symbol] id
23
+ # @yield [item,]
24
+ # @yieldparam [ThinReports::Core::Shape::Base::Interface] item
25
+ # @raise [ThinReports::Errors::UnknownItemId] If not found
26
+ # @return [ThinReports::Core::Shape::Base::Interface]
27
+ def item(id, &block)
28
+ shape = find_item(id, :except => Core::Shape::List::TYPE_NAME)
29
+
30
+ unless shape
31
+ raise ThinReports::Errors::UnknownItemId, id
32
+ else
33
+ block_exec_on(shape, &block)
34
+ end
35
+ end
36
+
37
+ # @param [Hash] item_values :id => value
38
+ def values(item_values)
39
+ item_values.each {|id, val| item(id).value(val)}
40
+ 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
+
50
+ # @param [Symbol, String] id
51
+ # @return [Boolean]
52
+ def item_exists?(id)
53
+ !!manager.find_format(id)
54
+ end
55
+ alias_method :exists?, :item_exists?
56
+
57
+ # @see #item
58
+ def list(id, &block)
59
+ shape = find_item(id, :only => Core::Shape::List::TYPE_NAME)
60
+
61
+ unless shape
62
+ raise ThinReports::Errors::UnknownItemId, id
63
+ else
64
+ manager.lists[id.to_sym] ||= shape
65
+ block_exec_on(shape, &block)
66
+ end
67
+ end
68
+
69
+ private
70
+
71
+ # @param format (see ThinReports::Core::Shape::Manager::Internal#initialize)
72
+ # @yield [format] Handler for initialize item.
73
+ # @yieldparam [ThinReports::Core::Shape::Basic::Format] format
74
+ def initialize_manager(format, &block)
75
+ @manager = Manager::Internal.new(format, block)
76
+ end
77
+
78
+ # @see ThinReports::Core::Shape::Manager::Internal#find_item
79
+ def find_item(id, limit = {})
80
+ manager.find_item(id, limit)
81
+ end
82
+ end
83
+
84
+ end
85
+ end
@@ -0,0 +1,16 @@
1
+ # coding: utf-8
2
+
3
+ module ThinReports
4
+ module Core::Shape
5
+
6
+ module Tblock
7
+ TYPE_NAME = 's-tblock'
8
+ end
9
+
10
+ end
11
+ end
12
+
13
+ require 'thinreports/core/shape/tblock/format'
14
+ require 'thinreports/core/shape/tblock/internal'
15
+ require 'thinreports/core/shape/tblock/interface'
16
+ require 'thinreports/core/shape/tblock/formatter'
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+
3
+ module ThinReports
4
+ module Core::Shape
5
+
6
+ # @private
7
+ class Tblock::Format < Basic::Format
8
+ config_reader :value
9
+ config_reader :ref_id => %w( ref-id )
10
+ config_reader :box
11
+ config_reader :format_base => %w( format base ),
12
+ :format_type => %w( format type ),
13
+ :format_datetime_format => %w( format datetime format ),
14
+ :format_number_delimiter => %w( format number delimiter ),
15
+ :format_number_precision => %w( format number precision ),
16
+ :format_padding_char => %w( format padding char ),
17
+ :format_padding_dir => %w( format padding direction )
18
+
19
+ config_checker 'true', :multiple
20
+ config_checker 'R', :format_padding_rdir => %w( format padding direction )
21
+
22
+ config_reader :format_padding_length => %w( format padding length ) do |len|
23
+ len.blank? ? 0 : len.to_i
24
+ end
25
+
26
+ config_reader :has_format? => %w( format type ) do |type|
27
+ %w( datetime number padding ).include?(type)
28
+ end
29
+
30
+ config_reader :has_reference? => %w( ref-id ) do |ref_id|
31
+ !ref_id.blank?
32
+ end
33
+ end
34
+
35
+ end
36
+ end