ruport 0.7.2 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/AUTHORS +7 -3
  2. data/Rakefile +8 -9
  3. data/TODO +16 -0
  4. data/examples/RWEmerson.jpg +0 -0
  5. data/examples/centered_pdf_text_box.rb +66 -0
  6. data/examples/invoice.rb +35 -25
  7. data/examples/invoice_report.rb +1 -1
  8. data/examples/line_plotter.rb +1 -1
  9. data/examples/pdf_table_with_title.rb +42 -0
  10. data/lib/ruport.rb +5 -7
  11. data/lib/ruport.rb.rej +41 -0
  12. data/lib/ruport.rb~ +85 -0
  13. data/lib/ruport/attempt.rb +59 -59
  14. data/lib/ruport/config.rb +15 -4
  15. data/lib/ruport/data.rb +0 -2
  16. data/lib/ruport/data/groupable.rb +25 -16
  17. data/lib/ruport/data/record.rb +128 -102
  18. data/lib/ruport/data/table.rb +352 -199
  19. data/lib/ruport/data/taggable.rb +18 -7
  20. data/lib/ruport/format/html.rb +3 -1
  21. data/lib/ruport/format/latex.rb +1 -1
  22. data/lib/ruport/format/latex.rb.rej +26 -0
  23. data/lib/ruport/format/latex.rb~ +47 -0
  24. data/lib/ruport/format/pdf.rb +111 -28
  25. data/lib/ruport/format/pdf.rb.rej +168 -0
  26. data/lib/ruport/format/pdf.rb~ +189 -0
  27. data/lib/ruport/format/plugin.rb +0 -5
  28. data/lib/ruport/format/svg.rb +4 -4
  29. data/lib/ruport/format/xml.rb +3 -3
  30. data/lib/ruport/generator.rb +66 -27
  31. data/lib/ruport/mailer.rb +4 -1
  32. data/lib/ruport/query.rb +13 -1
  33. data/lib/ruport/renderer.rb +89 -17
  34. data/lib/ruport/renderer/graph.rb +5 -5
  35. data/lib/ruport/renderer/table.rb +8 -9
  36. data/lib/ruport/report.rb +2 -6
  37. data/test/test_config.rb +88 -76
  38. data/test/{test_text_table.rb → test_format_text.rb} +4 -2
  39. data/test/test_groupable.rb +15 -13
  40. data/test/test_query.rb +6 -3
  41. data/test/test_record.rb +57 -33
  42. data/test/test_renderer.rb +77 -0
  43. data/test/test_report.rb +188 -181
  44. data/test/test_ruport.rb +5 -6
  45. data/test/test_table.rb +290 -190
  46. data/test/test_table_renderer.rb +56 -8
  47. data/test/test_taggable.rb +7 -8
  48. data/test/unit.log +259 -7
  49. metadata +22 -19
  50. data/lib/ruport/data/collection.rb +0 -65
  51. data/lib/ruport/data/set.rb +0 -148
  52. data/test/test_collection.rb +0 -30
  53. data/test/test_set.rb +0 -118
data/AUTHORS CHANGED
@@ -40,6 +40,10 @@ Marshall T. Vandegrift:
40
40
  Stefan Mahlitz:
41
41
  - Table#sort_rows_by
42
42
 
43
- Mike Milner:
44
- - mock object for Mailer
45
- - mock objects for Report (#130)
43
+ Michael Milner
44
+ - Refactoring for Table#column_names= (r436)
45
+ - Mock object for Mailer
46
+ - Mock object for Report (#130)
47
+
48
+ Chris Carter
49
+ - Table#remove_columns (r440)
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.7.2"
26
+ spec.version = "0.8.0"
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}/**/**/*") +
@@ -39,10 +39,10 @@ spec = Gem::Specification.new do |spec|
39
39
  spec.rdoc_options << '--title' << 'Ruport Documentation' <<
40
40
  '--main' << 'README' << '-q'
41
41
  unless LEAN
42
- spec.add_dependency('fastercsv', '>= 0.1.0')
43
- spec.add_dependency('RedCloth', '>= 3.0.0')
42
+ spec.add_dependency('fastercsv', '>= 1.1.0')
43
+ spec.add_dependency('RedCloth', '>= 3.0.4')
44
44
  spec.add_dependency('pdf-writer', '>= 1.1.3')
45
- spec.add_dependency("mailfactory", ">= 1.2.2")
45
+ spec.add_dependency("mailfactory", ">= 1.2.3")
46
46
  spec.add_dependency('scruffy', '>= 0.2.2')
47
47
  end
48
48
  spec.author = "Gregory Brown"
@@ -50,16 +50,15 @@ spec = Gem::Specification.new do |spec|
50
50
  spec.rubyforge_project = "ruport"
51
51
  spec.homepage = "http://reporting.stonecode.org"
52
52
  spec.description = <<END_DESC
53
- Ruport is a powerful report generation engine that allows users to generate
54
- custom ERb templates and easily query various forms of SQL databases via DBI.
55
- It provides helper methods and utilities to generate professional reports
56
- quickly and cleanly.
53
+ Ruby Reports is a software library that aims to make the task of reporting
54
+ less tedious and painful. It provides tools for data acquisition,
55
+ database interaction, formatting, and parsing/munging.
57
56
  END_DESC
58
57
  end
59
58
 
60
59
  Rake::RDocTask.new do |rdoc|
61
60
  rdoc.rdoc_files.include( "README",
62
- "TODO", "CHANGELOG",
61
+ "TODO", #"CHANGELOG",
63
62
  "AUTHORS", "COPYING",
64
63
  "LICENSE", "lib/" )
65
64
  rdoc.main = "README"
data/TODO CHANGED
@@ -1,5 +1,21 @@
1
1
  = TODO
2
2
 
3
+ --
4
+
5
+ * fix whitespace
6
+
7
+ * table should have record_class constructor
8
+
9
+ * logging in util/build.rb?
10
+
11
+ * Table#add_row ?
12
+
13
+ * Table#col_merge
14
+
15
+ * Table#join
16
+
17
+ --
18
+
3
19
  - Any future plans are available on Ruport's Trac website
4
20
 
5
21
  http://stonecode.svnrepository.com/ruport/trac.cgi
Binary file
@@ -0,0 +1,66 @@
1
+ require "ruport"
2
+
3
+ class Document < Ruport::Renderer
4
+
5
+ include Ruport::Renderer::Helpers
6
+
7
+ required_option :text
8
+ required_option :author
9
+ option :heading
10
+
11
+ stage :document_body
12
+ finalize :document
13
+ end
14
+
15
+
16
+ class CenteredPDFTextBox < Ruport::Format::PDF
17
+
18
+ Document.add_format self, :pdf
19
+
20
+ def build_document_body
21
+
22
+ add_text "-- " << options.author << " --",
23
+ :justification => :center, :font_size => 20
24
+
25
+
26
+ c = pdf_writer.absolute_x_middle - 239/2
27
+
28
+ #img,x,y,width,height
29
+ center_image_in_box("RWEmerson.jpg",c,325,239,359)
30
+
31
+ rounded_text_box(options.text) do |o|
32
+ o.radius = 5
33
+ o.width = layout.width || 400
34
+ o.height = layout.height || 130
35
+ o.font_size = layout.font_size || 12
36
+ o.heading = options.heading
37
+
38
+ o.x = pdf_writer.absolute_x_middle - o.width/2
39
+ o.y = 300
40
+ end
41
+
42
+ end
43
+
44
+ def finalize_document
45
+ output << pdf_writer.render
46
+ end
47
+ end
48
+
49
+ a = Document.render_pdf { |r|
50
+ r.heading = "a good quote"
51
+ r.author = "Ralph Waldo Emerson"
52
+ r.text = <<EOS
53
+ A foolish consistency is the hobgoblin of little minds, adored by little
54
+ statesmen and philosophers and divines. With consistency a great soul has simply
55
+ nothing to do. He may as well concern himself with his shadow on the wall. Speak
56
+ what you think now in hard words and to-morrow speak what to-morrow thinks in
57
+ hard words again, though it contradict every thing you said to-day.--"Ah, so you
58
+ shall be sure to be misunderstood."--Is it so bad then to be misunderstood?
59
+ Pythagoras was misunderstood, and Socrates, and Jesus, and Luther, and
60
+ Copernicus, and Galileo, and Newton, and every pure and wise spirit that ever
61
+ took flesh. To be great is to be misunderstood. . . .
62
+ EOS
63
+
64
+ }
65
+
66
+ puts a
data/examples/invoice.rb CHANGED
@@ -3,22 +3,18 @@ module Ruport
3
3
  class Invoice < Ruport::Renderer
4
4
 
5
5
  include Renderer::Helpers
6
-
7
- def init_options
8
- options do |o|
9
- o.customer_info ||= ""
10
- o.company_info ||= ""
11
- o.comments ||= ""
12
- o.order_info ||= ""
13
- o.title ||= ""
14
- end
15
- end
6
+
7
+ required_option :customer_info
8
+ required_option :company_info
9
+ required_option :order_info
10
+ option :title
11
+ required_option :comments
16
12
 
17
- def run
18
- init_options
19
- build [:headers,:body,:footer], :invoice
20
- finalize :invoice
21
- end
13
+ stage :invoice_headers
14
+ stage :invoice_body
15
+ stage :invoice_footer
16
+
17
+ finalize :invoice
22
18
 
23
19
  module InvoiceHelpers
24
20
  def build_company_header
@@ -27,23 +23,37 @@ module Ruport
27
23
  end
28
24
 
29
25
  def build_customer_header
30
- pdf_writer.y -= 10
26
+ move_cursor -10
31
27
  text_box(options.customer_info)
32
28
  end
33
29
 
34
30
  def build_title
35
- pdf_writer.y = @tod
36
- if options.title
37
- pdf_writer.text options.title, :left => 350,
38
- :font_size => layout.title_font_size || 14
39
- pdf_writer.y -= 10
40
- end
31
+ add_title(options.title) if options.title
41
32
  end
33
+
34
+ def add_title( title )
35
+ rounded_text_box("<b>#{title}</b>") do |o|
36
+ o.fill_color = Color::RGB::Gray80
37
+ o.radius = 5
38
+ o.width = layout.header_width || 200
39
+ o.height = layout.header_height || 20
40
+ o.font_size = layout.header_font_size || 11
41
+ o.x = pdf_writer.absolute_right_margin - o.width
42
+ o.y = pdf_writer.absolute_top_margin
43
+ end
44
+ end
42
45
 
43
46
  def build_order_header
44
47
  if options.order_info
45
- text_box(options.order_info,
46
- :position => layout.order_info_position || 350)
48
+ rounded_text_box("<b>#{options.order_info}</b>") do |o|
49
+ o.radius = 5
50
+ o.heading = "Billing Information"
51
+ o.width = layout.header_width || 200
52
+ o.height = layout.header_height || 80
53
+ o.font_size = layout.header_font_size || 10
54
+ o.x = pdf_writer.absolute_right_margin - o.width
55
+ o.y = pdf_writer.absolute_top_margin - 25
56
+ end
47
57
  end
48
58
  end
49
59
 
@@ -81,7 +91,7 @@ module Ruport
81
91
  def build_invoice_body
82
92
 
83
93
  pdf_writer.start_page_numbering(500,20,8,:right)
84
- pdf_writer.y = 620
94
+ pdf_writer.y = 550
85
95
 
86
96
  Ruport::Renderer::Table.render_pdf { |r|
87
97
  r.data = data
@@ -14,7 +14,7 @@ class SampleReport < Ruport::Report
14
14
  o.customer_info = "Gregory Brown\n200 Foo Ave."
15
15
  o.comments = "J. Random Comment"
16
16
  o.order_info = "Some info\nabout your order"
17
- o.title = "Hey There"
17
+ o.title = "Invoice for 12.15.2006 - 12.31.2006"
18
18
  end
19
19
 
20
20
  i.layout do |lay|
@@ -28,7 +28,7 @@ class SVG < Ruport::Format::Plugin
28
28
 
29
29
  def initialize
30
30
  require "builder"
31
- @builder = Builder::XmlMarkup.new(:indent => 2)
31
+ @builder = Builder::XmlMarkup.new(:indent => 2)
32
32
  end
33
33
 
34
34
  def render_plot
@@ -0,0 +1,42 @@
1
+ require "ruport"
2
+
3
+ class TitledPDFTable < Ruport::Format::PDF
4
+
5
+ Ruport::Renderer::Table.add_format self, :titled_pdf
6
+
7
+ def add_title( title )
8
+ rounded_text_box("<b>#{title}</b>") do |o|
9
+ o.fill_color = Color::RGB::Gray80
10
+ o.radius = 5
11
+ o.width = layout.header_width || 200
12
+ o.height = layout.header_height || 20
13
+ o.font_size = layout.header_font_size || 12
14
+ o.x = pdf_writer.absolute_right_margin - o.width
15
+ o.y = pdf_writer.absolute_top_margin
16
+ end
17
+ end
18
+
19
+ def prepare_table
20
+ layout.header_margin ||= 50
21
+ end
22
+
23
+ def build_table_header
24
+ add_title options.title
25
+ move_cursor -layout.header_margin
26
+ end
27
+
28
+ end
29
+
30
+
31
+ a = Ruport::Renderer::Table.render_titled_pdf { |r|
32
+ r.options.title = "This is a sample header"
33
+ r.data = Table(%w[a b]) { |t| t << [1,2] << [3,4] }
34
+ # NOTE: uncomment some options to play with layout
35
+ r.layout do |la|
36
+ # la.header_margin = 25
37
+ # la.header_width = 250
38
+ # la.header_height = 50
39
+ end
40
+ }
41
+
42
+ puts a
data/lib/ruport.rb CHANGED
@@ -9,9 +9,10 @@
9
9
  #
10
10
  # See LICENSE and COPYING for details
11
11
  #
12
+
12
13
  module Ruport
13
14
 
14
- VERSION = "0.7.2"
15
+ VERSION = "0.8.0"
15
16
 
16
17
  # This method is Ruport's logging and error interface. It can generate
17
18
  # warnings or raise fatal errors, logging +message+ to the file defined by
@@ -45,13 +46,10 @@ module Ruport
45
46
  options[:level].eql?(:log_only) and not Ruport::Config.debug_mode?
46
47
  Ruport::Config::logger.send(options[:status],message) if Config.logger
47
48
  if options[:status].eql? :fatal
48
- raise(options[:exception] || RuntimeError, message)
49
+ raise(options[:raises] || RuntimeError, message)
49
50
  end
50
- end
51
-
52
- # Alias for <tt>Ruport.log</tt>.
53
- def self.complain(*args); Ruport.log(*args) end
54
-
51
+ end
52
+
55
53
  # This method yields a <tt>Ruport::Config</tt> object, allowing you to
56
54
  # set the configuration options for your application.
57
55
  #
data/lib/ruport.rb.rej ADDED
@@ -0,0 +1,41 @@
1
+ ***************
2
+ *** 9,20 ****
3
+ #
4
+ # See LICENSE and COPYING for details
5
+ #
6
+ -
7
+ module Ruport
8
+
9
+ VERSION = "0.7.2"
10
+
11
+ - #
12
+ # This method is Ruport's logging and error interface. It can generate
13
+ # warnings or raise fatal errors, logging +message+ to the file defined by
14
+ # <tt>Config::log_file</tt>.
15
+ --- 9,18 ----
16
+ #
17
+ # See LICENSE and COPYING for details
18
+ #
19
+ module Ruport
20
+
21
+ VERSION = "0.7.2"
22
+
23
+ # This method is Ruport's logging and error interface. It can generate
24
+ # warnings or raise fatal errors, logging +message+ to the file defined by
25
+ # <tt>Config::log_file</tt>.
26
+ ***************
27
+ *** 54,60 ****
28
+ # Alias for <tt>Ruport.log</tt>.
29
+ def self.complain(*args); Ruport.log(*args) end
30
+
31
+ - #
32
+ # This method yields a <tt>Ruport::Config</tt> object, allowing you to
33
+ # set the configuration options for your application.
34
+ #
35
+ --- 52,57 ----
36
+ # Alias for <tt>Ruport.log</tt>.
37
+ def self.complain(*args); Ruport.log(*args) end
38
+
39
+ # This method yields a <tt>Ruport::Config</tt> object, allowing you to
40
+ # set the configuration options for your application.
41
+ #
data/lib/ruport.rb~ ADDED
@@ -0,0 +1,85 @@
1
+ # ruport.rb : Ruby Reports top level module
2
+ #
3
+ # Author: Gregory T. Brown (gregory.t.brown at gmail dot com)
4
+ #
5
+ # Copyright (c) 2006, All Rights Reserved.
6
+ #
7
+ # This is free software. You may modify and redistribute this freely under
8
+ # your choice of the GNU General Public License or the Ruby License.
9
+ #
10
+ # See LICENSE and COPYING for details
11
+ #
12
+
13
+ module Ruport
14
+
15
+ VERSION = "0.7.99"
16
+
17
+ #
18
+ # This method is Ruport's logging and error interface. It can generate
19
+ # warnings or raise fatal errors, logging +message+ to the file defined by
20
+ # <tt>Config::log_file</tt>.
21
+ #
22
+ # You can configure the logging preferences with the +options+ hash.
23
+ # Available options are:
24
+ #
25
+ # <b><tt>:status</tt></b>:: Sets the severity level. This defaults to
26
+ # <tt>:warn</tt>, which will invoke
27
+ # <tt>Logger#warn</tt>. A status of
28
+ # <tt>:fatal</tt> will invoke
29
+ # <tt>Logger#fatal</tt> and raise an exception.
30
+ # <b><tt>:output</tt></b>:: Optional 2nd output. By default, <tt>log()</tt>
31
+ # will print warnings to <tt>$stderr</tt> in
32
+ # addition to <tt>Config::log_file</tt>. You
33
+ # can redirect this to any I/O object with this
34
+ # option.
35
+ # <b><tt>:level</tt></b>:: Set this to <tt>:log_only</tt> to disable
36
+ # secondary output. If you want to globally
37
+ # override this setting for all calls to
38
+ # <tt>log()</tt> (which can be useful for
39
+ # debugging), you can set
40
+ # <tt>Config.debug_mode</tt>.
41
+ # <b><tt>:exception</tt></b>:: The +Exception+ to throw on failure. This
42
+ # defaults to +RunTimeError+.
43
+ #
44
+ def self.log(message, options={})
45
+ options = {:status => :warn, :output => $stderr}.merge(options)
46
+ options[:output].puts "[!!] #{message}" unless
47
+ options[:level].eql?(:log_only) and not Ruport::Config.debug_mode?
48
+ Ruport::Config::logger.send(options[:status],message) if Config.logger
49
+ if options[:status].eql? :fatal
50
+ raise(options[:raises] || RuntimeError, message)
51
+ end
52
+ end
53
+ #
54
+ # This method yields a <tt>Ruport::Config</tt> object, allowing you to
55
+ # set the configuration options for your application.
56
+ #
57
+ # Example:
58
+ #
59
+ # Ruport.configure do |c|
60
+ #
61
+ # c.source :default,
62
+ # :dsn => "dbi:mysql:foo",
63
+ # :user => "clyde",
64
+ # :password => "pman"
65
+ #
66
+ # c.mailer :default,
67
+ # :host => "mail.example.com",
68
+ # :address => "inky@example.com"
69
+ #
70
+ # end
71
+ #
72
+ def self.configure(&block)
73
+ block.call(Ruport::Config)
74
+ end
75
+ end
76
+
77
+ require "ruport/attempt"
78
+ require "ruport/config"
79
+ require "ruport/data"
80
+ require "ruport/report"
81
+ require "ruport/format"
82
+ require "ruport/query"
83
+ require "ruport/mailer"
84
+ require "ruport/layout"
85
+ require "ruport/renderer"