thinreports 0.6.0.pre3 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. data/README.rdoc +37 -32
  2. data/doc/yardoc_templates/default/layout/html/footer.erb +1 -1
  3. data/lib/thinreports.rb +2 -1
  4. data/lib/thinreports/config.rb +21 -0
  5. data/lib/thinreports/core/errors.rb +14 -1
  6. data/lib/thinreports/core/format/builder.rb +6 -1
  7. data/lib/thinreports/core/page.rb +6 -6
  8. data/lib/thinreports/core/shape.rb +8 -9
  9. data/lib/thinreports/core/shape/base/internal.rb +6 -12
  10. data/lib/thinreports/core/shape/basic.rb +3 -0
  11. data/lib/thinreports/core/shape/basic/block_format.rb +12 -0
  12. data/lib/thinreports/core/shape/basic/block_interface.rb +25 -0
  13. data/lib/thinreports/core/shape/basic/block_internal.rb +33 -0
  14. data/lib/thinreports/core/shape/basic/interface.rb +37 -11
  15. data/lib/thinreports/core/shape/basic/internal.rb +3 -12
  16. data/lib/thinreports/core/shape/image_block.rb +15 -0
  17. data/lib/thinreports/core/shape/image_block/format.rb +13 -0
  18. data/lib/thinreports/core/shape/image_block/interface.rb +19 -0
  19. data/lib/thinreports/core/shape/image_block/internal.rb +16 -0
  20. data/lib/thinreports/core/shape/list/events.rb +19 -2
  21. data/lib/thinreports/core/shape/list/manager.rb +17 -4
  22. data/lib/thinreports/core/shape/list/page.rb +2 -2
  23. data/lib/thinreports/core/shape/list/page_state.rb +4 -0
  24. data/lib/thinreports/core/shape/list/section_internal.rb +4 -0
  25. data/lib/thinreports/core/shape/manager/format.rb +1 -1
  26. data/lib/thinreports/core/shape/manager/internal.rb +24 -11
  27. data/lib/thinreports/core/shape/manager/target.rb +2 -2
  28. data/lib/thinreports/core/shape/style.rb +15 -0
  29. data/lib/thinreports/core/shape/style/base.rb +149 -0
  30. data/lib/thinreports/core/shape/style/basic.rb +17 -0
  31. data/lib/thinreports/core/shape/style/graphic.rb +60 -0
  32. data/lib/thinreports/core/shape/style/text.rb +138 -0
  33. data/lib/thinreports/core/shape/text/internal.rb +4 -0
  34. data/lib/thinreports/core/shape/text_block.rb +16 -0
  35. data/lib/thinreports/core/shape/{tblock → text_block}/format.rb +3 -3
  36. data/lib/thinreports/core/shape/{tblock → text_block}/formatter.rb +7 -7
  37. data/lib/thinreports/core/shape/{tblock → text_block}/formatter/basic.rb +1 -1
  38. data/lib/thinreports/core/shape/{tblock → text_block}/formatter/datetime.rb +1 -1
  39. data/lib/thinreports/core/shape/{tblock → text_block}/formatter/number.rb +1 -1
  40. data/lib/thinreports/core/shape/{tblock → text_block}/formatter/padding.rb +10 -8
  41. data/lib/thinreports/core/shape/{tblock → text_block}/interface.rb +2 -21
  42. data/lib/thinreports/core/shape/{tblock → text_block}/internal.rb +16 -10
  43. data/lib/thinreports/core/utils.rb +0 -8
  44. data/lib/thinreports/generator.rb +2 -2
  45. data/lib/thinreports/generator/configuration.rb +30 -0
  46. data/lib/thinreports/generator/pdf.rb +13 -10
  47. data/lib/thinreports/generator/pdf/configuration.rb +28 -0
  48. data/lib/thinreports/generator/pdf/document.rb +16 -56
  49. data/lib/thinreports/generator/pdf/document/draw_shape.rb +35 -17
  50. data/lib/thinreports/generator/pdf/document/font.rb +25 -9
  51. data/lib/thinreports/generator/pdf/document/graphics.rb +1 -1
  52. data/lib/thinreports/generator/pdf/document/graphics/attributes.rb +18 -4
  53. data/lib/thinreports/generator/pdf/document/graphics/basic.rb +1 -1
  54. data/lib/thinreports/generator/pdf/document/graphics/image.rb +18 -1
  55. data/lib/thinreports/generator/pdf/document/graphics/text.rb +29 -6
  56. data/lib/thinreports/generator/pdf/document/page.rb +70 -0
  57. data/lib/thinreports/generator/pdf/document/parse_color.rb +1 -1
  58. data/lib/thinreports/generator/pdf/document/parse_svg.rb +1 -1
  59. data/lib/thinreports/generator/pdf/drawer.rb +1 -1
  60. data/lib/thinreports/generator/pdf/drawer/base.rb +5 -7
  61. data/lib/thinreports/generator/pdf/drawer/list.rb +4 -4
  62. data/lib/thinreports/generator/pdf/drawer/list_section.rb +8 -3
  63. data/lib/thinreports/generator/pdf/drawer/page.rb +10 -3
  64. data/lib/thinreports/generator/pdf/prawn_ext.rb +16 -21
  65. data/lib/thinreports/layout/format.rb +2 -2
  66. data/lib/thinreports/layout/version.rb +2 -2
  67. data/lib/thinreports/report/base.rb +68 -31
  68. data/tasks/test.rake +48 -4
  69. data/test/benchmark/basic_estimate.tlf +1 -0
  70. data/test/benchmark/bench_basic_estimate.rb +95 -0
  71. data/test/case/character_spacing/character_spacing.rb +7 -0
  72. data/test/case/character_spacing/character_spacing.tlf +1 -0
  73. data/test/case/dynamic_image/dynamic_image.rb +41 -0
  74. data/test/case/dynamic_image/dynamic_image.tlf +1 -0
  75. data/test/case/dynamic_image/img200x100.png +0 -0
  76. data/test/case/dynamic_image/img50x50.png +0 -0
  77. data/test/case/dynamic_style/dynamic_style.rb +154 -0
  78. data/test/case/dynamic_style/dynamic_style.tlf +1 -0
  79. data/test/case/dynamic_style/dynamic_style_in_list.tlf +1 -0
  80. data/test/case/dynamic_style/image.png +0 -0
  81. data/test/case/eudc/eudc.rb +20 -0
  82. data/test/case/eudc/eudc.tlf +1 -0
  83. data/test/case/eudc/eudc.ttf +0 -0
  84. data/test/case/helper.rb +27 -0
  85. data/test/case/hidden_shapes/hidden_shapes.rb +13 -0
  86. data/test/case/hidden_shapes/hidden_shapes.tlf +1 -0
  87. data/test/case/list_events/list_events.rb +32 -0
  88. data/test/case/list_events/list_events.tlf +1 -0
  89. data/test/case/list_header_inheriting/list_header_inheriting.rb +19 -0
  90. data/test/case/list_header_inheriting/list_header_inheriting.tlf +1 -0
  91. data/test/case/list_manual_generation/list_manual_generation.rb +24 -0
  92. data/test/case/list_manual_generation/list_manual_generation.tlf +1 -0
  93. data/test/case/single_line_tblock/single_line_tblock.rb +15 -0
  94. data/test/case/single_line_tblock/single_line_tblock.tlf +1 -0
  95. data/test/case/tblock_styles/tblock_styles.rb +27 -0
  96. data/test/case/tblock_styles/tblock_styles.tlf +1 -0
  97. data/test/case/text_align/text_align.rb +9 -0
  98. data/test/case/text_align/text_align.tlf +1 -0
  99. data/test/unit/core/shape/base/test_internal.rb +65 -85
  100. data/test/unit/core/shape/basic/test_basic_format.rb +30 -0
  101. data/test/unit/core/shape/basic/test_basic_interface.rb +27 -0
  102. data/test/unit/core/shape/basic/test_basic_internal.rb +55 -0
  103. data/test/unit/core/shape/basic/test_interface.rb +84 -36
  104. data/test/unit/core/shape/basic/test_internal.rb +32 -24
  105. data/test/unit/core/shape/image_block/test_format.rb +58 -0
  106. data/test/unit/core/shape/image_block/test_interface.rb +23 -0
  107. data/test/unit/core/shape/image_block/test_internal.rb +28 -0
  108. data/test/unit/core/shape/list/test_events.rb +19 -11
  109. data/test/unit/core/shape/list/test_manager.rb +112 -0
  110. data/test/unit/core/shape/list/test_page.rb +57 -0
  111. data/test/unit/core/shape/list/test_section_format.rb +1 -1
  112. data/test/unit/core/shape/list/test_section_interface.rb +37 -30
  113. data/test/unit/core/shape/list/test_section_internal.rb +39 -14
  114. data/test/unit/core/shape/manager/test_format.rb +12 -18
  115. data/test/unit/core/shape/manager/test_internal.rb +127 -93
  116. data/test/unit/core/shape/manager/test_target.rb +63 -56
  117. data/test/unit/core/shape/styles/test_base.rb +219 -0
  118. data/test/unit/core/shape/styles/test_basic.rb +24 -0
  119. data/test/unit/core/shape/styles/test_graphic.rb +69 -0
  120. data/test/unit/core/shape/styles/test_text.rb +318 -0
  121. data/test/unit/core/shape/{tblock → text_block}/formatter/test_basic.rb +2 -2
  122. data/test/unit/core/shape/{tblock → text_block}/formatter/test_datetime.rb +2 -2
  123. data/test/unit/core/shape/{tblock → text_block}/formatter/test_number.rb +2 -2
  124. data/test/unit/core/shape/{tblock → text_block}/formatter/test_padding.rb +11 -6
  125. data/test/unit/core/shape/text_block/test_format.rb +160 -0
  126. data/test/unit/core/shape/{tblock → text_block}/test_formatter.rb +2 -2
  127. data/test/unit/core/shape/text_block/test_interface.rb +46 -0
  128. data/test/unit/core/shape/text_block/test_internal.rb +128 -0
  129. data/test/unit/core/test_shape.rb +31 -6
  130. data/test/unit/data/basic_layout1.tlf +1 -0
  131. data/test/unit/data/basic_layout2.tlf +1 -0
  132. data/test/unit/data/basic_list_layout.tlf +1 -0
  133. data/test/unit/generator/pdf/document/graphics/test_attributes.rb +81 -52
  134. data/test/unit/generator/pdf/document/graphics/test_text.rb +159 -0
  135. data/test/unit/generator/pdf/document/test_font.rb +21 -6
  136. data/test/unit/generator/pdf/document/test_graphics.rb +2 -2
  137. data/test/unit/generator/pdf/document/test_page.rb +95 -0
  138. data/test/unit/generator/pdf/document/test_parse_color.rb +2 -2
  139. data/test/unit/generator/pdf/test_configuration.rb +24 -0
  140. data/test/unit/generator/pdf/test_document.rb +28 -0
  141. data/test/unit/generator/test_configuration.rb +25 -0
  142. data/test/unit/generator/test_pdf.rb +19 -0
  143. data/test/unit/helper.rb +18 -0
  144. data/test/unit/layout/test_format.rb +24 -7
  145. data/test/unit/layout/test_version.rb +61 -27
  146. data/test/unit/report/test_base.rb +185 -89
  147. data/test/unit/test_config.rb +22 -0
  148. data/test/unit/test_report.rb +4 -4
  149. metadata +94 -43
  150. data/lib/thinreports/core/shape/tblock.rb +0 -16
  151. data/lib/thinreports/generator/pxd.rb +0 -75
  152. data/lib/thinreports/generator/pxd/helper.rb +0 -33
  153. data/lib/thinreports/generator/pxd/list_renderer.rb +0 -58
  154. data/lib/thinreports/generator/pxd/page_renderer.rb +0 -75
  155. data/tasks/clean.rake +0 -6
  156. data/test/unit/core/shape/tblock/test_format.rb +0 -125
  157. data/test/unit/core/shape/tblock/test_interface.rb +0 -40
  158. data/test/unit/core/shape/tblock/test_internal.rb +0 -139
@@ -1,69 +1,74 @@
1
1
  = ThinReports Generator
2
2
 
3
3
  ThinReports is Open Source Reporting Solution for Ruby.
4
- And it provide you these tools.
4
+ And it provides you these tools:
5
5
 
6
- * ThinReports Editor (GUI Layout Editor)
7
- * ThinReports Generator (Report Generation Interface for Ruby)
6
+ * ThinReports Editor (GUI Designer)
7
+ * ThinReports Generator (Report Generator for Ruby)
8
8
 
9
- Please refer to {Official Site}[http://www.thinreports.org/] and
10
- {Project Site}[http://osc.matsukei.net/projects/thinreports/wiki] for more details.
9
+ You can see more details:
10
+
11
+ * {Official Site}[http://www.thinreports.org/]
12
+ * {Project Site}[http://osc.matsukei.net/projects/thinreports/wiki]
11
13
 
12
14
  == Quick Start
13
15
 
14
16
  Getting started with ThinReports Generator can be as simple as:
15
17
 
16
- require 'thinreports'
18
+ require 'thinreports'
17
19
 
18
- report = ThinReports::Report.new :layout => 'report.tlf'
19
- report.start_new_page do
20
- page.item(:title).value('ThinReports')
21
- end
20
+ report = ThinReports::Report.new :layout => 'report.tlf'
21
+ report.start_new_page do
22
+ page.item(:title).value('ThinReports')
23
+ end
22
24
 
23
- report.generate_file(:pdf, 'report.pdf')
25
+ # :pdf is used as default when the type argument of a #generate_file is omitted.
26
+ report.generate_file('report.pdf')
24
27
 
25
28
  Or can be as:
26
-
27
- ThinReports::Report.generate_file(:pdf, 'report.pdf', :layout => 'report.tlf') do
28
- start_new_page
29
+
30
+ ThinReports::Report.generate_file(:pdf, 'report.pdf', :layout => 'report.tlf') do
31
+ start_new_page
29
32
 
30
- page.item(:title).value('ThinReports')
33
+ page.item(:title).value('ThinReports')
31
34
 
32
- start_new_page
35
+ start_new_page
33
36
 
34
- page.item(:title).value('ThinReports').style(:fill, 'red')
35
- end
36
-
37
+ page.item(:title).value('ThinReports').style(:color, '#ff0000')
38
+ end
39
+
37
40
  {Learn more}[http://osc.matsukei.net/projects/thinreports/wiki/Getting_Started].
38
41
 
39
- == Documentation
42
+ == Release Note
43
+
44
+ * {Changelog}[http://osc.matsukei.net/projects/thinreports/wiki/Changelog]
40
45
 
41
- We provide you a few useful resources to help you get started with ThinReports.
46
+ == Documentation
42
47
 
43
48
  * {Getting Started}[http://osc.matsukei.net/projects/thinreports/wiki/Getting_Started]
44
49
  * {Guide}[http://osc.matsukei.net/projects/thinreports/wiki/Guide]
45
- * {Roadmap}[http://osc.matsukei.net/projects/thinreports/roadmap]
46
- * {Changelog}[http://osc.matsukei.net/projects/thinreports/wiki/Changelog]
50
+ * {Examples}[http://osc.matsukei.net/projects/thinreports/wiki/Examples]
51
+ * {HowTos}[http://osc.matsukei.net/projects/thinreports/wiki/HowTos]
47
52
 
48
- == Source Code
53
+ == Project
49
54
 
50
- Please see {here}[http://osc.matsukei.net/projects/thinreports/wiki/Source_Code].
55
+ * {Roadmap}[http://osc.matsukei.net/projects/thinreports/roadmap]
56
+ * {Issue Tracker (Read-Only)}[http://osc.matsukei.net/projects/thinreports/issues]
57
+ * {Source Code}[http://osc.matsukei.net/projects/thinreports/wiki/Source_Code]
51
58
 
52
- == Community Support
59
+ == Help
53
60
 
54
61
  * {Open Forum}[http://osc.matsukei.net/projects/thinreports/boards]
55
- * {Issue Tracker (Read-Only)}[http://osc.matsukei.net/projects/thinreports/issues]
56
62
 
57
63
  == Dependencies
58
64
 
59
- * <code>prawn</code> <code>= 0.11.1</code>
60
- * <code>json</code> <code>>= 1.4.6</code>
61
- (Only for less than Ruby 1.9)
65
+ * <code>prawn</code> <code>= 0.12.0</code>
66
+ * <code>json</code> <code>>= 1.4.6</code> (Only for less than Ruby 1.9)
62
67
 
63
68
  === Note
64
69
 
65
70
  We tested on <code>Ruby 1.8.7</code> and <code>1.9.2</code>.
66
- We recommend <code>1.9.2+</code>.
71
+ But we recommend <code>1.9.2+</code>.
67
72
 
68
73
  == Resources
69
74
 
@@ -71,7 +76,7 @@ We recommend <code>1.9.2+</code>.
71
76
 
72
77
  ThinReports includes the following fonts.
73
78
 
74
- * IPAFonts: Copyright(c) 2003-2011 Information-technology Promotion Agency, Japan.
79
+ * IPAFonts: Copyright(c) 2003-2011 Information-technology Promotion Agency, Japan.
75
80
  Please see the lincense file {IPA_Font_License_Agreement_v1.0.txt}[http://ipafont.ipa.go.jp/ipa_font_license_v1.html].
76
81
 
77
82
  == License
@@ -7,4 +7,4 @@
7
7
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
8
8
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
9
9
  })();
10
- </script>
10
+ </script
@@ -2,9 +2,10 @@
2
2
 
3
3
  module ThinReports
4
4
  # The current version.
5
- VERSION = '0.6.0.pre3'
5
+ VERSION = '0.7.0'
6
6
  end
7
7
 
8
+ require 'thinreports/config'
8
9
  require 'thinreports/core'
9
10
  require 'thinreports/report'
10
11
  require 'thinreports/layout'
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+
3
+ module ThinReports
4
+ # @yield [config]
5
+ # @yieldparam [ThinReports::Configuration] config
6
+ def self.configure(&block)
7
+ block_exec_on(self.config, &block)
8
+ end
9
+
10
+ # @return [ThinReports::Configuration]
11
+ def self.config
12
+ @config ||= ThinReports::Configuration.new
13
+ end
14
+
15
+ class Configuration
16
+ # @return [ThinReports::Generator::Configuration]
17
+ def generator
18
+ @generator ||= ThinReports::Generator::Configuration.new
19
+ end
20
+ end
21
+ end
@@ -7,6 +7,10 @@ module ThinReports
7
7
  end
8
8
 
9
9
  class UnknownShapeStyleName < Basic
10
+ def initialize(style, availables)
11
+ super("The specified style name, '#{style}', cannot be used. " +
12
+ "The available styles are #{availables.map{|s| ":#{s}"}.join(', ')}.")
13
+ end
10
14
  end
11
15
 
12
16
  class UnknownShapeType < Basic
@@ -22,9 +26,15 @@ module ThinReports
22
26
  end
23
27
 
24
28
  class UnknownItemId < Basic
29
+ def initialize(id, item_type = 'Basic')
30
+ super("The layout does not have a #{item_type} Item with id '#{id}'.")
31
+ end
25
32
  end
26
33
 
27
34
  class DisabledListSection < Basic
35
+ def initialize(section)
36
+ super("The #{section} section is disabled.")
37
+ end
28
38
  end
29
39
 
30
40
  class UnknownEventType < Basic
@@ -34,6 +44,9 @@ module ThinReports
34
44
  end
35
45
 
36
46
  class UnknownGeneratorType < Basic
47
+ def initialize(type)
48
+ super("The specified generator type, '#{type}', was not found.")
49
+ end
37
50
  end
38
51
 
39
52
  class NoConfigurationFound < Basic
@@ -49,7 +62,7 @@ module ThinReports
49
62
  def initialize(filename, fileversion, required_rules)
50
63
  super("Generator #{ThinReports::VERSION} can not be built this file, " +
51
64
  "'#{File.basename(filename)}'." +
52
- "This file is created in the Editor of version '#{fileversion}', " +
65
+ "This file is updated in the Editor of version '#{fileversion}', " +
53
66
  "but Generator requires version #{required_rules}.")
54
67
  end
55
68
  end
@@ -1,6 +1,11 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'json'
3
+ begin
4
+ require 'json'
5
+ rescue LoadError
6
+ puts 'ThinReports requires json >= 1.4.6. ' +
7
+ 'Please `gem install json` and try again.'
8
+ end
4
9
 
5
10
  module ThinReports
6
11
  module Core::Format
@@ -5,8 +5,8 @@ module ThinReports
5
5
 
6
6
  class BlankPage
7
7
  # @return [Integer]
8
- attr_accessor :no
9
-
8
+ attr_accessor :no
9
+
10
10
  # @param [Boolean] count (nil)
11
11
  def initialize(count = nil)
12
12
  @count = count.nil? ? true : count
@@ -61,7 +61,7 @@ module ThinReports
61
61
  new_page.manager.shapes[id] = new_shape
62
62
 
63
63
  if new_shape.internal.type_of?(:list)
64
- new_page.manager.lists[id] = new_shape
64
+ new_page.manager.lists[id] = new_shape
65
65
  end
66
66
  end
67
67
  new_page
@@ -71,11 +71,11 @@ module ThinReports
71
71
  # @option options [:create, :copy] :at (:create)
72
72
  # @private
73
73
  def finalize(options = {})
74
- at = options[:at] || :create
75
-
74
+ at = options[:at] || :create
75
+
76
76
  # For list shapes.
77
77
  if at == :create
78
- manager.lists.values.each {|list| list.manager.finalize }
78
+ manager.lists.values.each {|list| list.manager.finalize }
79
79
  end
80
80
 
81
81
  @finalized = true
@@ -28,14 +28,11 @@ module ThinReports
28
28
  # @private
29
29
  def self.find_by_type(type)
30
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
31
+ when TextBlock::TYPE_NAME then TextBlock
32
+ when ImageBlock::TYPE_NAME then ImageBlock
33
+ when List::TYPE_NAME then List
34
+ when Text::TYPE_NAME then Text
35
+ when *Basic::TYPE_NAMES then Basic
39
36
  else
40
37
  raise ThinReports::Errors::UnknownShapeType
41
38
  end
@@ -45,9 +42,11 @@ module ThinReports
45
42
  end
46
43
  end
47
44
 
45
+ require 'thinreports/core/shape/style'
48
46
  require 'thinreports/core/shape/manager'
49
47
  require 'thinreports/core/shape/base'
50
48
  require 'thinreports/core/shape/basic'
51
49
  require 'thinreports/core/shape/text'
52
- require 'thinreports/core/shape/tblock'
50
+ require 'thinreports/core/shape/text_block'
51
+ require 'thinreports/core/shape/image_block'
53
52
  require 'thinreports/core/shape/list'
@@ -13,29 +13,27 @@ module ThinReports
13
13
  end
14
14
  private_class_method :format_delegators
15
15
 
16
- AVAILABLE_STYLES = [:fill, :stroke]
17
-
18
16
  attr_reader :parent
19
17
  attr_reader :format
20
- attr_accessor :attrs, :states
18
+ attr_writer :style
19
+ attr_accessor :states
21
20
 
22
21
  def initialize(parent, format)
23
22
  @parent = parent
24
23
  @format = format
25
-
26
24
  @states = {}
27
- @attrs = {}
25
+ @style = nil
28
26
 
29
27
  @finalized_attributes = nil
30
28
  end
31
29
 
32
- def attributes
33
- @finalized_attributes ||= (format.svg_attrs || {}).merge(attrs)
30
+ def style
31
+ raise NotImplementedError
34
32
  end
35
33
 
36
34
  def copy(new_parent, &block)
37
35
  new_internal = self.class.new(new_parent, format)
38
- new_internal.attrs = attrs.simple_deep_copy
36
+ new_internal.style = style.copy
39
37
  new_internal.states = states.simple_deep_copy
40
38
 
41
39
  block.call(new_internal) if block_given?
@@ -47,10 +45,6 @@ module ThinReports
47
45
  self
48
46
  end
49
47
 
50
- def available_style?(style_name)
51
- AVAILABLE_STYLES.include?(style_name)
52
- end
53
-
54
48
  def type_of?(type_name)
55
49
  raise NotImplementedError
56
50
  end
@@ -13,3 +13,6 @@ end
13
13
  require 'thinreports/core/shape/basic/format'
14
14
  require 'thinreports/core/shape/basic/internal'
15
15
  require 'thinreports/core/shape/basic/interface'
16
+ require 'thinreports/core/shape/basic/block_format'
17
+ require 'thinreports/core/shape/basic/block_internal'
18
+ require 'thinreports/core/shape/basic/block_interface'
@@ -0,0 +1,12 @@
1
+ # coding: utf-8
2
+
3
+ module ThinReports
4
+ module Core::Shape
5
+
6
+ # @private
7
+ class Basic::BlockFormat < Basic::Format
8
+ config_reader :value, :box
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+
3
+ module ThinReports
4
+ module Core::Shape
5
+
6
+ class Basic::BlockInterface < Basic::Interface
7
+ # @overload value(val)
8
+ # Set a val
9
+ # @param [Object] val
10
+ # @return [self]
11
+ # @overload value
12
+ # Return the value
13
+ # @return [Object]
14
+ def value(*args)
15
+ if args.empty?
16
+ internal.read_value
17
+ else
18
+ internal.write_value(args.first)
19
+ self
20
+ end
21
+ end
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+
3
+ module ThinReports
4
+ module Core::Shape
5
+
6
+ # @private
7
+ class Basic::BlockInternal < Basic::Internal
8
+ format_delegators :box
9
+
10
+ def style
11
+ @style ||= Style::Basic.new(format)
12
+ end
13
+
14
+ def read_value
15
+ states.key?(:value) ? states[:value] : format.value.dup
16
+ end
17
+ alias_method :value, :read_value
18
+
19
+ def write_value(val)
20
+ states[:value] = val
21
+ end
22
+
23
+ def real_value
24
+ read_value
25
+ end
26
+
27
+ def type_of?(type_name)
28
+ type_name == :block
29
+ end
30
+ end
31
+
32
+ end
33
+ end
@@ -4,27 +4,53 @@ module ThinReports
4
4
  module Core::Shape
5
5
 
6
6
  class Basic::Interface < Base::Interface
7
- internal_delegators :visible?, :id, :type
7
+ internal_delegators :type
8
+
9
+ # @return [String]
10
+ def id
11
+ internal.id.dup
12
+ end
8
13
 
9
14
  # @param [Boolean] visibility
10
15
  # @return [self]
11
16
  def visible(visibility)
12
- internal.visible(visibility)
17
+ internal.style.visible = visibility
13
18
  self
14
19
  end
15
20
 
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
21
+ # @return [Boolean]
22
+ def visible?
23
+ internal.style.visible
24
+ end
25
+
26
+ # @overload style(style_name)
27
+ # @param [Symbol] style_name
28
+ # @return [Object]
29
+ # @overload style(style_name, value)
30
+ # @param [Symbol] style_name
31
+ # @param [String, Symbol, Number, Array] value
32
+ # @return [self]
33
+ # @overload style(style_name, value1, value2)
34
+ # @param [Symbol] style_name
35
+ # @param [String, Number] value1
36
+ # @param [String, Number] value2
37
+ # @return [self]
38
+ def style(*args)
39
+ case args.length
40
+ when 1
41
+ internal.style[args.first]
42
+ when 2
43
+ internal.style[args.first] = args.last
44
+ self
45
+ when 3
46
+ internal.style[args.shift] = args
47
+ self
48
+ else
49
+ raise ArgumentError, '#style requires 1 or 2, 3 arguments'
22
50
  end
23
- internal.svg_attr(style_name, value)
24
- self
25
51
  end
26
52
 
27
- # @param [Hash] settings
53
+ # @param [Hash] settings :style_name => value
28
54
  # @return [self]
29
55
  def styles(settings)
30
56
  settings.each{ |args| style(*args) }