ruport 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/LICENSE +55 -9
  2. data/Rakefile +3 -5
  3. data/examples/line_plotter.rb +3 -0
  4. data/examples/pdf_complex_report.rb +0 -1
  5. data/examples/pdf_report_with_common_base.rb +72 -0
  6. data/examples/pdf_styles.rb +16 -0
  7. data/examples/simple_pdf_lines.rb +0 -1
  8. data/lib/ruport.rb +5 -66
  9. data/lib/ruport/acts_as_reportable.rb +122 -51
  10. data/lib/ruport/data/grouping.rb +30 -13
  11. data/lib/ruport/data/record.rb +26 -25
  12. data/lib/ruport/data/table.rb +91 -34
  13. data/lib/ruport/formatter.rb +86 -11
  14. data/lib/ruport/formatter/csv.rb +29 -2
  15. data/lib/ruport/formatter/html.rb +23 -1
  16. data/lib/ruport/formatter/pdf.rb +123 -32
  17. data/lib/ruport/formatter/text.rb +62 -6
  18. data/lib/ruport/query.rb +75 -39
  19. data/lib/ruport/renderer.rb +250 -35
  20. data/lib/ruport/renderer/grouping.rb +2 -2
  21. data/test/html_formatter_test.rb +4 -1
  22. data/test/pdf_formatter_test.rb +30 -7
  23. data/test/query_test.rb +12 -0
  24. data/test/renderer_test.rb +33 -2
  25. data/test/table_test.rb +8 -2
  26. data/test/text_formatter_test.rb +11 -1
  27. metadata +53 -107
  28. data/bin/rope +0 -12
  29. data/examples/rope_examples/itunes/README +0 -12
  30. data/examples/rope_examples/itunes/Rakefile +0 -39
  31. data/examples/rope_examples/itunes/config/environment.rb +0 -4
  32. data/examples/rope_examples/itunes/data/mix.txt +0 -1
  33. data/examples/rope_examples/itunes/lib/helpers.rb +0 -0
  34. data/examples/rope_examples/itunes/lib/init.rb +0 -39
  35. data/examples/rope_examples/itunes/lib/reports.rb +0 -1
  36. data/examples/rope_examples/itunes/lib/reports/playlist.rb +0 -17
  37. data/examples/rope_examples/itunes/log/ruport.log +0 -1
  38. data/examples/rope_examples/itunes/test/test_playlist.rb +0 -8
  39. data/examples/rope_examples/itunes/util/build +0 -96
  40. data/examples/rope_examples/itunes/util/sql_exec +0 -5
  41. data/examples/rope_examples/sales_report/README +0 -4
  42. data/examples/rope_examples/sales_report/Rakefile +0 -39
  43. data/examples/rope_examples/sales_report/config/environment.rb +0 -4
  44. data/examples/rope_examples/sales_report/lib/helpers.rb +0 -0
  45. data/examples/rope_examples/sales_report/lib/init.rb +0 -39
  46. data/examples/rope_examples/sales_report/lib/reports.rb +0 -1
  47. data/examples/rope_examples/sales_report/lib/reports/sales.rb +0 -132
  48. data/examples/rope_examples/sales_report/log/ruport.log +0 -1
  49. data/examples/rope_examples/sales_report/output/books.pdf +0 -170
  50. data/examples/rope_examples/sales_report/output/books.txt +0 -11
  51. data/examples/rope_examples/sales_report/test/test_sales.rb +0 -8
  52. data/examples/rope_examples/sales_report/util/build +0 -96
  53. data/examples/rope_examples/sales_report/util/sql_exec +0 -5
  54. data/examples/sample.rb +0 -16
  55. data/lib/ruport/generator.rb +0 -294
  56. data/lib/ruport/report.rb +0 -262
  57. data/setup.rb +0 -1585
  58. data/test/report_test.rb +0 -218
  59. 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,4 +0,0 @@
1
- require "ruport"
2
-
3
- Ruport::Query.add_source :default, :user => "root",
4
- :dsn => "dbi:mysql:mydb"
@@ -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,8 +0,0 @@
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
@@ -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,5 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "lib/init"
4
-
5
- puts Ruport::Query.new(ARGF.read).result
@@ -1,4 +0,0 @@
1
- This example is based on the code in James Healy's excellent formatting system
2
- tutorial, but includes updated features from 0.9
3
-
4
- http://www.yob.id.au/articles/ruport_formatting_system.html
@@ -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,4 +0,0 @@
1
- require "ruport"
2
-
3
- Ruport::Query.add_source :default, :user => "root",
4
- :dsn => "dbi:mysql:mydb"
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