ruport 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +55 -9
- data/Rakefile +3 -5
- data/examples/line_plotter.rb +3 -0
- data/examples/pdf_complex_report.rb +0 -1
- data/examples/pdf_report_with_common_base.rb +72 -0
- data/examples/pdf_styles.rb +16 -0
- data/examples/simple_pdf_lines.rb +0 -1
- data/lib/ruport.rb +5 -66
- data/lib/ruport/acts_as_reportable.rb +122 -51
- data/lib/ruport/data/grouping.rb +30 -13
- data/lib/ruport/data/record.rb +26 -25
- data/lib/ruport/data/table.rb +91 -34
- data/lib/ruport/formatter.rb +86 -11
- data/lib/ruport/formatter/csv.rb +29 -2
- data/lib/ruport/formatter/html.rb +23 -1
- data/lib/ruport/formatter/pdf.rb +123 -32
- data/lib/ruport/formatter/text.rb +62 -6
- data/lib/ruport/query.rb +75 -39
- data/lib/ruport/renderer.rb +250 -35
- data/lib/ruport/renderer/grouping.rb +2 -2
- data/test/html_formatter_test.rb +4 -1
- data/test/pdf_formatter_test.rb +30 -7
- data/test/query_test.rb +12 -0
- data/test/renderer_test.rb +33 -2
- data/test/table_test.rb +8 -2
- data/test/text_formatter_test.rb +11 -1
- metadata +53 -107
- data/bin/rope +0 -12
- data/examples/rope_examples/itunes/README +0 -12
- data/examples/rope_examples/itunes/Rakefile +0 -39
- data/examples/rope_examples/itunes/config/environment.rb +0 -4
- data/examples/rope_examples/itunes/data/mix.txt +0 -1
- data/examples/rope_examples/itunes/lib/helpers.rb +0 -0
- data/examples/rope_examples/itunes/lib/init.rb +0 -39
- data/examples/rope_examples/itunes/lib/reports.rb +0 -1
- data/examples/rope_examples/itunes/lib/reports/playlist.rb +0 -17
- data/examples/rope_examples/itunes/log/ruport.log +0 -1
- data/examples/rope_examples/itunes/test/test_playlist.rb +0 -8
- data/examples/rope_examples/itunes/util/build +0 -96
- data/examples/rope_examples/itunes/util/sql_exec +0 -5
- data/examples/rope_examples/sales_report/README +0 -4
- data/examples/rope_examples/sales_report/Rakefile +0 -39
- data/examples/rope_examples/sales_report/config/environment.rb +0 -4
- data/examples/rope_examples/sales_report/lib/helpers.rb +0 -0
- data/examples/rope_examples/sales_report/lib/init.rb +0 -39
- data/examples/rope_examples/sales_report/lib/reports.rb +0 -1
- data/examples/rope_examples/sales_report/lib/reports/sales.rb +0 -132
- data/examples/rope_examples/sales_report/log/ruport.log +0 -1
- data/examples/rope_examples/sales_report/output/books.pdf +0 -170
- data/examples/rope_examples/sales_report/output/books.txt +0 -11
- data/examples/rope_examples/sales_report/test/test_sales.rb +0 -8
- data/examples/rope_examples/sales_report/util/build +0 -96
- data/examples/rope_examples/sales_report/util/sql_exec +0 -5
- data/examples/sample.rb +0 -16
- data/lib/ruport/generator.rb +0 -294
- data/lib/ruport/report.rb +0 -262
- data/setup.rb +0 -1585
- data/test/report_test.rb +0 -218
- data/test/samples/foo.rtxt +0 -3
@@ -1,39 +0,0 @@
|
|
1
|
-
begin; require "rubygems"; rescue LoadError; end
|
2
|
-
require "rake/testtask"
|
3
|
-
|
4
|
-
task :default => [:test]
|
5
|
-
|
6
|
-
Rake::TestTask.new do |test|
|
7
|
-
test.libs << "test"
|
8
|
-
test.pattern = 'test/**/test_*.rb'
|
9
|
-
test.verbose = true
|
10
|
-
end
|
11
|
-
|
12
|
-
task :build do
|
13
|
-
if ENV['report']
|
14
|
-
sh "ruby util/build report #{ENV['report']}"
|
15
|
-
elsif ENV['renderer']
|
16
|
-
sh "ruby util/build renderer #{ENV['renderer']}"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
task :run do
|
21
|
-
sh "ruby lib/reports/#{ENV['report']}.rb"
|
22
|
-
end
|
23
|
-
|
24
|
-
task :use_utils do
|
25
|
-
raise "File lib/init_utils.rb exists!" if File.exist?('lib/init_utils.rb')
|
26
|
-
File.open('lib/init_utils.rb','w') { |f|
|
27
|
-
if ENV['only']
|
28
|
-
ENV['only'].split(',').each { |e|
|
29
|
-
f.puts "require 'ruport/util/#{e}'"
|
30
|
-
}
|
31
|
-
else
|
32
|
-
f.puts "require 'ruport/util'"
|
33
|
-
end
|
34
|
-
}
|
35
|
-
File.open('lib/init.rb','a') { |f|
|
36
|
-
f.puts '#comment out the line below to disable auto-loading of utils'
|
37
|
-
f.puts 'require "lib/init_utils.rb"'
|
38
|
-
}
|
39
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
Name Artist Composer Album Grouping Genre Size Time Disc Number Disc Count Track Number Track Count Year Date Modified Date Added Bit Rate Sample Rate Volume Adjustment Kind Equalizer Comments Play Count Last Played Skip Count Last Skipped My Rating Location
|
File without changes
|
@@ -1,39 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require "rubygems"
|
3
|
-
gem "ruport","=0.9.6"
|
4
|
-
rescue LoadError
|
5
|
-
nil
|
6
|
-
end
|
7
|
-
require "ruport"
|
8
|
-
require "lib/helpers"
|
9
|
-
require "config/environment"
|
10
|
-
|
11
|
-
class String
|
12
|
-
def /(other)
|
13
|
-
self + "/" + other
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class Ruport::Report
|
18
|
-
|
19
|
-
def output_dir
|
20
|
-
config.output_dir or dir('output')
|
21
|
-
end
|
22
|
-
|
23
|
-
def data_dir
|
24
|
-
config.data_dir or dir('data')
|
25
|
-
end
|
26
|
-
|
27
|
-
def query_dir
|
28
|
-
config.query_dir or dir('sql')
|
29
|
-
end
|
30
|
-
|
31
|
-
def template_dir
|
32
|
-
config.template_dir or dir('templates')
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
def dir(name)
|
37
|
-
"/Users/mikem836/ruport/itunes/#{name}"
|
38
|
-
end
|
39
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
require "lib/reports/playlist"
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require "lib/init"
|
2
|
-
class Playlist < Ruport::Report
|
3
|
-
|
4
|
-
def prepare
|
5
|
-
t = load_csv "data/mix.txt", :csv_options => { :col_sep => "\t" }
|
6
|
-
@table = t.sub_table(%w[Name Artist Album Time])
|
7
|
-
end
|
8
|
-
|
9
|
-
def generate
|
10
|
-
@table.to_pdf
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
if __FILE__ == $0
|
16
|
-
Playlist.run { |res| res.write 'output/mix.pdf'}
|
17
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
# Logfile created on Sat Feb 03 19:38:27 -0500 2007 by logger.rb/1.5.2.9
|
@@ -1,96 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'fileutils'
|
4
|
-
require 'lib/init.rb'
|
5
|
-
require "ruport/generator"
|
6
|
-
include FileUtils
|
7
|
-
include Ruport::Generator::Helpers
|
8
|
-
|
9
|
-
unless ARGV.length > 1
|
10
|
-
puts "usage: build [command] [options]"
|
11
|
-
exit
|
12
|
-
end
|
13
|
-
|
14
|
-
class_name = format_class_name(ARGV[1])
|
15
|
-
|
16
|
-
if ARGV[0].eql? "report"
|
17
|
-
check_for_files
|
18
|
-
File.open("lib/reports.rb", "a") { |f|
|
19
|
-
f.puts("require \"lib/reports/#{ARGV[1]}\"")
|
20
|
-
}
|
21
|
-
REP = <<EOR
|
22
|
-
require "lib/init"
|
23
|
-
class #{class_name} < Ruport::Report
|
24
|
-
|
25
|
-
def generate
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
if __FILE__ == $0
|
32
|
-
puts #{class_name}.run
|
33
|
-
end
|
34
|
-
EOR
|
35
|
-
|
36
|
-
TEST = <<EOR
|
37
|
-
require "test/unit"
|
38
|
-
require "lib/reports/#{ARGV[1]}"
|
39
|
-
|
40
|
-
class Test#{class_name} < Test::Unit::TestCase
|
41
|
-
def test_flunk
|
42
|
-
flunk "Write your real tests here or in any test/test_* file"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
EOR
|
46
|
-
|
47
|
-
File.open("lib/reports/#{ARGV[1]}.rb", "w") { |f| f << REP }
|
48
|
-
puts "reports file: lib/reports/#{ARGV[1]}.rb"
|
49
|
-
puts "test file: test/test_#{ARGV[1]}.rb"
|
50
|
-
puts "class name: #{class_name}"
|
51
|
-
File.open("test/test_#{ARGV[1]}.rb","w") { |f| f << TEST }
|
52
|
-
|
53
|
-
elsif ARGV[0].eql? "renderer"
|
54
|
-
|
55
|
-
check_for_files
|
56
|
-
File.open("lib/renderers.rb","a") { |f|
|
57
|
-
f.puts("require \"lib/renderers/#{ARGV[1]}\"")
|
58
|
-
}
|
59
|
-
REP = <<EOR
|
60
|
-
require "lib/init"
|
61
|
-
|
62
|
-
class #{class_name} < Ruport::Renderer
|
63
|
-
stage :#{class_name.downcase}
|
64
|
-
end
|
65
|
-
|
66
|
-
class #{class_name}Formatter < Ruport::Formatter
|
67
|
-
|
68
|
-
# change to your format name, or add additional formats
|
69
|
-
renders :my_format, :for => #{class_name}
|
70
|
-
|
71
|
-
def build_#{class_name.downcase}
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
76
|
-
EOR
|
77
|
-
|
78
|
-
TEST = <<EOR
|
79
|
-
require "test/unit"
|
80
|
-
require "lib/renderers/#{ARGV[1]}"
|
81
|
-
|
82
|
-
class Test#{class_name} < Test::Unit::TestCase
|
83
|
-
def test_flunk
|
84
|
-
flunk "Write your real tests here or in any test/test_* file"
|
85
|
-
end
|
86
|
-
end
|
87
|
-
EOR
|
88
|
-
puts "renderer file: lib/renderers/#{ARGV[1]}.rb"
|
89
|
-
File.open("lib/renderers/#{ARGV[1]}.rb", "w") { |f| f << REP }
|
90
|
-
puts "test file: test/test_#{ARGV[1]}.rb"
|
91
|
-
|
92
|
-
puts "class name: #{class_name}"
|
93
|
-
File.open("test/test_#{ARGV[1]}.rb","w") { |f| f << TEST }
|
94
|
-
else
|
95
|
-
puts "Incorrect usage."
|
96
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
begin; require "rubygems"; rescue LoadError; end
|
2
|
-
require "rake/testtask"
|
3
|
-
|
4
|
-
task :default => [:test]
|
5
|
-
|
6
|
-
Rake::TestTask.new do |test|
|
7
|
-
test.libs << "test"
|
8
|
-
test.pattern = 'test/**/test_*.rb'
|
9
|
-
test.verbose = true
|
10
|
-
end
|
11
|
-
|
12
|
-
task :build do
|
13
|
-
if ENV['report']
|
14
|
-
sh "ruby util/build report #{ENV['report']}"
|
15
|
-
elsif ENV['renderer']
|
16
|
-
sh "ruby util/build renderer #{ENV['renderer']}"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
task :run do
|
21
|
-
sh "ruby lib/reports/#{ENV['report']}.rb"
|
22
|
-
end
|
23
|
-
|
24
|
-
task :use_utils do
|
25
|
-
raise "File lib/init_utils.rb exists!" if File.exist?('lib/init_utils.rb')
|
26
|
-
File.open('lib/init_utils.rb','w') { |f|
|
27
|
-
if ENV['only']
|
28
|
-
ENV['only'].split(',').each { |e|
|
29
|
-
f.puts "require 'ruport/util/#{e}'"
|
30
|
-
}
|
31
|
-
else
|
32
|
-
f.puts "require 'ruport/util'"
|
33
|
-
end
|
34
|
-
}
|
35
|
-
File.open('lib/init.rb','a') { |f|
|
36
|
-
f.puts '#comment out the line below to disable auto-loading of utils'
|
37
|
-
f.puts 'require "lib/init_utils.rb"'
|
38
|
-
}
|
39
|
-
end
|
File without changes
|
@@ -1,39 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require "rubygems"
|
3
|
-
gem "ruport","=0.9.6"
|
4
|
-
rescue LoadError
|
5
|
-
nil
|
6
|
-
end
|
7
|
-
require "ruport"
|
8
|
-
require "lib/helpers"
|
9
|
-
require "config/environment"
|
10
|
-
|
11
|
-
class String
|
12
|
-
def /(other)
|
13
|
-
self + "/" + other
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class Ruport::Report
|
18
|
-
|
19
|
-
def output_dir
|
20
|
-
config.output_dir or dir('output')
|
21
|
-
end
|
22
|
-
|
23
|
-
def data_dir
|
24
|
-
config.data_dir or dir('data')
|
25
|
-
end
|
26
|
-
|
27
|
-
def query_dir
|
28
|
-
config.query_dir or dir('sql')
|
29
|
-
end
|
30
|
-
|
31
|
-
def template_dir
|
32
|
-
config.template_dir or dir('templates')
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
def dir(name)
|
37
|
-
"/Users/mikem836/sales_report/#{name}"
|
38
|
-
end
|
39
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
require "lib/reports/sales"
|
@@ -1,132 +0,0 @@
|
|
1
|
-
require "lib/init"
|
2
|
-
|
3
|
-
module MyModule
|
4
|
-
class SalesRenderer < Ruport::Renderer
|
5
|
-
|
6
|
-
option :report_title
|
7
|
-
required_option :titles
|
8
|
-
|
9
|
-
stage :document_header, :document_body
|
10
|
-
|
11
|
-
finalize :document
|
12
|
-
end
|
13
|
-
|
14
|
-
class Text < Ruport::Formatter
|
15
|
-
renders :txt, :for => SalesRenderer
|
16
|
-
|
17
|
-
def pad(str, len)
|
18
|
-
return "".ljust(len) if str.nil?
|
19
|
-
str = str.slice(0, len) # truncate long strings
|
20
|
-
str.ljust(len) # pad with whitespace
|
21
|
-
end
|
22
|
-
|
23
|
-
def build_document_header
|
24
|
-
unless options.report_title.nil?
|
25
|
-
output << "".ljust(75,"*") << "\n"
|
26
|
-
output << " #{options.report_title}\n"
|
27
|
-
output << "".ljust(75,"*") << "\n"
|
28
|
-
output << "\n"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def build_document_body
|
33
|
-
# table heading
|
34
|
-
output << pad("isbn", 15) << "|" << pad("title",30) << "|"
|
35
|
-
output << pad("author", 15) << "|" << pad("sales", 10) << "\n"
|
36
|
-
output << "".ljust(75,"#") << "\n"
|
37
|
-
|
38
|
-
# table data
|
39
|
-
options.titles.each do |title|
|
40
|
-
output << pad(title["isbn"],15) << "|"
|
41
|
-
output << pad(title["title"],30) << "|"
|
42
|
-
output << pad(title["author"],15) << "|"
|
43
|
-
output << pad(title["sales"].to_s,10) << "\n"
|
44
|
-
end
|
45
|
-
|
46
|
-
output << "".ljust(75,"#") << "\n"
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
class PDF < Ruport::Formatter::PDF
|
52
|
-
renders :pdf, :for => SalesRenderer
|
53
|
-
|
54
|
-
def add_title( title )
|
55
|
-
rounded_text_box("<b>#{title}</b>") do |o|
|
56
|
-
o.fill_color = Color::RGB::Gray80
|
57
|
-
o.radius = 5
|
58
|
-
o.width = options.header_width || 200
|
59
|
-
o.height = options.header_height || 20
|
60
|
-
o.font_size = options.header_font_size || 12
|
61
|
-
o.x = pdf_writer.absolute_right_margin - o.width
|
62
|
-
o.y = pdf_writer.absolute_top_margin
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def build_document_header
|
67
|
-
add_title( options.report_title ) unless options.report_title.nil?
|
68
|
-
end
|
69
|
-
|
70
|
-
def build_document_body
|
71
|
-
pad(50) {
|
72
|
-
::PDF::SimpleTable.new do |table|
|
73
|
-
table.maximum_width = 500
|
74
|
-
table.orientation = :center
|
75
|
-
table.data = options.titles
|
76
|
-
table.column_order = %w[isbn title author sales]
|
77
|
-
table.render_on(pdf_writer)
|
78
|
-
end
|
79
|
-
}
|
80
|
-
end
|
81
|
-
|
82
|
-
def finalize_document
|
83
|
-
render_pdf
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
class Sales < Ruport::Report
|
91
|
-
|
92
|
-
attr_accessor :books, :format
|
93
|
-
|
94
|
-
def generate
|
95
|
-
MyModule::SalesRenderer.render(format) do |r|
|
96
|
-
r.report_title = "December 2006 Sales Figures"
|
97
|
-
r.titles = books
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
end
|
102
|
-
|
103
|
-
if __FILE__ == $0
|
104
|
-
|
105
|
-
book1 = {"isbn" => "978111111111",
|
106
|
-
"title" => "Book Number One",
|
107
|
-
"author" => "me", "sales" => 10}
|
108
|
-
|
109
|
-
book2 = { "isbn" => "978222222222",
|
110
|
-
"title" => "Two is better than one",
|
111
|
-
"author" => "you", "sales" => 267}
|
112
|
-
|
113
|
-
book3 = { "isbn" => "978333333333",
|
114
|
-
"title" => "Three Blind Mice",
|
115
|
-
"author" => "John Howard", "sales" => 1}
|
116
|
-
|
117
|
-
book4 = { "isbn" => "978444444444",
|
118
|
-
"title" => "The number 4",
|
119
|
-
"author" => "George Bush", "sales" => 1829}
|
120
|
-
|
121
|
-
books = [book1, book2, book3, book4]
|
122
|
-
|
123
|
-
report = Sales.new
|
124
|
-
|
125
|
-
report.books = books
|
126
|
-
|
127
|
-
[:pdf, :txt].each { |f|
|
128
|
-
report.format = f
|
129
|
-
report.run { |r| r.write "output/books.#{f}" }
|
130
|
-
}
|
131
|
-
|
132
|
-
end
|