ruport 0.5.2 → 0.5.3

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.
data/CHANGELOG CHANGED
@@ -1,4 +1,22 @@
1
- Tnghe current version of Ruby Reports is 0.5.2
1
+ Tnghe current version of Ruby Reports is 0.5.3
2
+
3
+ changes since 0.5.2
4
+
5
+ - Fixed a bug in Format Engine which required a data attribute to be specified.
6
+ (will still provide an accessor for this, but no more do you *need* it)
7
+
8
+ - Fixed a bug in rope's build.rb that prevented generation of multiple reports.
9
+
10
+ - Fixed a bug in the way reorder() was working that was causing many
11
+ unneccessary copies of column_names to be made
12
+
13
+ - Fixed a bug in TextPlugin that caused it to throw an error when trying to
14
+ print an empty table. (Now returns empty string)
15
+
16
+ - Since Plugin#rendering_options and Plugin#options serve a different purpose
17
+ and when combined, cause problems, they have been split out into two different
18
+ instance variables. This does not effect their intended use from the
19
+ interface side.
2
20
 
3
21
  changes since 0.5.1
4
22
 
data/Rakefile CHANGED
@@ -23,7 +23,7 @@ end
23
23
 
24
24
  spec = Gem::Specification.new do |spec|
25
25
  spec.name = LEAN ? "lean-ruport" : "ruport"
26
- spec.version = "0.5.2"
26
+ spec.version = "0.5.3"
27
27
  spec.platform = Gem::Platform::RUBY
28
28
  spec.summary = "A generalized Ruby report generation and templating engine."
29
29
  spec.files = Dir.glob("{examples,lib,test,bin}/**/**/**/*") +
data/TODO CHANGED
@@ -1,5 +1,4 @@
1
1
  = TODO
2
2
 
3
3
  Any future plans are available on Ruports Trac website
4
-
5
- http://stonecode.svnrepository.com/ruport/trac.cgi
4
+ = http://stonecode.svnrepository.com/ruport/trac.cgi
data/bin/rope CHANGED
@@ -48,7 +48,7 @@ class_name = format_class_name(ARGV[1])
48
48
  exit if File.exist? "app/reports/#{ARGV[1]}.rb"
49
49
  if ARGV[0].eql? "report"
50
50
  File.open("app/reports.rb", "a") { |f|
51
- f << "require \"app/reports/#{ARGV[1]}\""
51
+ f.puts("require \"app/reports/#{ARGV[1]}\"")
52
52
  }
53
53
  REP = <<EOR
54
54
  begin; require "rubygems"; rescue LoadError; end
@@ -139,12 +139,7 @@ module Ruport::Data
139
139
 
140
140
  # Same as Record#reorder but is destructive
141
141
  def reorder!(*indices)
142
- indices = indices[0] if indices[0].kind_of?(Array)
143
- indices.each do |i|
144
- self[i] rescue raise ArgumentError,
145
- "you may have specified an invalid column"
146
- end
147
- @data = indices.map { |i| self[i] }
142
+ indices = reorder_data!(*indices)
148
143
  if @attributes
149
144
  if indices.all? { |e| e.kind_of? Integer }
150
145
  @attributes = indices.map { |i| @attributes[i] }
@@ -153,6 +148,17 @@ module Ruport::Data
153
148
  end
154
149
  end; self
155
150
  end
151
+
152
+ def reorder_data!(*indices)
153
+ indices = indices[0] if indices[0].kind_of?(Array)
154
+ indices.each do |i|
155
+ self[i] rescue raise ArgumentError,
156
+ "you may have specified an invalid column"
157
+ end
158
+ @data = indices.map { |i| self[i] }
159
+ return indices;
160
+ end
161
+
156
162
 
157
163
  # Makes a fresh copy of the Record
158
164
  def dup
@@ -107,13 +107,17 @@ module Ruport::Data
107
107
  def reorder!(*indices)
108
108
  indices = indices[0] if indices[0].kind_of? Array
109
109
  if @column_names
110
- @column_names = if indices.all? { |i| i.kind_of? Integer }
110
+ x = if indices.all? { |i| i.kind_of? Integer }
111
111
  indices.map { |i| @column_names[i] }
112
112
  else
113
113
  indices
114
114
  end
115
+ @column_names = x
115
116
  end
116
- @data.each { |r| r.reorder! *indices }; self
117
+ @data.each { |r|
118
+ r.reorder_data! *indices
119
+ r.attributes = @column_names
120
+ }; self
117
121
  end
118
122
 
119
123
  # Returns a copy of the table with its columns in the requested order.
@@ -1,6 +1,6 @@
1
1
  module Ruport
2
2
  class Format::Engine
3
- class Format::Engine::Invoice < Ruport::Format::Engine
3
+ class Invoice < Ruport::Format::Engine
4
4
 
5
5
  # order meta data
6
6
  attributes [ :customer_info, :company_info,
@@ -64,7 +64,7 @@ module Ruport
64
64
 
65
65
  def render
66
66
  raise "No plugin specified" unless plugin
67
- active_plugin.data = data.dup
67
+ active_plugin.data = data.dup if data
68
68
  if active_plugin.respond_to? :init_plugin_helper
69
69
  active_plugin.init_plugin_helper(self)
70
70
  end
@@ -2,8 +2,9 @@ module Ruport
2
2
  class Format::Plugin
3
3
  class HTMLPlugin < Format::Plugin
4
4
 
5
- rendering_options :red_cloth_enabled => true, :erb_enabled => true
6
-
5
+ rendering_options :red_cloth_enabled => true,
6
+ :erb_enabled => true
7
+
7
8
  renderer :document
8
9
 
9
10
  renderer :table do
@@ -8,6 +8,7 @@ module Ruport
8
8
  renderer :table do
9
9
  require "ruport/system_extensions"
10
10
 
11
+ return "" if data.length == 0;
11
12
  th = "#{rendered_field_names}#{hr}"
12
13
 
13
14
  data.each { |r|
@@ -28,6 +29,7 @@ module Ruport
28
29
  end
29
30
 
30
31
  format_field_names do
32
+ return "" if data.length == 0;
31
33
  data.column_names.each_with_index { |f,i|
32
34
  data.column_names[i] = f.to_s.center(max_col_width(i))
33
35
  }
@@ -50,9 +52,8 @@ module Ruport
50
52
  action :table_width do
51
53
  f = data.column_names if data.respond_to? :column_names
52
54
  d = Data::Table.new:column_names => f, :data => data
53
-
55
+
54
56
  f = d[0].attributes || (0...d[0].length)
55
-
56
57
  f.inject(0) { |s,e| s + max_col_width(e) }
57
58
  end
58
59
 
@@ -60,9 +60,9 @@ module Ruport
60
60
  end
61
61
 
62
62
  def rendering_options(hash={})
63
- @options ||= {}
64
- @options.merge!(hash)
65
- @options.dup
63
+ @rendering_options ||= {}
64
+ @rendering_options.merge!(hash)
65
+ @rendering_options.dup
66
66
  end
67
67
 
68
68
  attr_accessor :rendered_field_names
data/lib/ruport.rb CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  module Ruport
14
14
 
15
- VERSION = "0.5.2"
15
+ VERSION = "0.5.3"
16
16
 
17
17
  # Ruports logging and error interface.
18
18
  # Can generate warnings or raise fatal errors
@@ -1,7 +1,13 @@
1
1
  require 'ruport'
2
- require 'rubygems' rescue LoadError nil
2
+ begin; require 'rubygems'; rescue LoadError; nil; end
3
3
  require 'test/unit'
4
4
 
5
+ class Naked < Ruport::Format::Engine
6
+ alias_engine Naked, :naked_engine
7
+ Ruport::Format.build_interface_for Naked, :naked
8
+ end
9
+
10
+
5
11
  class MockPlugin < Ruport::Format::Plugin
6
12
 
7
13
  renderer(:table) { "#{rendered_field_names}#{data}" }
@@ -24,9 +30,39 @@ class MockPlugin < Ruport::Format::Plugin
24
30
  eng.rewrite_column(0) { "a" } if apple
25
31
  }
26
32
 
33
+ helper(:init_plugin) { |eng|
34
+ eng.options ||= {}
35
+ eng.options = options.merge!(:init_ran => true)
36
+ }
37
+
27
38
  plugin_name :mock
28
39
  register_on :table_engine
29
40
  register_on :document_engine
41
+ register_on :naked_engine
42
+
43
+ end
44
+
45
+ class TestFormatEngine < Test::Unit::TestCase
46
+
47
+ def test_no_data_required
48
+ assert_nothing_raised {
49
+ Ruport::Format.naked_object(:plugin => :mock).render
50
+ }
51
+ end
52
+
53
+ def test_init_plugin_helper
54
+ a = Ruport::Format.naked_object(:plugin => :mock)
55
+ a.render
56
+ assert a.options[:init_ran]
57
+ end
58
+
59
+ def test_options_hash
60
+ a = Ruport::Format.naked_object(:plugin => :mock, :data => [1,2,3])
61
+ assert(a.respond_to?(:options))
62
+ assert(a.active_plugin.respond_to?(:options))
63
+ a.render
64
+ assert_equal a.options, a.active_plugin.options
65
+ end
30
66
 
31
67
  end
32
68
 
data/test/test_plugin.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require "test/unit"
2
2
  require "ruport"
3
- require "rubygems" rescue LoadError nil
3
+ begin; require "rubygems"; rescue LoadError; nil; end
4
4
 
5
5
  include Ruport
6
6
 
@@ -29,6 +29,8 @@ class TSVPlugin < Format::Plugin
29
29
  register_on :invoice_engine
30
30
  register_on :document_engine
31
31
 
32
+ rendering_options :boring => :true
33
+
32
34
  end
33
35
 
34
36
  class TestPlugin < Test::Unit::TestCase
@@ -44,8 +46,18 @@ class TestPlugin < Test::Unit::TestCase
44
46
  assert_nothing_raised { d.baz }
45
47
  assert_raise(NoMethodError) { i.foo }
46
48
  assert_raise(NoMethodError) { d.foo }
47
- assert_raise(NoMethodError) { d.bar }
49
+ assert_raise(NoMethodError) { d.bar }
50
+ end
51
+
52
+ def test_rendering_options
53
+ t = Ruport::Format.table_object(:data => [[1,2]], :plugin => :tsv)
54
+ assert t.active_plugin.respond_to?(:options)
55
+ assert t.active_plugin.respond_to?(:rendering_options)
56
+ assert t.active_plugin.rendering_options[:boring]
57
+ assert_nil t.active_plugin.options
58
+ assert_nil t.options
48
59
  end
60
+
49
61
  end
50
62
 
51
63
  class CSVPluginTest < Test::Unit::TestCase
@@ -224,6 +236,12 @@ class TextPluginTest < Test::Unit::TestCase
224
236
  a = Format.table_object :plugin => :text, :data => [[1,2],[300,4]]
225
237
  assert_equal(nil,a.active_plugin.right_margin)
226
238
  end
239
+
240
+ def test_graceful_failure_on_empty_table
241
+ assert_nothing_raised { [].to_table.to_text }
242
+ assert_nothing_raised { [].to_table(%w[a b c]).to_text }
243
+ end
244
+
227
245
 
228
246
  end
229
247
 
data/test/test_table.rb CHANGED
@@ -53,8 +53,12 @@ class TestTable < Test::Unit::TestCase
53
53
 
54
54
  b = [[1,2,3],[4,5,6]].to_table(%w[a b c]).reorder(%w[a c])
55
55
  rows = [[1,3],[4,6]]
56
- b.each { |r| assert_equal rows.shift, r.data
57
- assert_equal %w[a c], r.attributes }
56
+ b.each { |r|
57
+ assert_equal rows.shift, r.data
58
+ assert_equal %w[a c], r.attributes
59
+ assert_equal b.column_names.object_id,
60
+ r.instance_eval{@attributes}.object_id
61
+ }
58
62
  end
59
63
 
60
64
  def test_append_column
data/test/unit.log CHANGED
@@ -5,3 +5,108 @@ F, [2006-09-02T18:29:02.139771 #3218] FATAL -- : no block given!
5
5
  F, [2006-09-03T11:57:39.721854 #4421] FATAL -- : Missing host for mailer bar
6
6
  F, [2006-09-03T11:57:39.723273 #4421] FATAL -- : Missing DSN for source foo!
7
7
  F, [2006-09-03T11:57:41.224266 #4421] FATAL -- : no block given!
8
+ F, [2006-09-06T02:05:31.162211 #2279] FATAL -- : Missing host for mailer bar
9
+ F, [2006-09-06T02:05:31.186639 #2279] FATAL -- : Missing DSN for source foo!
10
+ F, [2006-09-06T02:05:32.685959 #2279] FATAL -- : no block given!
11
+ F, [2006-09-06T02:07:29.461513 #2299] FATAL -- : Missing host for mailer bar
12
+ F, [2006-09-06T02:07:29.462790 #2299] FATAL -- : Missing DSN for source foo!
13
+ F, [2006-09-06T02:07:30.834786 #2299] FATAL -- : no block given!
14
+ F, [2006-09-06T02:07:39.501562 #2307] FATAL -- : Missing host for mailer bar
15
+ F, [2006-09-06T02:07:39.502847 #2307] FATAL -- : Missing DSN for source foo!
16
+ F, [2006-09-06T02:07:40.867553 #2307] FATAL -- : no block given!
17
+ F, [2006-09-06T02:08:15.951719 #2324] FATAL -- : Missing host for mailer bar
18
+ F, [2006-09-06T02:08:15.953031 #2324] FATAL -- : Missing DSN for source foo!
19
+ F, [2006-09-06T02:08:17.327679 #2324] FATAL -- : no block given!
20
+ F, [2006-09-06T02:09:55.207829 #2346] FATAL -- : Missing host for mailer bar
21
+ F, [2006-09-06T02:09:55.209021 #2346] FATAL -- : Missing DSN for source foo!
22
+ F, [2006-09-06T02:09:56.579415 #2346] FATAL -- : no block given!
23
+ F, [2006-09-06T02:10:57.371514 #2363] FATAL -- : Missing host for mailer bar
24
+ F, [2006-09-06T02:10:57.372702 #2363] FATAL -- : Missing DSN for source foo!
25
+ F, [2006-09-06T02:10:58.735178 #2363] FATAL -- : no block given!
26
+ F, [2006-09-06T02:12:20.106302 #2387] FATAL -- : Missing host for mailer bar
27
+ F, [2006-09-06T02:12:20.107504 #2387] FATAL -- : Missing DSN for source foo!
28
+ F, [2006-09-06T02:12:21.541101 #2387] FATAL -- : no block given!
29
+ F, [2006-09-06T02:23:19.798195 #2411] FATAL -- : Missing host for mailer bar
30
+ F, [2006-09-06T02:23:19.799518 #2411] FATAL -- : Missing DSN for source foo!
31
+ F, [2006-09-06T02:23:21.551952 #2411] FATAL -- : no block given!
32
+ F, [2006-09-06T02:24:24.486511 #2432] FATAL -- : Missing host for mailer bar
33
+ F, [2006-09-06T02:24:24.487828 #2432] FATAL -- : Missing DSN for source foo!
34
+ F, [2006-09-06T02:24:26.351275 #2432] FATAL -- : no block given!
35
+ F, [2006-09-06T02:25:49.579542 #2466] FATAL -- : Missing host for mailer bar
36
+ F, [2006-09-06T02:25:49.580731 #2466] FATAL -- : Missing DSN for source foo!
37
+ F, [2006-09-06T02:25:50.946354 #2466] FATAL -- : no block given!
38
+ F, [2006-09-06T02:26:40.801772 #2478] FATAL -- : Missing host for mailer bar
39
+ F, [2006-09-06T02:26:40.803067 #2478] FATAL -- : Missing DSN for source foo!
40
+ F, [2006-09-06T02:26:42.178881 #2478] FATAL -- : no block given!
41
+ F, [2006-09-06T02:34:37.820463 #2543] FATAL -- : Missing host for mailer bar
42
+ F, [2006-09-06T02:34:37.821736 #2543] FATAL -- : Missing DSN for source foo!
43
+ F, [2006-09-06T02:34:39.186743 #2543] FATAL -- : no block given!
44
+ F, [2006-09-06T02:34:59.951157 #2562] FATAL -- : Missing host for mailer bar
45
+ F, [2006-09-06T02:34:59.952376 #2562] FATAL -- : Missing DSN for source foo!
46
+ F, [2006-09-06T02:35:01.336348 #2562] FATAL -- : no block given!
47
+ F, [2006-09-06T02:36:26.308317 #2578] FATAL -- : Missing host for mailer bar
48
+ F, [2006-09-06T02:36:26.310977 #2578] FATAL -- : Missing DSN for source foo!
49
+ F, [2006-09-06T02:36:27.710023 #2578] FATAL -- : no block given!
50
+ F, [2006-09-06T02:37:03.381886 #2590] FATAL -- : Missing host for mailer bar
51
+ F, [2006-09-06T02:37:03.383193 #2590] FATAL -- : Missing DSN for source foo!
52
+ F, [2006-09-06T02:37:04.752215 #2590] FATAL -- : no block given!
53
+ F, [2006-09-06T02:38:01.261965 #2623] FATAL -- : Missing host for mailer bar
54
+ F, [2006-09-06T02:38:01.263340 #2623] FATAL -- : Missing DSN for source foo!
55
+ F, [2006-09-06T02:38:02.775252 #2623] FATAL -- : no block given!
56
+ F, [2006-09-09T15:12:29.044943 #4092] FATAL -- : Missing host for mailer bar
57
+ F, [2006-09-09T15:12:29.077832 #4092] FATAL -- : Missing DSN for source foo!
58
+ F, [2006-09-09T15:12:30.640727 #4092] FATAL -- : no block given!
59
+ F, [2006-09-10T23:45:58.521016 #3114] FATAL -- : Missing host for mailer bar
60
+ F, [2006-09-10T23:45:58.553802 #3114] FATAL -- : Missing DSN for source foo!
61
+ F, [2006-09-10T23:46:00.003750 #3114] FATAL -- : no block given!
62
+ F, [2006-09-10T23:47:10.565187 #3129] FATAL -- : Missing host for mailer bar
63
+ F, [2006-09-10T23:47:10.566720 #3129] FATAL -- : Missing DSN for source foo!
64
+ F, [2006-09-10T23:47:12.022613 #3129] FATAL -- : no block given!
65
+ F, [2006-09-13T20:46:21.960919 #2337] FATAL -- : Missing host for mailer bar
66
+ F, [2006-09-13T20:46:21.982106 #2337] FATAL -- : Missing DSN for source foo!
67
+ F, [2006-09-13T20:46:23.480527 #2337] FATAL -- : no block given!
68
+ F, [2006-09-13T20:48:24.836142 #2382] FATAL -- : Missing host for mailer bar
69
+ F, [2006-09-13T20:48:24.837660 #2382] FATAL -- : Missing DSN for source foo!
70
+ F, [2006-09-13T20:48:26.328458 #2382] FATAL -- : no block given!
71
+ F, [2006-09-13T20:49:11.334379 #2397] FATAL -- : Missing host for mailer bar
72
+ F, [2006-09-13T20:49:11.335947 #2397] FATAL -- : Missing DSN for source foo!
73
+ F, [2006-09-13T20:49:12.840600 #2397] FATAL -- : no block given!
74
+ F, [2006-09-14T14:55:40.003769 #2286] FATAL -- : Missing host for mailer bar
75
+ F, [2006-09-14T14:55:40.034439 #2286] FATAL -- : Missing DSN for source foo!
76
+ F, [2006-09-14T14:55:41.420531 #2286] FATAL -- : no block given!
77
+ F, [2006-09-14T14:57:33.765321 #2314] FATAL -- : Missing host for mailer bar
78
+ F, [2006-09-14T14:57:33.766633 #2314] FATAL -- : Missing DSN for source foo!
79
+ F, [2006-09-14T14:57:35.134511 #2314] FATAL -- : no block given!
80
+ F, [2006-09-14T15:09:44.869755 #2389] FATAL -- : Missing host for mailer bar
81
+ F, [2006-09-14T15:09:44.870964 #2389] FATAL -- : Missing DSN for source foo!
82
+ F, [2006-09-14T15:09:46.241647 #2389] FATAL -- : no block given!
83
+ F, [2006-09-14T15:10:39.003512 #2406] FATAL -- : Missing host for mailer bar
84
+ F, [2006-09-14T15:10:39.004723 #2406] FATAL -- : Missing DSN for source foo!
85
+ F, [2006-09-14T15:10:40.390227 #2406] FATAL -- : no block given!
86
+ F, [2006-09-14T15:13:47.931038 #2474] FATAL -- : Missing host for mailer bar
87
+ F, [2006-09-14T15:13:47.932247 #2474] FATAL -- : Missing DSN for source foo!
88
+ F, [2006-09-14T15:13:49.301237 #2474] FATAL -- : no block given!
89
+ F, [2006-09-14T15:15:33.282728 #2504] FATAL -- : Missing host for mailer bar
90
+ F, [2006-09-14T15:15:33.283937 #2504] FATAL -- : Missing DSN for source foo!
91
+ F, [2006-09-14T15:15:34.671120 #2504] FATAL -- : no block given!
92
+ F, [2006-09-14T15:19:23.897944 #2541] FATAL -- : Missing host for mailer bar
93
+ F, [2006-09-14T15:19:23.899149 #2541] FATAL -- : Missing DSN for source foo!
94
+ F, [2006-09-14T15:19:25.270930 #2541] FATAL -- : no block given!
95
+ F, [2006-09-14T15:21:45.369960 #2569] FATAL -- : Missing host for mailer bar
96
+ F, [2006-09-14T15:21:45.371195 #2569] FATAL -- : Missing DSN for source foo!
97
+ F, [2006-09-14T15:21:46.732855 #2569] FATAL -- : no block given!
98
+ F, [2006-09-14T15:29:00.285359 #2626] FATAL -- : Missing host for mailer bar
99
+ F, [2006-09-14T15:29:00.286595 #2626] FATAL -- : Missing DSN for source foo!
100
+ F, [2006-09-14T15:29:01.667713 #2626] FATAL -- : no block given!
101
+ F, [2006-09-14T15:36:10.757949 #2664] FATAL -- : Missing host for mailer bar
102
+ F, [2006-09-14T15:36:10.759201 #2664] FATAL -- : Missing DSN for source foo!
103
+ F, [2006-09-14T15:36:12.184753 #2664] FATAL -- : no block given!
104
+ F, [2006-09-14T15:38:50.563309 #2686] FATAL -- : Missing host for mailer bar
105
+ F, [2006-09-14T15:38:50.564546 #2686] FATAL -- : Missing DSN for source foo!
106
+ F, [2006-09-14T15:38:51.987976 #2686] FATAL -- : no block given!
107
+ F, [2006-09-14T15:43:01.826129 #2747] FATAL -- : Missing host for mailer bar
108
+ F, [2006-09-14T15:43:01.827337 #2747] FATAL -- : Missing DSN for source foo!
109
+ F, [2006-09-14T15:43:03.220988 #2747] FATAL -- : no block given!
110
+ F, [2006-09-14T15:44:57.026175 #2795] FATAL -- : Missing host for mailer bar
111
+ F, [2006-09-14T15:44:57.027386 #2795] FATAL -- : Missing DSN for source foo!
112
+ F, [2006-09-14T15:44:58.401789 #2795] FATAL -- : no block given!
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: ruport
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.5.2
7
- date: 2006-09-03 00:00:00 -04:00
6
+ version: 0.5.3
7
+ date: 2006-09-15 00:00:00 -04:00
8
8
  summary: A generalized Ruby report generation and templating engine.
9
9
  require_paths:
10
10
  - lib