ruport 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/AUTHORS +1 -5
  2. data/README +4 -4
  3. data/Rakefile +2 -2
  4. data/examples/rope_examples/itunes/README +12 -0
  5. data/examples/rope_examples/itunes/Rakefile +18 -0
  6. data/examples/rope_examples/itunes/config/ruport_config.rb +8 -0
  7. data/examples/rope_examples/itunes/data/mix.txt +1 -0
  8. data/examples/rope_examples/itunes/lib/helpers.rb +0 -0
  9. data/examples/rope_examples/itunes/lib/init.rb +9 -0
  10. data/examples/rope_examples/itunes/lib/reports.rb +1 -0
  11. data/examples/rope_examples/itunes/lib/reports/playlist.rb +17 -0
  12. data/examples/rope_examples/itunes/log/ruport.log +1 -0
  13. data/examples/rope_examples/itunes/test/test_playlist.rb +8 -0
  14. data/examples/rope_examples/itunes/util/build +62 -0
  15. data/examples/rope_examples/itunes/util/sql_exec +5 -0
  16. data/examples/rope_examples/sales_report/README +4 -0
  17. data/examples/rope_examples/sales_report/Rakefile +18 -0
  18. data/examples/rope_examples/sales_report/config/ruport_config.rb +8 -0
  19. data/examples/rope_examples/sales_report/lib/helpers.rb +0 -0
  20. data/examples/rope_examples/sales_report/lib/init.rb +9 -0
  21. data/examples/rope_examples/sales_report/lib/reports.rb +1 -0
  22. data/examples/rope_examples/sales_report/lib/reports/sales.rb +138 -0
  23. data/examples/rope_examples/sales_report/log/ruport.log +1 -0
  24. data/examples/rope_examples/sales_report/output/books.pdf +170 -0
  25. data/examples/rope_examples/sales_report/output/books.txt +11 -0
  26. data/examples/rope_examples/sales_report/test/test_sales.rb +8 -0
  27. data/examples/rope_examples/sales_report/util/build +62 -0
  28. data/examples/rope_examples/sales_report/util/sql_exec +5 -0
  29. data/lib/ruport.rb +1 -1
  30. data/lib/ruport/data/groupable.rb +1 -1
  31. data/lib/ruport/data/record.rb +8 -8
  32. data/lib/ruport/data/table.rb +17 -14
  33. data/test/test_groupable.rb +14 -2
  34. data/test/test_table.rb +24 -0
  35. metadata +101 -60
  36. data/lib/ruport.rb.rej +0 -41
  37. data/lib/ruport.rb~ +0 -85
  38. data/lib/ruport/format/latex.rb.rej +0 -26
  39. data/lib/ruport/format/latex.rb~ +0 -47
  40. data/lib/ruport/format/pdf.rb.rej +0 -168
  41. data/lib/ruport/format/pdf.rb~ +0 -189
  42. data/test/unit.log +0 -259
data/AUTHORS CHANGED
@@ -4,6 +4,7 @@
4
4
  - {Dudley Flanders}[mailto:dudley@misnomer.us]
5
5
  - {James Healy}[mailto:jimmy@deefa.com]
6
6
  - Dinko Mehinovic
7
+ - {Michael Milner}[mailto:mikem836@gmail.com]
7
8
 
8
9
  = Contributors / People we've (legally) stolen from:
9
10
 
@@ -40,10 +41,5 @@ Marshall T. Vandegrift:
40
41
  Stefan Mahlitz:
41
42
  - Table#sort_rows_by
42
43
 
43
- Michael Milner
44
- - Refactoring for Table#column_names= (r436)
45
- - Mock object for Mailer
46
- - Mock object for Report (#130)
47
-
48
44
  Chris Carter
49
45
  - Table#remove_columns (r440)
data/README CHANGED
@@ -99,7 +99,7 @@
99
99
  #
100
100
  # = Bug Reports / Feature Requests
101
101
  #
102
- # Our Trac is at: http://stonecode.svnrepository.com
102
+ # Our Trac is at: http://code.stonecode.org
103
103
  # You may use the username ruport and password blinky to file tickets
104
104
  #
105
105
  # = Resources
@@ -123,7 +123,7 @@
123
123
  # http://rubyforge.org/projects/ruport
124
124
  #
125
125
  # - The latest stable API documentation is available at:
126
- # http://reporting.stonecode.org/docs
126
+ # http://api.rubyreports.org
127
127
  #
128
128
  # There are also some tutorial available:
129
129
  # http://stonecode.svnrepository.com/ruport/trac.cgi/wiki/TutorialsAndArticles
@@ -136,11 +136,11 @@
136
136
  #
137
137
  # - Grabbing the code from the svn trunk is simple:
138
138
  #
139
- # svn co svn://rubyforge.org//var/svn/ruport/trunk/
139
+ # svn co svn://rubyforge.org//var/svn/ruport/trunk/ ruport
140
140
  #
141
141
  # - Or if you are interested in the latest updates to the stable branch
142
142
  #
143
- # svn co svn://rubyforge.org//var/svn/ruport/branches/stable
143
+ # svn co svn://rubyforge.org//var/svn/ruport/branches/stable ruport
144
144
  #
145
145
  # Thanks for checking out Ruport!
146
146
  #
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.8.0"
26
+ spec.version = "0.8.1"
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}/**/**/*") +
@@ -40,7 +40,7 @@ spec = Gem::Specification.new do |spec|
40
40
  '--main' << 'README' << '-q'
41
41
  unless LEAN
42
42
  spec.add_dependency('fastercsv', '>= 1.1.0')
43
- spec.add_dependency('RedCloth', '>= 3.0.4')
43
+ spec.add_dependency('RedCloth', '>= 3.0.3')
44
44
  spec.add_dependency('pdf-writer', '>= 1.1.3')
45
45
  spec.add_dependency("mailfactory", ">= 1.2.3")
46
46
  spec.add_dependency('scruffy', '>= 0.2.2')
@@ -0,0 +1,12 @@
1
+ - this is an up to date version of the code in Chris Carter's tutorial at:
2
+ http://concentrationstudios.com/2007/1/21/ruports
3
+
4
+ To run the report do:
5
+
6
+ ruby app/reports/playlist.rb
7
+
8
+ or
9
+
10
+ rake run report=playlist
11
+
12
+ It will generate a pdf in output/
@@ -0,0 +1,18 @@
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
+ sh "ruby util/build report #{ENV['report']}"
14
+ end
15
+
16
+ task :run do
17
+ sh "ruby lib/reports/#{ENV['report']}.rb"
18
+ end
@@ -0,0 +1,8 @@
1
+ require "ruport"
2
+
3
+ # For details, see Ruport::Config documentation
4
+ Ruport.configure { |c|
5
+ c.source :default, :user => "root",
6
+ :dsn => "dbi:mysql:mydb"
7
+ c.log_file "log/ruport.log"
8
+ }
@@ -0,0 +1 @@
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
@@ -0,0 +1,9 @@
1
+ begin
2
+ require "rubygems"
3
+ gem "ruport","=0.8.0"
4
+ rescue LoadError
5
+ nil
6
+ end
7
+ require "ruport"
8
+ require "lib/helpers"
9
+ require "config/ruport_config"
@@ -0,0 +1 @@
1
+ require "lib/reports/playlist"
@@ -0,0 +1,17 @@
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
@@ -0,0 +1 @@
1
+ # Logfile created on Sat Feb 03 19:38:27 -0500 2007 by logger.rb/1.5.2.9
@@ -0,0 +1,8 @@
1
+ require "test/unit"
2
+ require "lib/reports/playlist"
3
+
4
+ class TestPlaylist < Test::Unit::TestCase
5
+ def test_flunk
6
+ flunk "Write your real tests here or in any test/test_* file"
7
+ end
8
+ end
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fileutils'
4
+ include FileUtils
5
+
6
+ def format_class_name(string)
7
+ string.downcase.split("_").map { |s| s.capitalize }.join
8
+ end
9
+
10
+ unless ARGV.length > 1
11
+ puts "usage: build [command] [options]"
12
+ exit
13
+ end
14
+
15
+ class_name = format_class_name(ARGV[1])
16
+
17
+ exit if File.exist? "lib/reports/#{ARGV[1]}.rb"
18
+ if ARGV[0].eql? "report"
19
+ File.open("lib/reports.rb", "a") { |f|
20
+ f.puts("require \"lib/reports/#{ARGV[1]}\"")
21
+ }
22
+ REP = <<EOR
23
+ require "lib/init"
24
+ class #{class_name} < Ruport::Report
25
+
26
+ def prepare
27
+
28
+ end
29
+
30
+ def generate
31
+
32
+ end
33
+
34
+ def cleanup
35
+
36
+ end
37
+
38
+ end
39
+
40
+ if __FILE__ == $0
41
+ #{class_name}.run { |res| puts res.results }
42
+ end
43
+ EOR
44
+
45
+ TEST = <<EOR
46
+ require "test/unit"
47
+ require "lib/reports/#{ARGV[1]}"
48
+
49
+ class Test#{class_name} < Test::Unit::TestCase
50
+ def test_flunk
51
+ flunk "Write your real tests here or in any test/test_* file"
52
+ end
53
+ end
54
+ EOR
55
+ puts "report file: lib/reports/#{ARGV[1]}.rb"
56
+ File.open("lib/reports/#{ARGV[1]}.rb", "w") { |f| f << REP }
57
+ puts "test file: test/test_#{ARGV[1]}.rb"
58
+ puts "class name: #{class_name}"
59
+ File.open("test/test_#{ARGV[1]}.rb","w") { |f| f << TEST }
60
+ else
61
+ puts "Incorrect usage."
62
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "lib/init"
4
+
5
+ puts Ruport::Query.new(ARGF.read).result
@@ -0,0 +1,4 @@
1
+ This example is based on the code in James Healy's excellent formatting system
2
+ tutorial, but includes updated features from 0.8
3
+
4
+ http://www.yob.id.au/articles/ruport_formatting_system.html
@@ -0,0 +1,18 @@
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
+ sh "ruby util/build report #{ENV['report']}"
14
+ end
15
+
16
+ task :run do
17
+ sh "ruby lib/reports/#{ENV['report']}.rb"
18
+ end
@@ -0,0 +1,8 @@
1
+ require "ruport"
2
+
3
+ # For details, see Ruport::Config documentation
4
+ Ruport.configure { |c|
5
+ c.source :default, :user => "root",
6
+ :dsn => "dbi:mysql:mydb"
7
+ c.log_file "log/ruport.log"
8
+ }
@@ -0,0 +1,9 @@
1
+ begin
2
+ require "rubygems"
3
+ gem "ruport","=0.8.0"
4
+ rescue LoadError
5
+ nil
6
+ end
7
+ require "ruport"
8
+ require "lib/helpers"
9
+ require "config/ruport_config"
@@ -0,0 +1 @@
1
+ require "lib/reports/sales"
@@ -0,0 +1,138 @@
1
+ require "lib/init"
2
+
3
+ module MyModule
4
+ class SalesRenderer < Ruport::Renderer
5
+
6
+ include Ruport::Renderer::Helpers
7
+
8
+ required_option :report_title
9
+ required_option :titles
10
+
11
+ stage :document_header
12
+ stage :document_body
13
+
14
+ finalize :document
15
+ end
16
+
17
+ class Text < Ruport::Format::Plugin
18
+
19
+ SalesRenderer.add_format self, :txt
20
+
21
+ def pad(str, len)
22
+ return "".ljust(len) if str.nil?
23
+ str = str.slice(0, len) # truncate long strings
24
+ str.ljust(len) # pad with whitespace
25
+ end
26
+
27
+ def build_document_header
28
+ unless options.report_title.nil?
29
+ output << "".ljust(75,"*") << "\n"
30
+ output << " #{options.report_title}\n"
31
+ output << "".ljust(75,"*") << "\n"
32
+ output << "\n"
33
+ end
34
+ end
35
+
36
+ def build_document_body
37
+ # table heading
38
+ output << pad("isbn", 15) << "|" << pad("title",30) << "|"
39
+ output << pad("author", 15) << "|" << pad("sales", 10) << "\n"
40
+ output << "".ljust(75,"#") << "\n"
41
+
42
+ # table data
43
+ options.titles.each do |title|
44
+ output << pad(title["isbn"],15) << "|"
45
+ output << pad(title["title"],30) << "|"
46
+ output << pad(title["author"],15) << "|"
47
+ output << pad(title["sales"].to_s,10) << "\n"
48
+ end
49
+
50
+ output << "".ljust(75,"#") << "\n"
51
+ end
52
+
53
+ def finalize_document; output end
54
+
55
+ end
56
+
57
+ class PDF < Ruport::Format::PDF
58
+ SalesRenderer.add_format self, :pdf
59
+
60
+ def add_title( title )
61
+ rounded_text_box("<b>#{title}</b>") do |o|
62
+ o.fill_color = Color::RGB::Gray80
63
+ o.radius = 5
64
+ o.width = layout.header_width || 200
65
+ o.height = layout.header_height || 20
66
+ o.font_size = layout.header_font_size || 12
67
+ o.x = pdf_writer.absolute_right_margin - o.width
68
+ o.y = pdf_writer.absolute_top_margin
69
+ end
70
+ end
71
+
72
+ def build_document_header
73
+ add_title( options.report_title ) unless options.report_title.nil?
74
+ end
75
+
76
+ def build_document_body
77
+ pad(50) {
78
+ ::PDF::SimpleTable.new do |table|
79
+ table.maximum_width = 500
80
+ table.orientation = :center
81
+ table.data = options.titles
82
+ table.column_order = %w[isbn title author sales]
83
+ table.render_on(pdf_writer)
84
+ end
85
+ }
86
+ end
87
+
88
+ def finalize_document
89
+ output << pdf_writer.render
90
+ end
91
+
92
+ end
93
+
94
+ end
95
+
96
+ class Sales < Ruport::Report
97
+
98
+ attr_accessor :books, :format
99
+
100
+ def generate
101
+ MyModule::SalesRenderer.render(format) do |r|
102
+ r.report_title = "December 2006 Sales Figures"
103
+ r.titles = books
104
+ end
105
+ end
106
+
107
+ end
108
+
109
+ if __FILE__ == $0
110
+
111
+ book1 = {"isbn" => "978111111111",
112
+ "title" => "Book Number One",
113
+ "author" => "me", "sales" => 10}
114
+
115
+ book2 = { "isbn" => "978222222222",
116
+ "title" => "Two is better than one",
117
+ "author" => "you", "sales" => 267}
118
+
119
+ book3 = { "isbn" => "978333333333",
120
+ "title" => "Three Blind Mice",
121
+ "author" => "John Howard", "sales" => 1}
122
+
123
+ book4 = { "isbn" => "978444444444",
124
+ "title" => "The number 4",
125
+ "author" => "George Bush", "sales" => 1829}
126
+
127
+ books = [book1, book2, book3, book4]
128
+
129
+ report = Sales.new
130
+
131
+ report.books = books
132
+
133
+ [:pdf, :txt].each { |f|
134
+ report.format = f
135
+ report.run { |r| r.write "output/books.#{f}" }
136
+ }
137
+
138
+ end
@@ -0,0 +1 @@
1
+ # Logfile created on Sat Feb 03 20:02:43 -0500 2007 by logger.rb/1.5.2.9
@@ -0,0 +1,170 @@
1
+ %PDF-1.3
2
+ %����
3
+
4
+ 1 0 obj
5
+ << /Type /Catalog
6
+ /Outlines 2 0 R
7
+ /Pages 3 0 R>>
8
+ endobj
9
+ 2 0 obj
10
+ << /Type /Outlines >>
11
+ endobj
12
+ 3 0 obj
13
+ << /Type /Pages
14
+ /Kids [6 0 R
15
+ ]
16
+ /Count 1
17
+ /Resources <<
18
+ /ProcSet 4 0 R
19
+ /Font <<
20
+ /F1 8 0 R
21
+ /F2 10 0 R >>
22
+ >>
23
+ /MediaBox [0 0 612.0 792.0]
24
+ >>
25
+ endobj
26
+ 4 0 obj
27
+ [/PDF /Text ]
28
+ endobj
29
+ 5 0 obj
30
+ <<
31
+ /CreationDate (D:200702040113)
32
+ /Creator (sales.rb)
33
+ /Producer (PDF::Writer for Ruby)
34
+ >>
35
+ endobj
36
+ 6 0 obj
37
+ << /Type /Page
38
+ /Parent 3 0 R
39
+ /Contents [
40
+ 7 0 R
41
+ 11 0 R
42
+ ]
43
+ >>
44
+ endobj
45
+ 7 0 obj
46
+ <<
47
+ /Length 811 >>
48
+ stream
49
+
50
+ 0.000 0.000 0.000 rg
51
+ 0.000 0.000 0.000 RG
52
+ q
53
+ 0.800 0.800 0.800 rg
54
+ 381.000 756.000 m
55
+ 571.000 756.000 l
56
+ 573.500 756.000 576.000 753.500 576.000 751.000 c
57
+ 576.000 741.000 l
58
+ 576.000 738.500 573.500 736.000 571.000 736.000 c
59
+ 381.000 736.000 l
60
+ 378.500 736.000 376.000 738.500 376.000 741.000 c
61
+ 376.000 751.000 l
62
+ 376.000 753.500 378.500 756.000 381.000 756.000 c
63
+ 576.000 736.000 m B
64
+ 1 w
65
+ Q
66
+ BT 391.292 742.128 Td /F2 12.0 Tf 0 Tr (December 2006 Sales Figures) Tj ET
67
+ 0.800 0.800 0.800 RG
68
+ BT 158.443 670.128 Td /F1 12.0 Tf 0 Tr (isbn) Tj ET
69
+ BT 235.830 670.128 Td /F1 12.0 Tf 0 Tr (title) Tj ET
70
+ BT 345.760 670.128 Td /F1 12.0 Tf 0 Tr (author) Tj ET
71
+ BT 415.269 670.128 Td /F1 12.0 Tf 0 Tr (sales) Tj ET
72
+ q
73
+ 0.800 0.800 0.800 rg
74
+ 153.443 648.068 295.114 15.560 re f
75
+ 0.800 0.800 0.800 rg
76
+ 153.443 616.948 295.114 15.560 re f
77
+ 1 w
78
+ Q
79
+ endstream
80
+ endobj
81
+
82
+ 8 0 obj
83
+ << /Type /Font
84
+ /Subtype /Type1
85
+ /Name /F1
86
+ /BaseFont /Helvetica
87
+ /Encoding /WinAnsiEncoding
88
+ >>
89
+ endobj
90
+ 9 0 obj
91
+ << /Type /Encoding
92
+ /BaseEncoding /WinAnsiEncoding
93
+
94
+ >>
95
+ endobj
96
+ 10 0 obj
97
+ << /Type /Font
98
+ /Subtype /Type1
99
+ /Name /F2
100
+ /BaseFont /Helvetica-Bold
101
+ /Encoding 9 0 R
102
+ >>
103
+ endobj
104
+ 11 0 obj
105
+ <<
106
+ /Length 1255 >>
107
+ stream
108
+
109
+ BT 158.443 652.318 Td /F1 10.0 Tf 0 Tr (978111111111) Tj ET
110
+ BT 235.830 652.318 Td /F1 10.0 Tf 0 Tr (Book Number One) Tj ET
111
+ BT 345.760 652.318 Td /F1 10.0 Tf 0 Tr (me) Tj ET
112
+ BT 415.269 652.318 Td /F1 10.0 Tf 0 Tr (10) Tj ET
113
+ BT 158.443 636.758 Td /F1 10.0 Tf 0 Tr (978222222222) Tj ET
114
+ BT 235.830 636.758 Td /F1 10.0 Tf 0 Tr (Two is better than one) Tj ET
115
+ BT 345.760 636.758 Td /F1 10.0 Tf 0 Tr (you) Tj ET
116
+ BT 415.269 636.758 Td /F1 10.0 Tf 0 Tr (267) Tj ET
117
+ BT 158.443 621.198 Td /F1 10.0 Tf 0 Tr (978333333333) Tj ET
118
+ BT 235.830 621.198 Td /F1 10.0 Tf 0 Tr (Three Blind Mice) Tj ET
119
+ BT 345.760 621.198 Td /F1 10.0 Tf 0 Tr (John Howard) Tj ET
120
+ BT 415.269 621.198 Td /F1 10.0 Tf 0 Tr (1) Tj ET
121
+ BT 158.443 605.638 Td /F1 10.0 Tf 0 Tr (978444444444) Tj ET
122
+ BT 235.830 605.638 Td /F1 10.0 Tf 0 Tr (The number 4) Tj ET
123
+ BT 345.760 605.638 Td /F1 10.0 Tf 0 Tr (George Bush) Tj ET
124
+ BT 415.269 605.638 Td /F1 10.0 Tf 0 Tr (1829) Tj ET
125
+ 0.000 0.000 0.000 RG
126
+ 1 w
127
+ 153.443 686.000 m
128
+ 153.443 601.388 l S
129
+ 1 w
130
+ 230.830 686.000 m
131
+ 230.830 601.388 l S
132
+ 340.760 686.000 m
133
+ 340.760 601.388 l S
134
+ 410.269 686.000 m
135
+ 410.269 601.388 l S
136
+ 1 w
137
+ 448.557 686.000 m
138
+ 448.557 601.388 l S
139
+ 152.943 686.000 m
140
+ 449.057 686.000 l S
141
+ 153.443 665.878 m
142
+ 448.557 665.878 l S
143
+ 152.943 601.388 m
144
+ 449.057 601.388 l S
145
+ endstream
146
+ endobj
147
+
148
+ xref
149
+ 0 12
150
+ 0000000000 65535 f
151
+ 0000000015 00000 n
152
+ 0000000079 00000 n
153
+ 0000000116 00000 n
154
+ 0000000269 00000 n
155
+ 0000000298 00000 n
156
+ 0000000403 00000 n
157
+ 0000000477 00000 n
158
+ 0000001340 00000 n
159
+ 0000001447 00000 n
160
+ 0000001516 00000 n
161
+ 0000001618 00000 n
162
+
163
+ trailer
164
+ << /Size 12
165
+ /Root 1 0 R
166
+ /Info 5 0 R
167
+ >>
168
+ startxref
169
+ 2927
170
+ %%EOF