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,65 @@
1
+ # coding: utf-8
2
+
3
+ require 'json'
4
+
5
+ module ThinReports
6
+ module Core::Format
7
+
8
+ # @private
9
+ module Builder
10
+ def build(*args)
11
+ build_internal(*args)
12
+ rescue ThinReports::Errors::Basic => e
13
+ raise e
14
+ rescue => e
15
+ raise ThinReports::Errors::InvalidLayoutFormat
16
+ end
17
+
18
+ private
19
+
20
+ # @abstract
21
+ def build_internal(*args)
22
+ raise NotImplementedError
23
+ end
24
+
25
+ # @param [ThinReports::Core::Format::Base] format
26
+ # @param [Hash] options
27
+ def build_layout(format, options = {}, &block)
28
+ level = '-' * ((options[:level] || 1 ) - 1)
29
+
30
+ format.layout.gsub!(/<!--#{level}SHAPE(.*?)SHAPE#{level}-->/) do
31
+ shape_format = block.call(*parsed_format_and_shape_type($1))
32
+
33
+ format.shapes[shape_format.id.to_sym] = shape_format
34
+ shape_tag(shape_format)
35
+ end
36
+ end
37
+
38
+ # @param [String] svg
39
+ def clean(svg)
40
+ svg.gsub!(/<!--.*?-->/, '')
41
+ end
42
+
43
+ # @param [String] svg
44
+ def clean_with_attributes(svg)
45
+ clean(svg)
46
+ svg.gsub!(/ x\-[a-z\d\-]+?=".*?"/, '')
47
+ svg.gsub!(/ class=".*?"/, '')
48
+ end
49
+
50
+ def shape_tag(format)
51
+ %{<%= r(:"#{format.id}")%>}
52
+ end
53
+
54
+ def parsed_format_and_shape_type(json_string)
55
+ f = parse_json(json_string)
56
+ [ f['type'], f ]
57
+ end
58
+
59
+ def parse_json(json_string)
60
+ JSON.parse(json_string)
61
+ end
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+
3
+ module ThinReports
4
+ module Core
5
+
6
+ ruby_18 do
7
+ # @private
8
+ class OrderedHash < ::Hash
9
+ def initialize
10
+ @keys = []
11
+ super
12
+ end
13
+
14
+ def []=(key, value)
15
+ @keys << key unless member?(key)
16
+ super
17
+ end
18
+
19
+ def each
20
+ @keys.each {|key| yield(key, self[key])}
21
+ end
22
+
23
+ def each_key
24
+ @keys.each {|key| yield(key)}
25
+ end
26
+
27
+ def keys
28
+ @keys
29
+ end
30
+ end
31
+ end
32
+
33
+ ruby_19 do
34
+ # @private
35
+ OrderedHash = ::Hash
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,91 @@
1
+ # coding: utf-8
2
+
3
+ module ThinReports
4
+ module Core
5
+
6
+ class BlankPage
7
+ # @return [Integer]
8
+ attr_accessor :no
9
+
10
+ # @param [Boolean] count (nil)
11
+ def initialize(count = nil)
12
+ @count = count.nil? ? true : count
13
+ end
14
+
15
+ # @return [Boolean]
16
+ def count?
17
+ @count
18
+ end
19
+
20
+ # @return [Boolean] (true)
21
+ def blank?
22
+ true
23
+ end
24
+ end
25
+
26
+ class Page < BlankPage
27
+ include Core::Shape::Manager::Target
28
+
29
+ # @return [ThinReports::Report::Base]
30
+ # @private
31
+ attr_reader :report
32
+
33
+ # @return [ThinReports::Layout::Base]
34
+ attr_reader :layout
35
+
36
+ # @param [ThinReports::Report::Base] report
37
+ # @param [ThinReports::Layout::Base] layout
38
+ def initialize(report, layout)
39
+ super(true)
40
+
41
+ @report = report
42
+ @layout = layout
43
+ @finalized = false
44
+
45
+ initialize_manager(layout.format) do |f|
46
+ Core::Shape::Interface(self, f)
47
+ end
48
+ end
49
+
50
+ # @return [Boolean] (false)
51
+ def blank?
52
+ false
53
+ end
54
+
55
+ # @private
56
+ def copy
57
+ new_page = self.class.new(report, layout)
58
+
59
+ manager.shapes.each do |id, shape|
60
+ new_shape = shape.copy(new_page)
61
+ new_page.manager.shapes[id] = new_shape
62
+
63
+ if new_shape.internal.type_of?(:list)
64
+ new_page.manager.lists[id] = new_shape
65
+ end
66
+ end
67
+ new_page
68
+ end
69
+
70
+ # @param [Hash] options
71
+ # @option options [:create, :copy] :at (:create)
72
+ # @private
73
+ def finalize(options = {})
74
+ at = options[:at] || :create
75
+
76
+ # For list shapes.
77
+ if at == :create
78
+ manager.lists.values.each {|list| list.manager.finalize }
79
+ end
80
+
81
+ @finalized = true
82
+ end
83
+
84
+ # @private
85
+ def finalized?
86
+ @finalized
87
+ end
88
+ end
89
+
90
+ end
91
+ end
@@ -0,0 +1,53 @@
1
+ # coding: utf-8
2
+
3
+ module ThinReports
4
+ module Core
5
+
6
+ module Shape
7
+ # @private
8
+ def Interface(parent, format)
9
+ find_by_type(format.type)::Interface.new(parent, format)
10
+ end
11
+
12
+ # @private
13
+ def Format(type)
14
+ find_by_type(type)::Format
15
+ end
16
+
17
+ # @private
18
+ def Configuration(type)
19
+ klass = find_by_type(type)
20
+ unless klass.const_defined?(:Configuration)
21
+ raise ThinReports::Errors::NoConfigurationFound, type
22
+ end
23
+ klass.const_get(:Configuration)
24
+ end
25
+
26
+ module_function :Interface, :Format, :Configuration
27
+
28
+ # @private
29
+ def self.find_by_type(type)
30
+ case type
31
+ when Tblock::TYPE_NAME
32
+ Tblock
33
+ when List::TYPE_NAME
34
+ List
35
+ when Text::TYPE_NAME
36
+ Text
37
+ when *Basic::TYPE_NAMES
38
+ Basic
39
+ else
40
+ raise ThinReports::Errors::UnknownShapeType
41
+ end
42
+ end
43
+ end
44
+
45
+ end
46
+ end
47
+
48
+ require 'thinreports/core/shape/manager'
49
+ require 'thinreports/core/shape/base'
50
+ require 'thinreports/core/shape/basic'
51
+ require 'thinreports/core/shape/text'
52
+ require 'thinreports/core/shape/tblock'
53
+ require 'thinreports/core/shape/list'
@@ -0,0 +1,16 @@
1
+ # coding: utf-8
2
+
3
+ require 'forwardable'
4
+
5
+ module ThinReports
6
+ module Core::Shape
7
+
8
+ # @private
9
+ module Base
10
+ end
11
+
12
+ end
13
+ end
14
+
15
+ require 'thinreports/core/shape/base/internal'
16
+ require 'thinreports/core/shape/base/interface'
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+
3
+ module ThinReports
4
+ module Core::Shape
5
+
6
+ # @private
7
+ # @abstract
8
+ class Base::Interface
9
+ extend ::Forwardable
10
+
11
+ def self.internal_delegators(*args)
12
+ def_delegators :internal, *args
13
+ end
14
+ private_class_method :internal_delegators
15
+
16
+ attr_reader :internal
17
+
18
+ def initialize(parent, format, internal = nil)
19
+ @internal = internal || init_internal(parent, format)
20
+ end
21
+
22
+ def copy(parent)
23
+ self.class.new(parent, internal.format, internal.copy(parent))
24
+ end
25
+
26
+ private
27
+
28
+ # @param [ThinReports::Core::Page, ThinReports::Core::Shape::List::SectionInterface] parent
29
+ # @param [ThinReports::Core::Shape::Basic::Format] format
30
+ # @return [ThinReports::Core::Shape::Basic::Internal]
31
+ # @abstract
32
+ def init_internal(parent, format)
33
+ raise NotImplementedError
34
+ end
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,60 @@
1
+ # coding: utf-8
2
+
3
+ module ThinReports
4
+ module Core::Shape
5
+
6
+ # @private
7
+ # @abstract
8
+ class Base::Internal
9
+ extend ::Forwardable
10
+
11
+ def self.format_delegators(*args)
12
+ def_delegators :format, *args
13
+ end
14
+ private_class_method :format_delegators
15
+
16
+ AVAILABLE_STYLES = [:fill, :stroke]
17
+
18
+ attr_reader :parent
19
+ attr_reader :format
20
+ attr_accessor :attrs, :states
21
+
22
+ def initialize(parent, format)
23
+ @parent = parent
24
+ @format = format
25
+
26
+ @states = {}
27
+ @attrs = {}
28
+
29
+ @finalized_attributes = nil
30
+ end
31
+
32
+ def attributes
33
+ @finalized_attributes ||= (format.svg_attrs || {}).merge(attrs)
34
+ end
35
+
36
+ def copy(new_parent, &block)
37
+ new_internal = self.class.new(new_parent, format)
38
+ new_internal.attrs = attrs.simple_deep_copy
39
+ new_internal.states = states.simple_deep_copy
40
+
41
+ block.call(new_internal) if block_given?
42
+ new_internal
43
+ end
44
+
45
+ def switch_parent!(new_parent)
46
+ @parent = new_parent
47
+ self
48
+ end
49
+
50
+ def available_style?(style_name)
51
+ AVAILABLE_STYLES.include?(style_name)
52
+ end
53
+
54
+ def type_of?(type_name)
55
+ raise NotImplementedError
56
+ end
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,15 @@
1
+ # coding: utf-8
2
+
3
+ module ThinReports
4
+ module Core::Shape
5
+
6
+ module Basic
7
+ TYPE_NAMES = %w( s-line s-rect s-ellipse s-image )
8
+ end
9
+
10
+ end
11
+ end
12
+
13
+ require 'thinreports/core/shape/basic/format'
14
+ require 'thinreports/core/shape/basic/internal'
15
+ require 'thinreports/core/shape/basic/interface'
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+
3
+ module ThinReports
4
+ module Core::Shape
5
+
6
+ # @private
7
+ class Basic::Format < Core::Format::Base
8
+ config_reader :type, :id
9
+ config_reader :svg_tag => %w( svg tag ),
10
+ :svg_attrs => %w( svg attrs )
11
+
12
+ config_checker 'true', :display
13
+
14
+ class << self
15
+ private
16
+
17
+ # @param [Hash] raw_format
18
+ # @return [ThinReports::Core::Shape::Basic::Format]
19
+ def build_internal(raw_format)
20
+ new(raw_format)
21
+ end
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,57 @@
1
+ # coding: utf-8
2
+
3
+ module ThinReports
4
+ module Core::Shape
5
+
6
+ class Basic::Interface < Base::Interface
7
+ internal_delegators :visible?, :id, :type
8
+
9
+ # @param [Boolean] visibility
10
+ # @return [self]
11
+ def visible(visibility)
12
+ internal.visible(visibility)
13
+ self
14
+ end
15
+
16
+ # @param [Symbol] style_name
17
+ # @param [String] value
18
+ # @return [self]
19
+ def style(style_name, value)
20
+ unless internal.available_style?(style_name)
21
+ raise ThinReports::Errors::UnknownShapeStyleName
22
+ end
23
+ internal.svg_attr(style_name, value)
24
+ self
25
+ end
26
+
27
+ # @param [Hash] settings
28
+ # @return [self]
29
+ def styles(settings)
30
+ settings.each{ |args| style(*args) }
31
+ self
32
+ end
33
+
34
+ # @see #visible
35
+ # @return [self]
36
+ def hide
37
+ visible(false)
38
+ self
39
+ end
40
+
41
+ # @see #visible
42
+ # @return [self]
43
+ def show
44
+ visible(true)
45
+ self
46
+ end
47
+
48
+ private
49
+
50
+ # @see ThinReports::Core::Shape::Base::Interface#init_internal
51
+ def init_internal(parent, format)
52
+ Basic::Internal.new(parent, format)
53
+ end
54
+ end
55
+
56
+ end
57
+ end