ruport 0.7.0 → 0.7.1

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/README CHANGED
@@ -52,7 +52,7 @@
52
52
  #
53
53
  # To install ruport via rubygems with all it's dependencies (except DBI):
54
54
  #
55
- # sudo gem install ruport
55
+ # sudo gem install ruport -y
56
56
  #
57
57
  # To install ruport manually via setup.rb:
58
58
  #
@@ -75,29 +75,32 @@
75
75
  #
76
76
  # == Data Collection and Manipulation
77
77
  #
78
- # To begin, your data must be read from its source and stored in Ruports
79
- # standard data structures. Ruport::Data::Set, Ruport::Data::Table and
80
- # Ruport::Data::Record have further information on how to work with with
78
+ # To begin, your data must be read from its source and stored in Ruport's
79
+ # standard data structures. Ruport::Data::Table and Ruport::Data::Record
80
+ # have further information on how to work with with
81
81
  # and store data in ruport.
82
82
  #
83
83
  # If you wish to retrieve your data using Ruby on Rails and ActiveRecord,
84
- # Ruport::Reportable has some useful information; To pull your data directly
85
- # from a database, Ruport::Query will be useful, and to build it manually
86
- # Array has been extended with a convenience function or two.
84
+ # please see the acts_as_reportable plugin.
87
85
  #
88
86
  # == Report Generation
89
87
  #
90
88
  # Once the data is ready, it can be rendered using a combination of
91
- # Ruport::Format, Ruport::Format::Engine and Ruport::Format::Plugin.
92
- # The engine defines the report type (tablular, invoice, graph, etc), and
89
+ # Ruport::Renderer and Ruport::Format::Plugin.
90
+ # The renderer defines the report type (tablular, graph, etc), and
93
91
  # the plugin renders the engine into a final format (PDF, CSV, HTML, SVG).
94
- # Engines will often interact with more than one plugin, to allow the same
92
+ # Renderers will often interact with more than one plugin, to allow the same
95
93
  # report to be rendered in multiple ways ie. as HTML and a PDF.
96
94
  #
97
95
  # To tie these together, a basic DSL is provided by Ruport::Report
98
96
  #
99
97
  # For further reading and specific examples, please explore the examples/
100
- # directory in the source tree and read the Ruport Cookbook.
98
+ # directory in the source tree.
99
+ #
100
+ # = Bug Reports / Feature Requests
101
+ #
102
+ # Our Trac is at: http://stonecode.svnrepository.com
103
+ # You may use the username ruport and password blinky to file tickets
101
104
  #
102
105
  # = Resources
103
106
  #
@@ -106,14 +109,14 @@
106
109
  # up to date information.
107
110
  #
108
111
  # - You can sign up and/or view the archives here:
109
- # http://lists.stonecode.org/listinfo.cgi/ruport-stonecode.org
112
+ # http://stonecode.svnrepository.com/ruport/trac.cgi/browser/trunk/test/test_table.rb
110
113
  #
111
114
  # Please do not hesitate to use this list! I am happily accepting patches and
112
115
  # documentation, as well as encouraging design discussions and also am quite
113
116
  # curious about what people use or want to use ruport for.
114
117
  #
115
118
  # I will announce Ruport releases on RubyTalk, on the Ruport mailing list, on
116
- # Freshmeat, RAA, and the new_haven.rb mailing list. If you would like to
119
+ # Freshmeat, and RAAt. If you would like to
117
120
  # keep an eye out for releases, please monitor one of those places.
118
121
  #
119
122
  # - You may download Ruport's source from the project page:
@@ -122,7 +125,7 @@
122
125
  # - The latest stable API documentation is available at:
123
126
  # http://reporting.stonecode.org/docs
124
127
  #
125
- # There also will be some tutorials on reporting.stonecode.org
128
+ # There also will be some tutorials on rubyreports.org
126
129
  #
127
130
  # If you are interested in developing Ruport, please *never* study code in
128
131
  # official releases. As this software is in it's early stages, it's essential
@@ -138,12 +141,6 @@
138
141
  #
139
142
  # svn co svn://rubyforge.org//var/svn/ruport/branches/stable
140
143
  #
141
- # Those who would like to become regular contributors will be given write
142
- # access. Also, anyone interested in the internal design and project
143
- # management aspects of Ruport can request to be added to our Trac
144
- # account. This is primarily intended for people who are working on the
145
- #
146
- #
147
144
  # Thanks for checking out Ruport!
148
145
  #
149
146
  # If you have any questions or concerns, hop on the mailing list and fire away!
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.0"
26
+ spec.version = "0.7.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}/**/**/*") +
@@ -0,0 +1,132 @@
1
+ module Ruport
2
+ module Extensions
3
+ class Invoice < Ruport::Renderer
4
+
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
16
+
17
+ def run
18
+ init_options
19
+ build [:headers,:body,:footer], :invoice
20
+ finalize :invoice
21
+ end
22
+
23
+ module InvoiceHelpers
24
+ def build_company_header
25
+ @tod = pdf_writer.y
26
+ text_box(options.company_info)
27
+ end
28
+
29
+ def build_customer_header
30
+ pdf_writer.y -= 10
31
+ text_box(options.customer_info)
32
+ end
33
+
34
+ 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
41
+ end
42
+
43
+ def build_order_header
44
+ if options.order_info
45
+ text_box(options.order_info,
46
+ :position => layout.order_info_position || 350)
47
+ end
48
+ end
49
+
50
+ def text_box(content,opts={})
51
+ ::PDF::SimpleTable.new do |table|
52
+ table.data = content.to_a.inject([]) do |s,line|
53
+ s << { "value" => line, }
54
+ end
55
+
56
+ table.column_order = "value"
57
+ table.show_headings = false
58
+ table.show_lines = :outer
59
+ table.shade_rows = :none
60
+ table.width = opts[:width] || 200
61
+ table.orientation = opts[:orientation] || :right
62
+ table.position = opts[:position] || :left
63
+ table.font_size = opts[:font_size] || 10
64
+ table.render_on(pdf_writer)
65
+ end
66
+ end
67
+ end
68
+
69
+ class PDF < Ruport::Format::PDF
70
+
71
+ include InvoiceHelpers
72
+ Invoice.add_format self, :pdf
73
+
74
+ def build_invoice_headers
75
+ build_company_header
76
+ build_customer_header
77
+ build_title
78
+ build_order_header
79
+ end
80
+
81
+ def build_invoice_body
82
+
83
+ pdf_writer.start_page_numbering(500,20,8,:right)
84
+ pdf_writer.y = 620
85
+
86
+ Ruport::Renderer::Table.render_pdf { |r|
87
+ r.data = data
88
+ r.plugin.pdf_writer = pdf_writer
89
+ r.layout.table_width = layout.body_width || 450
90
+ }
91
+
92
+ end
93
+
94
+ def build_invoice_footer
95
+ # footer
96
+ pdf_writer.open_object do |footer|
97
+ pdf_writer.save_state
98
+ pdf_writer.stroke_color! Color::RGB::Black
99
+ pdf_writer.stroke_style! ::PDF::Writer::StrokeStyle::DEFAULT
100
+ if options.comments
101
+ pdf_writer.y -= 20
102
+ text_box options.comments,
103
+ :position => layout.comments_position || 110,
104
+ :width => layout.comments_width || 400,
105
+ :font_size => layout.comments_font_size || 14,
106
+ :orientation => layout.comments_orientation
107
+ end
108
+ pdf_writer.add_text_wrap( 50, 20, 200, "Generated at " +
109
+ Time.now.strftime(options.date_format || "%H:%M %Y-%m-%d"), 8)
110
+
111
+ pdf_writer.restore_state
112
+ pdf_writer.close_object
113
+ pdf_writer.add_object(footer, :all_pages)
114
+ end
115
+ pdf_writer.stop_page_numbering(true, :current)
116
+ end
117
+
118
+ def finalize_invoice
119
+ output << pdf_writer.render
120
+ end
121
+
122
+ end
123
+ end
124
+ end
125
+ end
126
+
127
+ module Ruport::Report::Invoice
128
+ def render_invoice(&block)
129
+ Ruport::Extensions::Invoice.render_pdf(&block)
130
+ end
131
+ end
132
+
@@ -0,0 +1,29 @@
1
+ require "rubygems"
2
+ require "ruport"
3
+ require "invoice"
4
+
5
+ class SampleReport < Ruport::Report
6
+ include Invoice
7
+
8
+ def generate
9
+ render_invoice do |i|
10
+ i.data = [[1,2,3],[4,5,6]].to_table(%w[a b c])
11
+
12
+ i.options do |o|
13
+ o.company_info = "Stone Code Productions\n43 Neagle Street"
14
+ o.customer_info = "Gregory Brown\n200 Foo Ave."
15
+ o.comments = "J. Random Comment"
16
+ o.order_info = "Some info\nabout your order"
17
+ o.title = "Hey There"
18
+ end
19
+
20
+ i.layout do |lay|
21
+ lay.body_width = 480
22
+ lay.comments_font_size = 12
23
+ lay.title_font_size = 10
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ SampleReport.run { |r| r.write "out.pdf" }
@@ -0,0 +1,63 @@
1
+ require "ruport"
2
+
3
+ class LinePlotter < Ruport::Renderer
4
+
5
+ layout do |l|
6
+ l.line_color = "green"
7
+ l.line_width = 2
8
+ l.width = "100%"
9
+ l.height = "100%"
10
+ end
11
+
12
+ def run
13
+ plugin do |p|
14
+ p.data = get_lines
15
+ p.render_plot
16
+ end
17
+ end
18
+
19
+ Line = Struct.new(:x1,:y1,:x2,:y2)
20
+
21
+ def get_lines
22
+ data.map { |r| Line.new( r[0][0],r[0][1],r[1][0],r[1][1] ) }
23
+ end
24
+
25
+ end
26
+
27
+ class SVG < Ruport::Format::Plugin
28
+
29
+ def initialize
30
+ require "builder"
31
+ @builder = Builder::XmlMarkup.new(:indent => 2)
32
+ end
33
+
34
+ def render_plot
35
+
36
+ opts = { :width => layout.width, :height => layout.height,
37
+ :xmlns => "http://www.w3.org/2000/svg" }
38
+
39
+ output << @builder.svg(opts) do |builder|
40
+ builder.g( :stroke => layout.line_color,
41
+ "stroke-width" => layout.line_width ) do |g|
42
+ data.each { |r| render_line(r,g) }
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+ def render_line(line,xml_obj)
49
+ opts = { :x1 => line.x1, :x2 => line.x2,
50
+ :y1 => line.y1, :y2 => line.y2 }
51
+ xml_obj.line(opts)
52
+ end
53
+
54
+ LinePlotter.add_format self, :svg
55
+
56
+ end
57
+
58
+ puts LinePlotter.render_svg { |r|
59
+ r.data = [ [ [0,0], [0,100] ],
60
+ [ [0,100], [100,100] ],
61
+ [ [100,100], [100,0] ],
62
+ [ [100,0], [0,0] ] ]
63
+ }
@@ -12,7 +12,7 @@
12
12
 
13
13
  module Ruport
14
14
 
15
- VERSION = "0.7.0"
15
+ VERSION = "0.7.1"
16
16
 
17
17
  #
18
18
  # This method is Ruport's logging and error interface. It can generate
@@ -17,7 +17,7 @@ module Ruport::Format
17
17
 
18
18
  # Calls build_csv_row for each row in the Data::Table
19
19
  def build_table_body
20
- data.map { |r| build_csv_row(r) }.join("\n")
20
+ data.each { |r| build_csv_row(r) }
21
21
  end
22
22
 
23
23
  # Produces CSV output for a data row.
@@ -257,3 +257,21 @@ F, [2006-12-25T12:16:59.960464 #2969] FATAL -- : no block given!
257
257
  W, [2006-12-25T12:17:00.167594 #2969] WARN -- : Error on attempt # 1: ; retrying
258
258
  W, [2006-12-25T12:17:01.164421 #2969] WARN -- : Error on attempt # 2: ; retrying
259
259
  W, [2006-12-25T12:17:02.572305 #2969] WARN -- : Error on attempt # 1: ; retrying
260
+ F, [2006-12-25T13:08:12.541594 #3379] FATAL -- : Missing host for mailer bar
261
+ F, [2006-12-25T13:08:12.542918 #3379] FATAL -- : Missing DSN for source foo!
262
+ F, [2006-12-25T13:08:12.946874 #3379] FATAL -- : no block given!
263
+ W, [2006-12-25T13:08:13.152682 #3379] WARN -- : Error on attempt # 1: ; retrying
264
+ W, [2006-12-25T13:08:14.152472 #3379] WARN -- : Error on attempt # 2: ; retrying
265
+ W, [2006-12-25T13:08:16.157324 #3379] WARN -- : Error on attempt # 1: execution expired; retrying
266
+ F, [2007-01-18T01:47:24.338302 #2551] FATAL -- : Missing host for mailer bar
267
+ F, [2007-01-18T01:47:24.361525 #2551] FATAL -- : Missing DSN for source foo!
268
+ F, [2007-01-18T01:47:25.244275 #2551] FATAL -- : no block given!
269
+ W, [2007-01-18T01:47:25.851688 #2551] WARN -- : Error on attempt # 1: ; retrying
270
+ W, [2007-01-18T01:47:26.849615 #2551] WARN -- : Error on attempt # 2: ; retrying
271
+ W, [2007-01-18T01:47:28.854434 #2551] WARN -- : Error on attempt # 1: execution expired; retrying
272
+ F, [2007-01-18T12:45:33.550978 #3525] FATAL -- : Missing host for mailer bar
273
+ F, [2007-01-18T12:45:33.552282 #3525] FATAL -- : Missing DSN for source foo!
274
+ F, [2007-01-18T12:45:33.921435 #3525] FATAL -- : no block given!
275
+ W, [2007-01-18T12:45:34.086657 #3525] WARN -- : Error on attempt # 1: ; retrying
276
+ W, [2007-01-18T12:45:35.085521 #3525] WARN -- : Error on attempt # 2: ; retrying
277
+ W, [2007-01-18T12:45:37.090298 #3525] WARN -- : Error on attempt # 1: execution expired; retrying
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: ruport
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.7.0
7
- date: 2006-12-25 00:00:00 -05:00
6
+ version: 0.7.1
7
+ date: 2007-01-18 00:00:00 -05:00
8
8
  summary: A generalized Ruby report generation and templating engine.
9
9
  require_paths:
10
10
  - lib
@@ -30,46 +30,47 @@ authors:
30
30
  - Gregory Brown
31
31
  files:
32
32
  - examples/pdf_complex_report.rb
33
- - examples/line_graph_report.rb~
34
- - examples/line_graph_report.rb.rej
33
+ - examples/line_plotter.rb
34
+ - examples/invoice.rb
35
+ - examples/invoice_report.rb
35
36
  - lib/ruport
36
- - lib/uport.rb
37
37
  - lib/ruport.rb
38
+ - lib/uport.rb
38
39
  - lib/ruport.rb~
39
40
  - lib/ruport/query
40
41
  - lib/ruport/format
41
42
  - lib/ruport/data
42
43
  - lib/ruport/report
44
+ - lib/ruport/renderer
45
+ - lib/ruport/data.rb
43
46
  - lib/ruport/system_extensions.rb
44
47
  - lib/ruport/config.rb
45
48
  - lib/ruport/query.rb
46
49
  - lib/ruport/layout.rb
47
- - lib/ruport/renderer
48
- - lib/ruport/data.rb
50
+ - lib/ruport/layout
49
51
  - lib/ruport/mailer.rb
50
52
  - lib/ruport/report.rb
51
53
  - lib/ruport/attempt.rb
52
54
  - lib/ruport/data.rb~
53
55
  - lib/ruport/data.rb.rej
54
56
  - lib/ruport/generator.rb
55
- - lib/ruport/layout
56
57
  - lib/ruport/format.rb
57
58
  - lib/ruport/renderer.rb
58
59
  - lib/ruport/query/sql_split.rb
59
- - lib/ruport/format/latex.rb
60
60
  - lib/ruport/format/plugin.rb
61
+ - lib/ruport/format/latex.rb
61
62
  - lib/ruport/format/svg.rb
62
63
  - lib/ruport/format/xml.rb
63
64
  - lib/ruport/format/html.rb
64
65
  - lib/ruport/format/text.rb
65
66
  - lib/ruport/format/pdf.rb
66
67
  - lib/ruport/format/csv.rb
68
+ - lib/ruport/data/collection.rb
67
69
  - lib/ruport/data/record.rb
68
70
  - lib/ruport/data/taggable.rb
69
71
  - lib/ruport/data/table.rb
70
- - lib/ruport/data/collection.rb
71
- - lib/ruport/data/set.rb
72
72
  - lib/ruport/data/groupable.rb
73
+ - lib/ruport/data/set.rb
73
74
  - lib/ruport/data/table.rb~
74
75
  - lib/ruport/data/table.rb.rej
75
76
  - lib/ruport/data/record.rb~
@@ -78,32 +79,32 @@ files:
78
79
  - lib/ruport/renderer/table.rb
79
80
  - lib/ruport/layout/component.rb
80
81
  - test/samples
82
+ - test/test_collection.rb
81
83
  - test/test_record.rb
82
84
  - test/test_table.rb
83
85
  - test/test_renderer.rb
84
86
  - test/test_ruport.rb
85
- - test/test_collection.rb
87
+ - test/test_query.rb
86
88
  - test/test_set.rb
87
- - test/test_groupable.rb
88
89
  - test/test_graph_renderer.rb
90
+ - test/test_groupable.rb
91
+ - test/test_table_renderer.rb
89
92
  - test/_test_database.rb
90
- - test/test_query.rb
91
93
  - test/test_config.rb
92
94
  - test/test_text_table.rb
93
95
  - test/test_taggable.rb
94
96
  - test/test_mailer.rb
95
97
  - test/test_sql_split.rb
96
98
  - test/test_report.rb
97
- - test/test_table_renderer.rb
98
99
  - test/unit.log
99
100
  - test/test_record.rb.rej
100
101
  - test/test_table.rb~
101
102
  - test/test_query.rb~
102
103
  - test/test_query.rb.rej
103
- - test/samples/test.yaml
104
104
  - test/samples/query_test.sql
105
- - test/samples/data.csv
105
+ - test/samples/test.yaml
106
106
  - test/samples/erb_test.sql
107
+ - test/samples/data.csv
107
108
  - test/samples/stonecodeblog.sql
108
109
  - test/samples/ruport_test.sql
109
110
  - test/samples/addressbook.csv
@@ -120,22 +121,22 @@ files:
120
121
  - TODO
121
122
  - AUTHORS
122
123
  test_files:
124
+ - test/test_collection.rb
123
125
  - test/test_record.rb
124
126
  - test/test_table.rb
125
127
  - test/test_renderer.rb
126
128
  - test/test_ruport.rb
127
- - test/test_collection.rb
129
+ - test/test_query.rb
128
130
  - test/test_set.rb
129
- - test/test_groupable.rb
130
131
  - test/test_graph_renderer.rb
131
- - test/test_query.rb
132
+ - test/test_groupable.rb
133
+ - test/test_table_renderer.rb
132
134
  - test/test_config.rb
133
135
  - test/test_text_table.rb
134
136
  - test/test_taggable.rb
135
137
  - test/test_mailer.rb
136
138
  - test/test_sql_split.rb
137
139
  - test/test_report.rb
138
- - test/test_table_renderer.rb
139
140
  rdoc_options:
140
141
  - --title
141
142
  - Ruport Documentation
@@ -1,15 +0,0 @@
1
- ***************
2
- *** 19,24 ****
3
- end
4
- end
5
-
6
- - GraphSample.run { |r| puts r.write }
7
-
8
-
9
- --- 19,24 ----
10
- end
11
- end
12
-
13
- + GraphSample.run(:tries => 3, :timeout => 1) { |r| sleep 2; puts r.results }
14
-
15
-
@@ -1,23 +0,0 @@
1
- require "ruport"
2
- class GraphSample < Ruport::Report
3
-
4
- include Graph
5
-
6
- prepare do
7
- @data = [[5,7,9,12,14,16,18]].to_table(%w[jan feb mar apr may jun jul])
8
- end
9
-
10
- generate do
11
- render_graph do |g|
12
- g.data = @data
13
- g.width = 700
14
- g.height = 500
15
- g.title = "A Simple Line Graph"
16
- g.style = :line
17
- end
18
- end
19
- end
20
-
21
- GraphSample.run { |r| puts r.results }
22
-
23
-