ruport-util 0.1.0
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/Rakefile +69 -0
- data/example/graph_report.rb +17 -0
- data/example/invoice_report.rb +28 -0
- data/example/managed_report.rb +37 -0
- data/lib/ruport/util/graph.rb +186 -0
- data/lib/ruport/util/invoice.rb +138 -0
- data/lib/ruport/util/report_manager.rb +93 -0
- data/lib/ruport/util.rb +3 -0
- data/test/init.rb +7 -0
- data/test/test_graph_renderer.rb +105 -0
- data/test/test_invoice.rb +29 -0
- data/test/test_report_manager.rb +38 -0
- metadata +79 -0
data/Rakefile
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require "rake/rdoctask"
|
2
|
+
require "rake/testtask"
|
3
|
+
require "rake/gempackagetask"
|
4
|
+
|
5
|
+
begin
|
6
|
+
require "rubygems"
|
7
|
+
rescue LoadError
|
8
|
+
nil
|
9
|
+
end
|
10
|
+
|
11
|
+
task :default => [:test]
|
12
|
+
|
13
|
+
Rake::TestTask.new do |test|
|
14
|
+
test.libs << "test"
|
15
|
+
test.test_files = Dir[ "test/test_*.rb" ]
|
16
|
+
test.verbose = true
|
17
|
+
end
|
18
|
+
|
19
|
+
spec = Gem::Specification.new do |spec|
|
20
|
+
spec.name = "ruport-util"
|
21
|
+
spec.version = "0.1.0"
|
22
|
+
spec.platform = Gem::Platform::RUBY
|
23
|
+
spec.summary = "A set of tools and helper libs for Ruby Reports"
|
24
|
+
spec.files = Dir.glob("{example,lib,test,bin}/**/**/*") +
|
25
|
+
["Rakefile"]
|
26
|
+
|
27
|
+
spec.require_path = "lib"
|
28
|
+
|
29
|
+
spec.test_files = Dir[ "test/test_*.rb" ]
|
30
|
+
spec.bindir = "bin"
|
31
|
+
spec.has_rdoc = true
|
32
|
+
spec.extra_rdoc_files = %w{}
|
33
|
+
spec.rdoc_options << '--title' << 'Ruport Documentation' #<<
|
34
|
+
# '--main' << 'README' << '-q'
|
35
|
+
spec.add_dependency('ruport', ">=0.9.3")
|
36
|
+
spec.add_dependency('scruffy', ">=0.2.2")
|
37
|
+
spec.author = "Gregory Brown"
|
38
|
+
spec.email = " gregory.t.brown@gmail.com"
|
39
|
+
spec.rubyforge_project = "ruport"
|
40
|
+
spec.homepage = "http://code.rubyreports.org"
|
41
|
+
spec.description = <<END_DESC
|
42
|
+
ruport-util provides a number of utilities and helper libs
|
43
|
+
for Ruby Reports
|
44
|
+
END_DESC
|
45
|
+
end
|
46
|
+
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
rdoc.rdoc_files.include( "README",
|
49
|
+
"TODO", #"CHANGELOG",
|
50
|
+
"AUTHORS", "COPYING",
|
51
|
+
"LICENSE", "lib/" )
|
52
|
+
rdoc.main = "README"
|
53
|
+
rdoc.rdoc_dir = "doc/html"
|
54
|
+
rdoc.title = "Ruport Documentation"
|
55
|
+
end
|
56
|
+
|
57
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
58
|
+
pkg.need_zip = true
|
59
|
+
pkg.need_tar = true
|
60
|
+
end
|
61
|
+
|
62
|
+
begin
|
63
|
+
require 'rcov/rcovtask'
|
64
|
+
Rcov::RcovTask.new do |t|
|
65
|
+
t.test_files = Dir[ "test/test_*.rb" ]
|
66
|
+
end
|
67
|
+
rescue LoadError
|
68
|
+
nil
|
69
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "ruport"
|
3
|
+
|
4
|
+
require "ruport/util/graph"
|
5
|
+
|
6
|
+
class GraphReport < Ruport::Report
|
7
|
+
|
8
|
+
def generate
|
9
|
+
graph = Ruport::Graph(:column_names => %w[a b c d e])
|
10
|
+
graph.add_line [1,2,3,4,5], :name => "foo"
|
11
|
+
graph.add_line [11,22,70,2,19], :name => "bar"
|
12
|
+
graph.to_svg
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
GraphReport.run { |r| r.write("foo.svg") }
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "ruport"
|
3
|
+
require "ruport/util/invoice"
|
4
|
+
|
5
|
+
class SampleReport < Ruport::Report
|
6
|
+
include Invoice
|
7
|
+
|
8
|
+
def generate
|
9
|
+
render_invoice do |i|
|
10
|
+
i.data = Table("Item Number","Description","Price") { |t|
|
11
|
+
t << %w[101 Erlang\ The\ Movie $1000.00]
|
12
|
+
t << %w[102 Erlang\ The\ Book $45.95]
|
13
|
+
}
|
14
|
+
i.company_info = "Stone Code Productions\n43 Neagle Street"
|
15
|
+
i.customer_info = "Gregory Brown\n200 Foo Ave.\n"
|
16
|
+
i.comments = "Hello Mike! Hello Joe!"
|
17
|
+
i.order_info = "Some info\nabout your order"
|
18
|
+
i.title = "Invoice for 12.15.2006 - 12.31.2006"
|
19
|
+
i.options do |o|
|
20
|
+
o.body_width = 480
|
21
|
+
o.comments_font_size = 12
|
22
|
+
o.title_font_size = 10
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
SampleReport.run { |r| r.write "out.pdf" }
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "ruport"
|
3
|
+
require "ruport/util/report_manager"
|
4
|
+
|
5
|
+
class MyReport < Ruport::Report
|
6
|
+
|
7
|
+
acts_as_managed_report
|
8
|
+
|
9
|
+
def generate
|
10
|
+
"Hello Mike"
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
class YourReport < Ruport::Report
|
16
|
+
|
17
|
+
acts_as_managed_report
|
18
|
+
|
19
|
+
def generate
|
20
|
+
"Hello Joe"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
class HisReport < Ruport::Report
|
26
|
+
|
27
|
+
acts_as_managed_report
|
28
|
+
|
29
|
+
def generate
|
30
|
+
"Hello Robert"
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
%w[MyReport YourReport HisReport].each do |report|
|
36
|
+
puts Ruport::ReportManager[report].run
|
37
|
+
end
|
@@ -0,0 +1,186 @@
|
|
1
|
+
# renderer/graph.rb
|
2
|
+
# Generalized graphing support for Ruby Reports
|
3
|
+
#
|
4
|
+
# Written by Gregory Brown, Copright December 2006, All Rights Reserved.
|
5
|
+
#
|
6
|
+
# This is free software. See LICENSE and COPYING for details.
|
7
|
+
#
|
8
|
+
|
9
|
+
begin
|
10
|
+
require "rubygems"
|
11
|
+
gem "ruport", ">= 0.9.3"
|
12
|
+
rescue LoadError
|
13
|
+
nil
|
14
|
+
end
|
15
|
+
|
16
|
+
module Ruport
|
17
|
+
|
18
|
+
def Graph(*args)
|
19
|
+
Graph.new(*args)
|
20
|
+
end
|
21
|
+
|
22
|
+
module_function :Graph
|
23
|
+
|
24
|
+
class Graph < Ruport::Data::Table
|
25
|
+
|
26
|
+
class Line < Ruport::Data::Record
|
27
|
+
attr_accessor :name
|
28
|
+
|
29
|
+
def initialize_copy(from)
|
30
|
+
@name = from.name.dup if from.name
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def initialize(options={})
|
35
|
+
super({:record_class => Line}.merge(options))
|
36
|
+
end
|
37
|
+
|
38
|
+
def add_line(row_data,options={})
|
39
|
+
self << row_data
|
40
|
+
self[-1].name = options[:name]
|
41
|
+
end
|
42
|
+
|
43
|
+
def dup
|
44
|
+
obj = self.class.new(:column_names => column_names)
|
45
|
+
data.each { |r| obj.add_line(r.to_a,:name => r.name)}
|
46
|
+
return obj
|
47
|
+
end
|
48
|
+
|
49
|
+
def as(format,*args,&block)
|
50
|
+
Ruport::Renderer::Graph.render(format,*args,&block)
|
51
|
+
end
|
52
|
+
|
53
|
+
def method_missing(id,*args,&block)
|
54
|
+
id.to_s =~ /^to_(.*)/
|
55
|
+
$1 ? as($1.to_sym,{:data => self}.merge(args[0]||{}),&block) : super
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
# This class implements the basic graphing engine for Ruport.
|
61
|
+
#
|
62
|
+
# == Supported Format Plugins
|
63
|
+
#
|
64
|
+
# * Format::XML
|
65
|
+
# * Format::SVG
|
66
|
+
#
|
67
|
+
# == Default layout options
|
68
|
+
#
|
69
|
+
# * height #=> 350
|
70
|
+
# * width #=> 500
|
71
|
+
# * style #=> :line
|
72
|
+
#
|
73
|
+
# == Plugin hooks called (in order)
|
74
|
+
#
|
75
|
+
# * prepare_graph
|
76
|
+
# * build_graph
|
77
|
+
# * finalize_graph
|
78
|
+
class Renderer::Graph < Renderer
|
79
|
+
|
80
|
+
options { |o| o.style = :line }
|
81
|
+
|
82
|
+
prepare :graph
|
83
|
+
|
84
|
+
stage :graph
|
85
|
+
|
86
|
+
finalize :graph
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
class SVG < Formatter
|
91
|
+
|
92
|
+
renders :svg, :for => Renderer::Graph
|
93
|
+
|
94
|
+
# a hash of Scruffy themes.
|
95
|
+
#
|
96
|
+
# You can use these by setting options.theme like this:
|
97
|
+
#
|
98
|
+
# Graph.render_svg { |r| r.options.theme = r.plugin.themes[:mephisto] }
|
99
|
+
#
|
100
|
+
# Available themes: ( :mephisto, :keynote, :ruby_blog )
|
101
|
+
#
|
102
|
+
def themes
|
103
|
+
{ :mephisto => Scruffy::Themes::Mephisto.new,
|
104
|
+
:keynote => Scruffy::Themes::Keynote.new,
|
105
|
+
:ruby_blog => Scruffy::Themes::RubyBlog.new }
|
106
|
+
end
|
107
|
+
|
108
|
+
# generates a scruffy graph object
|
109
|
+
def initialize
|
110
|
+
quiet { require 'scruffy' }
|
111
|
+
|
112
|
+
@graph = Scruffy::Graph.new
|
113
|
+
end
|
114
|
+
|
115
|
+
# the Scruffy::Graph object
|
116
|
+
attr_reader :graph
|
117
|
+
|
118
|
+
# sets the graph title, theme, and column_names
|
119
|
+
#
|
120
|
+
# column_names are defined by the Data::Table,
|
121
|
+
# theme may be specified by options.theme (see SVG#themes)
|
122
|
+
# title may be specified by options.title
|
123
|
+
#
|
124
|
+
def prepare_graph
|
125
|
+
@graph.title ||= options.title
|
126
|
+
@graph.theme = options.theme if options.theme
|
127
|
+
@graph.point_markers ||= data.column_names
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
# Generates an SVG using Scruffy.
|
132
|
+
def build_graph
|
133
|
+
data.each_with_index do |r,i|
|
134
|
+
add_line(r.to_a,r.name||"series #{i+1}")
|
135
|
+
end
|
136
|
+
|
137
|
+
output << @graph.render(
|
138
|
+
:size => [options.width||500, options.height||300]
|
139
|
+
)
|
140
|
+
end
|
141
|
+
|
142
|
+
# Uses Scruffy::Graph#add to add a new line to the graph.
|
143
|
+
#
|
144
|
+
# Line style is determined by options.style
|
145
|
+
#
|
146
|
+
def add_line(row,label)
|
147
|
+
@graph.add( options.style, label, row )
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
class XML_SWF < Formatter
|
153
|
+
|
154
|
+
renders :xml_swf, :for => Renderer::Graph
|
155
|
+
|
156
|
+
def prepare_graph
|
157
|
+
gem "builder"
|
158
|
+
require "builder"
|
159
|
+
@builder = Builder::XmlMarkup.new(:indent => 2)
|
160
|
+
end
|
161
|
+
|
162
|
+
def build_graph
|
163
|
+
output << @builder.chart do |b|
|
164
|
+
b.chart_type(options.style.to_s)
|
165
|
+
|
166
|
+
b.chart_data do |cd|
|
167
|
+
|
168
|
+
cd.row { |first|
|
169
|
+
first.null
|
170
|
+
data.column_names.each { |c| first.string(c) }
|
171
|
+
}
|
172
|
+
|
173
|
+
data.each_with_index { |r,i|
|
174
|
+
label = r.name || "Region #{i}"
|
175
|
+
cd.row { |data_row|
|
176
|
+
data_row.string(label)
|
177
|
+
r.each { |e| data_row.number(e) }
|
178
|
+
}
|
179
|
+
}
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
module Ruport
|
2
|
+
class Renderer
|
3
|
+
class Invoice < Ruport::Renderer
|
4
|
+
|
5
|
+
required_option :customer_info,:company_info,:order_info,:comments
|
6
|
+
|
7
|
+
option :title
|
8
|
+
|
9
|
+
stage :invoice_headers,:invoice_body,:invoice_footer
|
10
|
+
|
11
|
+
finalize :invoice
|
12
|
+
|
13
|
+
module InvoiceHelpers
|
14
|
+
def build_company_header
|
15
|
+
@tod = pdf_writer.y
|
16
|
+
rounded_text_box(options.company_info) { |o|
|
17
|
+
o.radius = 3
|
18
|
+
o.width = options.header_width || 200
|
19
|
+
o.height = options.header_height || 50
|
20
|
+
o.font_size = options.header_font_size || 10
|
21
|
+
o.y = pdf_writer.y
|
22
|
+
o.x = pdf_writer.absolute_left_margin + 10
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def build_customer_header
|
27
|
+
move_cursor -5
|
28
|
+
rounded_text_box(options.customer_info) { |o|
|
29
|
+
o.radius = 3
|
30
|
+
o.width = options.header_width || 200
|
31
|
+
o.height = options.header_height || 50
|
32
|
+
o.font_size = options.header_font_size || 10
|
33
|
+
o.y = pdf_writer.y
|
34
|
+
o.x = pdf_writer.absolute_left_margin + 10
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def build_title
|
39
|
+
add_title(options.title) if options.title
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_title( title )
|
43
|
+
rounded_text_box("<b>#{title}</b>") do |o|
|
44
|
+
o.fill_color = Color::RGB::Gray80
|
45
|
+
o.radius = 5
|
46
|
+
o.width = options.header_width || 200
|
47
|
+
o.height = options.header_height || 20
|
48
|
+
o.font_size = options.header_font_size || 11
|
49
|
+
o.x = pdf_writer.absolute_right_margin - o.width
|
50
|
+
o.y = pdf_writer.absolute_top_margin
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def build_order_header
|
55
|
+
if options.order_info
|
56
|
+
rounded_text_box("<b>#{options.order_info}</b>") do |o|
|
57
|
+
o.radius = 5
|
58
|
+
o.heading = "Billing Information"
|
59
|
+
o.width = options.header_width || 200
|
60
|
+
o.height = options.header_height || 80
|
61
|
+
o.font_size = options.header_font_size || 10
|
62
|
+
o.x = pdf_writer.absolute_right_margin - o.width
|
63
|
+
o.y = pdf_writer.absolute_top_margin - 25
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def horizontal_line(x1,x2)
|
69
|
+
pdf_writer.line(x1,pdf_writer.y,x2,pdf_writer.y)
|
70
|
+
pdf_writer.stroke
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
class PDF < Ruport::Formatter::PDF
|
76
|
+
|
77
|
+
include InvoiceHelpers
|
78
|
+
renders :pdf, :for => Renderer::Invoice
|
79
|
+
|
80
|
+
def build_invoice_headers
|
81
|
+
build_company_header
|
82
|
+
build_customer_header
|
83
|
+
build_title
|
84
|
+
build_order_header
|
85
|
+
end
|
86
|
+
|
87
|
+
def build_invoice_body
|
88
|
+
|
89
|
+
pdf_writer.y = 600
|
90
|
+
|
91
|
+
Ruport::Renderer::Table.render_pdf { |r|
|
92
|
+
r.data = data
|
93
|
+
r.options.formatter = pdf_writer
|
94
|
+
r.options.table_width = options.body_width || 450
|
95
|
+
}
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
def build_invoice_footer
|
100
|
+
# footer
|
101
|
+
pdf_writer.open_object do |footer|
|
102
|
+
pdf_writer.save_state
|
103
|
+
pdf_writer.stroke_color! Color::RGB::Black
|
104
|
+
pdf_writer.stroke_style! ::PDF::Writer::StrokeStyle::DEFAULT
|
105
|
+
if options.comments
|
106
|
+
|
107
|
+
move_cursor_to 60
|
108
|
+
|
109
|
+
horizontal_line left_boundary + 20, right_boundary - 25
|
110
|
+
|
111
|
+
move_cursor -10
|
112
|
+
|
113
|
+
add_text(options.comments,:justification => :center,
|
114
|
+
:left => 0, :right => 0 )
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
pdf_writer.restore_state
|
119
|
+
pdf_writer.close_object
|
120
|
+
pdf_writer.add_object(footer, :all_pages)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def finalize_invoice
|
125
|
+
output << pdf_writer.render
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
module Ruport::Report::Invoice
|
134
|
+
def render_invoice(*args,&block)
|
135
|
+
Ruport::Renderer::Invoice.render_pdf(*args,&block)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module Ruport
|
2
|
+
class ReportManager
|
3
|
+
|
4
|
+
def self.add_model(*new_models)
|
5
|
+
self.models |= new_models
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.add_report(*new_reports)
|
9
|
+
self.reports |= new_reports
|
10
|
+
end
|
11
|
+
|
12
|
+
# Looks in reports first, then models.
|
13
|
+
# if there is a conflict, you are F'ed.
|
14
|
+
#
|
15
|
+
# just kidding, use models#find or reports#find
|
16
|
+
def self.[](name)
|
17
|
+
reports.find { |r| r.name.eql?(name) } ||
|
18
|
+
models.find { |m| m.name.eql?(name) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.models
|
22
|
+
@models ||= []
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.reports
|
26
|
+
@reports ||= []
|
27
|
+
end
|
28
|
+
|
29
|
+
class << self
|
30
|
+
attr_writer :models
|
31
|
+
attr_writer :reports
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
if defined? ActiveRecord
|
38
|
+
class ActiveRecord::Base
|
39
|
+
def self.acts_as_managed_report
|
40
|
+
Ruport::ReportManager.add_model(self)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class Ruport::Report
|
46
|
+
def self.acts_as_managed_report
|
47
|
+
Ruport::ReportManager.add_report(self)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
if __FILE__ == $PROGRAM_NAME
|
52
|
+
|
53
|
+
include Ruport
|
54
|
+
|
55
|
+
require "test/unit"
|
56
|
+
|
57
|
+
# we'll autoregister this one
|
58
|
+
class FakeModel
|
59
|
+
ReportManager.add_model(self)
|
60
|
+
end
|
61
|
+
|
62
|
+
# we'll add these afterwards
|
63
|
+
class FakeModel2;end
|
64
|
+
class FakeModel3;end
|
65
|
+
|
66
|
+
|
67
|
+
class TestReportManager < Test::Unit::TestCase
|
68
|
+
|
69
|
+
def test_simple_usage
|
70
|
+
assert_equal [FakeModel], ReportManager.models
|
71
|
+
assert_equal FakeModel, ReportManager["FakeModel"]
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_add_models_externally
|
75
|
+
klass = ReportManager.dup # we need to do this to make the tests work
|
76
|
+
# no need in production code
|
77
|
+
assert_equal [FakeModel], klass.models
|
78
|
+
|
79
|
+
klass.add_model(FakeModel2)
|
80
|
+
assert_equal [FakeModel,FakeModel2], klass.models
|
81
|
+
|
82
|
+
klass.add_model(FakeModel3)
|
83
|
+
assert_equal [FakeModel,FakeModel2, FakeModel3], klass.models
|
84
|
+
|
85
|
+
# let's make sure we can still grab these by name (a string)
|
86
|
+
[FakeModel,FakeModel2,FakeModel3].each do |m|
|
87
|
+
assert_equal m, klass[m.name]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
data/lib/ruport/util.rb
ADDED
data/test/init.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
require "test/init"
|
2
|
+
require "ruport/util/graph"
|
3
|
+
|
4
|
+
class MockGraphPlugin < Ruport::Formatter
|
5
|
+
renders :mock, :for => Ruport::Renderer::Graph
|
6
|
+
def prepare_graph
|
7
|
+
output << "prepare"
|
8
|
+
end
|
9
|
+
def build_graph
|
10
|
+
output << "build"
|
11
|
+
end
|
12
|
+
def finalize_graph
|
13
|
+
output << "finalize"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
class TestGraphRenderer < Test::Unit::TestCase
|
19
|
+
|
20
|
+
def test_basics
|
21
|
+
out = Ruport::Renderer::Graph.render_mock do |r|
|
22
|
+
r.options do |l|
|
23
|
+
assert_equal :line, l.style
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
assert_equal("preparebuildfinalize",out)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
class TestSVGPlugin < Test::Unit::TestCase
|
34
|
+
|
35
|
+
def test_output
|
36
|
+
assert_not_nil Ruport::Renderer::Graph.render_svg { |r|
|
37
|
+
r.data = Ruport::Graph(:data => [[1,2,3],[4,5,6]])
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
class TestXMLSWFPlugin < Test::Unit::TestCase
|
44
|
+
|
45
|
+
def test_output
|
46
|
+
|
47
|
+
expected = <<-EOS
|
48
|
+
<chart>
|
49
|
+
<chart_type>line</chart_type>
|
50
|
+
<chart_data>
|
51
|
+
<row>
|
52
|
+
<null/>
|
53
|
+
</row>
|
54
|
+
<row>
|
55
|
+
<string>Region 0</string>
|
56
|
+
<number>1</number>
|
57
|
+
<number>2</number>
|
58
|
+
<number>3</number>
|
59
|
+
</row>
|
60
|
+
<row>
|
61
|
+
<string>Region 1</string>
|
62
|
+
<number>4</number>
|
63
|
+
<number>5</number>
|
64
|
+
<number>6</number>
|
65
|
+
</row>
|
66
|
+
</chart_data>
|
67
|
+
</chart>
|
68
|
+
EOS
|
69
|
+
assert_equal expected,
|
70
|
+
Ruport::Renderer::Graph.render_xml_swf { |r|
|
71
|
+
r.data = Ruport::Graph(:data => [[1,2,3],[4,5,6]])
|
72
|
+
}
|
73
|
+
|
74
|
+
expected = <<-EOS
|
75
|
+
<chart>
|
76
|
+
<chart_type>line</chart_type>
|
77
|
+
<chart_data>
|
78
|
+
<row>
|
79
|
+
<null/>
|
80
|
+
</row>
|
81
|
+
<row>
|
82
|
+
<string>Alpha</string>
|
83
|
+
<number>1</number>
|
84
|
+
<number>2</number>
|
85
|
+
<number>3</number>
|
86
|
+
</row>
|
87
|
+
<row>
|
88
|
+
<string>Beta</string>
|
89
|
+
<number>4</number>
|
90
|
+
<number>5</number>
|
91
|
+
<number>6</number>
|
92
|
+
</row>
|
93
|
+
</chart_data>
|
94
|
+
</chart>
|
95
|
+
EOS
|
96
|
+
|
97
|
+
graph = Ruport::Graph()
|
98
|
+
graph.add_line [1,2,3], :name => "Alpha"
|
99
|
+
graph.add_line [4,5,6], :name => "Beta"
|
100
|
+
|
101
|
+
assert_equal expected, graph.to_xml_swf
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "test/init"
|
2
|
+
require "ruport/util/invoice"
|
3
|
+
|
4
|
+
class TestInvoice < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_required_options
|
7
|
+
assert_raises(RuntimeError) { Ruport::Renderer::Invoice.render_pdf }
|
8
|
+
|
9
|
+
#hash form
|
10
|
+
assert_nothing_raised {
|
11
|
+
Ruport::Renderer::Invoice.render_pdf :data => Table(%w[a b c]) << [1,2,3],
|
12
|
+
:customer_info => "blah", :company_info => "also blah",
|
13
|
+
:order_info => "Incredibly Blah", :comments => "Super Blah"
|
14
|
+
}
|
15
|
+
|
16
|
+
#block form
|
17
|
+
assert_nothing_raised {
|
18
|
+
Ruport::Renderer::Invoice.render_pdf do |r|
|
19
|
+
r.data = Table(%w[a b c]) << [1,2,3]
|
20
|
+
r.customer_info = "blah"
|
21
|
+
r.company_info = "also blah"
|
22
|
+
r.order_info = "Incredibly Blah"
|
23
|
+
r.comments = "Super blah"
|
24
|
+
end
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "test/init"
|
2
|
+
require "ruport/util/report_manager"
|
3
|
+
|
4
|
+
class Sample < Ruport::Report; def generate; "Hello Mike"; end; end
|
5
|
+
class Sample2 < Ruport::Report; def generate; "Hello Joe"; end; end
|
6
|
+
Sample.acts_as_managed_report
|
7
|
+
Sample2.acts_as_managed_report
|
8
|
+
|
9
|
+
class FakeModel2;end
|
10
|
+
class FakeModel3;end
|
11
|
+
|
12
|
+
class TestReportManager < Test::Unit::TestCase
|
13
|
+
|
14
|
+
def test_simple_usage
|
15
|
+
assert_equal "Hello Mike", Ruport::ReportManager["Sample"].run
|
16
|
+
assert_equal "Hello Joe", Ruport::ReportManager["Sample2"].run
|
17
|
+
assert_equal [ Sample, Sample2 ], Ruport::ReportManager.reports
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_add_models
|
21
|
+
# we need to do this to make the tests work,no need in production code
|
22
|
+
klass = Ruport::ReportManager.dup
|
23
|
+
|
24
|
+
assert_equal [], klass.models
|
25
|
+
|
26
|
+
klass.add_model(FakeModel2)
|
27
|
+
assert_equal [FakeModel2], klass.models
|
28
|
+
|
29
|
+
klass.add_model(FakeModel3)
|
30
|
+
assert_equal [FakeModel2, FakeModel3], klass.models
|
31
|
+
|
32
|
+
# let's make sure we can still grab these by name (a string)
|
33
|
+
[FakeModel2,FakeModel3].each do |m|
|
34
|
+
assert_equal m, klass[m.name]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.2
|
3
|
+
specification_version: 1
|
4
|
+
name: ruport-util
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.1.0
|
7
|
+
date: 2007-04-04 00:00:00 -04:00
|
8
|
+
summary: A set of tools and helper libs for Ruby Reports
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: " gregory.t.brown@gmail.com"
|
12
|
+
homepage: http://code.rubyreports.org
|
13
|
+
rubyforge_project: ruport
|
14
|
+
description: ruport-util provides a number of utilities and helper libs for Ruby Reports
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Gregory Brown
|
31
|
+
files:
|
32
|
+
- example/graph_report.rb
|
33
|
+
- example/invoice_report.rb
|
34
|
+
- example/managed_report.rb
|
35
|
+
- lib/ruport
|
36
|
+
- lib/ruport/util
|
37
|
+
- lib/ruport/util.rb
|
38
|
+
- lib/ruport/util/graph.rb
|
39
|
+
- lib/ruport/util/invoice.rb
|
40
|
+
- lib/ruport/util/report_manager.rb
|
41
|
+
- test/init.rb
|
42
|
+
- test/test_graph_renderer.rb
|
43
|
+
- test/test_invoice.rb
|
44
|
+
- test/test_report_manager.rb
|
45
|
+
- Rakefile
|
46
|
+
test_files:
|
47
|
+
- test/test_graph_renderer.rb
|
48
|
+
- test/test_invoice.rb
|
49
|
+
- test/test_report_manager.rb
|
50
|
+
rdoc_options:
|
51
|
+
- --title
|
52
|
+
- Ruport Documentation
|
53
|
+
extra_rdoc_files: []
|
54
|
+
|
55
|
+
executables: []
|
56
|
+
|
57
|
+
extensions: []
|
58
|
+
|
59
|
+
requirements: []
|
60
|
+
|
61
|
+
dependencies:
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: ruport
|
64
|
+
version_requirement:
|
65
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.9.3
|
70
|
+
version:
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: scruffy
|
73
|
+
version_requirement:
|
74
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 0.2.2
|
79
|
+
version:
|