ruport 0.8.14 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +42 -107
- data/Rakefile +29 -32
- data/examples/centered_pdf_text_box.rb +13 -19
- data/examples/example.csv +3 -0
- data/examples/line_plotter.rb +15 -15
- data/examples/pdf_complex_report.rb +10 -23
- data/examples/pdf_table_with_title.rb +12 -12
- data/examples/rope_examples/itunes/Rakefile +22 -1
- data/examples/rope_examples/itunes/config/environment.rb +4 -0
- data/examples/rope_examples/itunes/lib/init.rb +32 -2
- data/examples/rope_examples/itunes/util/build +50 -16
- data/examples/rope_examples/sales_report/README +1 -1
- data/examples/rope_examples/sales_report/Rakefile +22 -1
- data/examples/rope_examples/sales_report/config/environment.rb +4 -0
- data/examples/rope_examples/sales_report/lib/init.rb +32 -2
- data/examples/rope_examples/sales_report/lib/reports/sales.rb +10 -16
- data/examples/rope_examples/sales_report/util/build +50 -16
- data/examples/row_renderer.rb +39 -0
- data/examples/ruport_list/png_embed.rb +61 -0
- data/examples/ruport_list/roadmap.png +0 -0
- data/examples/sample.rb +16 -0
- data/examples/simple_pdf_lines.rb +24 -0
- data/lib/ruport.rb +143 -57
- data/lib/ruport/acts_as_reportable.rb +246 -0
- data/lib/ruport/data.rb +1 -2
- data/lib/ruport/data/grouping.rb +311 -0
- data/lib/ruport/data/record.rb +113 -84
- data/lib/ruport/data/table.rb +275 -174
- data/lib/ruport/formatter.rb +149 -0
- data/lib/ruport/formatter/csv.rb +87 -0
- data/lib/ruport/formatter/html.rb +89 -0
- data/lib/ruport/formatter/pdf.rb +357 -0
- data/lib/ruport/formatter/text.rb +151 -0
- data/lib/ruport/generator.rb +127 -30
- data/lib/ruport/query.rb +46 -99
- data/lib/ruport/renderer.rb +238 -194
- data/lib/ruport/renderer/grouping.rb +67 -0
- data/lib/ruport/renderer/table.rb +25 -98
- data/lib/ruport/report.rb +45 -96
- data/test/acts_as_reportable_test.rb +229 -0
- data/test/csv_formatter_test.rb +97 -0
- data/test/{_test_database.rb → database_test_.rb} +0 -0
- data/test/grouping_test.rb +305 -0
- data/test/html_formatter_test.rb +104 -0
- data/test/pdf_formatter_test.rb +25 -0
- data/test/{test_query.rb → query_test.rb} +32 -121
- data/test/{test_record.rb → record_test.rb} +40 -23
- data/test/renderer_test.rb +344 -0
- data/test/{test_report.rb → report_test.rb} +74 -44
- data/test/samples/ticket_count.csv +124 -0
- data/test/{test_sql_split.rb → sql_split_test.rb} +0 -0
- data/test/{test_table.rb → table_test.rb} +255 -44
- data/test/text_formatter_test.rb +144 -0
- data/util/bench/data/record/bench_as_vs_to.rb +17 -0
- data/util/bench/data/record/bench_constructor.rb +46 -0
- data/util/bench/data/record/bench_indexing.rb +65 -0
- data/util/bench/data/record/bench_reorder.rb +35 -0
- data/util/bench/data/record/bench_to_a.rb +19 -0
- data/util/bench/data/table/bench_column_manip.rb +103 -0
- data/util/bench/data/table/bench_dup.rb +24 -0
- data/util/bench/data/table/bench_init.rb +67 -0
- data/util/bench/data/table/bench_manip.rb +125 -0
- data/util/bench/formatter/bench_csv.rb +14 -0
- data/util/bench/formatter/bench_html.rb +14 -0
- data/util/bench/formatter/bench_pdf.rb +14 -0
- data/util/bench/formatter/bench_text.rb +14 -0
- data/util/bench/samples/tattle.csv +1237 -0
- metadata +121 -143
- data/TODO +0 -21
- data/examples/invoice.rb +0 -142
- data/examples/invoice_report.rb +0 -29
- data/examples/line_graph.rb +0 -38
- data/examples/rope_examples/itunes/config/ruport_config.rb +0 -8
- data/examples/rope_examples/sales_report/config/ruport_config.rb +0 -8
- data/lib/ruport/attempt.rb +0 -63
- data/lib/ruport/config.rb +0 -204
- data/lib/ruport/data/groupable.rb +0 -93
- data/lib/ruport/data/taggable.rb +0 -80
- data/lib/ruport/format.rb +0 -1
- data/lib/ruport/format/csv.rb +0 -29
- data/lib/ruport/format/html.rb +0 -42
- data/lib/ruport/format/latex.rb +0 -47
- data/lib/ruport/format/pdf.rb +0 -233
- data/lib/ruport/format/plugin.rb +0 -31
- data/lib/ruport/format/svg.rb +0 -60
- data/lib/ruport/format/text.rb +0 -103
- data/lib/ruport/format/xml.rb +0 -32
- data/lib/ruport/layout.rb +0 -1
- data/lib/ruport/layout/component.rb +0 -7
- data/lib/ruport/mailer.rb +0 -99
- data/lib/ruport/renderer/graph.rb +0 -46
- data/lib/ruport/report/graph.rb +0 -14
- data/lib/ruport/system_extensions.rb +0 -71
- data/test/test_config.rb +0 -88
- data/test/test_format_text.rb +0 -63
- data/test/test_graph_renderer.rb +0 -97
- data/test/test_groupable.rb +0 -56
- data/test/test_mailer.rb +0 -170
- data/test/test_renderer.rb +0 -151
- data/test/test_ruport.rb +0 -58
- data/test/test_table_renderer.rb +0 -141
- data/test/test_taggable.rb +0 -52
data/lib/ruport/format/svg.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
module Ruport::Format
|
2
|
-
class SVG < Plugin
|
3
|
-
|
4
|
-
# a hash of Scruffy themes.
|
5
|
-
#
|
6
|
-
# You can use these by setting layout.theme like this:
|
7
|
-
#
|
8
|
-
# Graph.render_svg { |r| r.layout.theme = r.plugin.themes[:mephisto] }
|
9
|
-
#
|
10
|
-
# Available themes: ( :mephisto, :keynote, :ruby_blog )
|
11
|
-
#
|
12
|
-
def themes
|
13
|
-
{ :mephisto => Scruffy::Themes::Mephisto.new,
|
14
|
-
:keynote => Scruffy::Themes::Keynote.new,
|
15
|
-
:ruby_blog => Scruffy::Themes::RubyBlog.new }
|
16
|
-
end
|
17
|
-
|
18
|
-
# generates a scruffy graph object
|
19
|
-
def initialize
|
20
|
-
require 'scruffy'
|
21
|
-
|
22
|
-
@graph = Scruffy::Graph.new
|
23
|
-
end
|
24
|
-
|
25
|
-
# the Scruffy::Graph object
|
26
|
-
attr_reader :graph
|
27
|
-
|
28
|
-
# sets the graph title, theme, and column_names
|
29
|
-
#
|
30
|
-
# column_names are defined by the Data::Table,
|
31
|
-
# theme may be specified by layout.theme (see SVG#themes)
|
32
|
-
# title may be specified by options.title
|
33
|
-
#
|
34
|
-
def prepare_graph
|
35
|
-
@graph.title ||= options.title
|
36
|
-
@graph.theme = layout.theme if layout.theme
|
37
|
-
@graph.point_markers ||= data.column_names
|
38
|
-
end
|
39
|
-
|
40
|
-
# Generates an SVG using Scruffy.
|
41
|
-
def build_graph
|
42
|
-
data.each_with_index do |r,i|
|
43
|
-
add_line(r.to_a,r.tags.to_a[0].to_s || "series #{i+1}")
|
44
|
-
end
|
45
|
-
|
46
|
-
output << @graph.render(:size => [layout.width, layout.height])
|
47
|
-
end
|
48
|
-
|
49
|
-
# Uses Scruffy::Graph#add to add a new line to the graph.
|
50
|
-
#
|
51
|
-
# Will use the first tag on a Record as the label if present.
|
52
|
-
#
|
53
|
-
# Line style is determined by layout.style
|
54
|
-
#
|
55
|
-
def add_line(row,label)
|
56
|
-
@graph.add( layout.style, label, row )
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
data/lib/ruport/format/text.rb
DELETED
@@ -1,103 +0,0 @@
|
|
1
|
-
module Ruport
|
2
|
-
module Format
|
3
|
-
class Text < Plugin
|
4
|
-
|
5
|
-
# Checks to ensure the table is not empty and then calls
|
6
|
-
# calculate_max_col_widths
|
7
|
-
#
|
8
|
-
def prepare_table
|
9
|
-
raise "Can't output empty table" if data.empty?
|
10
|
-
calculate_max_col_widths
|
11
|
-
end
|
12
|
-
|
13
|
-
# Uses the column names from the given Data::Table to generate a table
|
14
|
-
# header.
|
15
|
-
#
|
16
|
-
# calls fit_to_width to truncate table heading if necessary.
|
17
|
-
def build_table_header
|
18
|
-
return if data.column_names.empty? || !layout.show_table_headers
|
19
|
-
c = data.column_names.dup
|
20
|
-
c.each_with_index { |f,i|
|
21
|
-
c[i] = f.to_s.center(layout.max_col_width[i])
|
22
|
-
}
|
23
|
-
output << fit_to_width("#{hr}| #{c.to_a.join(' | ')} |\n")
|
24
|
-
end
|
25
|
-
|
26
|
-
# Generates the body of the text table.
|
27
|
-
#
|
28
|
-
# Defaults to numeric values being right justified, and other values being
|
29
|
-
# left justified. Can be changed to support centering of output by
|
30
|
-
# setting layout.alignment to :center
|
31
|
-
#
|
32
|
-
# Uses fit_to_width to truncate table if necessary
|
33
|
-
def build_table_body
|
34
|
-
s = hr
|
35
|
-
|
36
|
-
data.each { |r|
|
37
|
-
line = Array.new
|
38
|
-
r.each_with_index { |f,i|
|
39
|
-
if layout.alignment.eql? :center
|
40
|
-
line << f.to_s.center(layout.max_col_width[i])
|
41
|
-
else
|
42
|
-
align = f.is_a?(Numeric) ? :rjust : :ljust
|
43
|
-
line << f.to_s.send(align, layout.max_col_width[i])
|
44
|
-
end
|
45
|
-
}
|
46
|
-
s += "| #{line.join(' | ')} |\n"
|
47
|
-
}
|
48
|
-
s += hr
|
49
|
-
|
50
|
-
output << fit_to_width(s)
|
51
|
-
end
|
52
|
-
|
53
|
-
# Generates the horizontal rule by calculating the total table width and
|
54
|
-
# then generating a bar that looks like this:
|
55
|
-
#
|
56
|
-
# "+------------------+"
|
57
|
-
def hr
|
58
|
-
len = layout.max_col_width.inject(data[0].to_a.length * 3) {|s,e|s+e}+1
|
59
|
-
"+" + "-"*(len-2) + "+\n"
|
60
|
-
end
|
61
|
-
|
62
|
-
# Returns layout.table_width if specified.
|
63
|
-
#
|
64
|
-
# Otherwise, uses SystemExtensions to determine terminal width.
|
65
|
-
def width
|
66
|
-
require "ruport/system_extensions"
|
67
|
-
layout.table_width || SystemExtensions.terminal_width
|
68
|
-
end
|
69
|
-
|
70
|
-
# Truncates a string so that it does not exceed Text#width
|
71
|
-
def fit_to_width(s)
|
72
|
-
# workaround for Rails setting terminal_width to 1
|
73
|
-
width < 2 ? max_width = 80 : max_width = width
|
74
|
-
|
75
|
-
s.split("\n").each { |r|
|
76
|
-
r.gsub!(/\A.{#{max_width+1},}/) { |m| m[0,max_width-2] + ">>" }
|
77
|
-
}.join("\n") + "\n"
|
78
|
-
end
|
79
|
-
|
80
|
-
# determines the text widths for each column.
|
81
|
-
def calculate_max_col_widths
|
82
|
-
# allow override
|
83
|
-
return if layout.max_col_width
|
84
|
-
|
85
|
-
layout.max_col_width=Array.new
|
86
|
-
unless data.column_names.empty?
|
87
|
-
data.column_names.each_index do |i|
|
88
|
-
layout.max_col_width[i] = data.column_names[i].to_s.length
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
data.each { |r|
|
93
|
-
r.each_with_index { |f,i|
|
94
|
-
if !layout.max_col_width[i] || f.to_s.length > layout.max_col_width[i]
|
95
|
-
layout.max_col_width[i] = f.to_s.length
|
96
|
-
end
|
97
|
-
}
|
98
|
-
}
|
99
|
-
end
|
100
|
-
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
data/lib/ruport/format/xml.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
module Ruport::Format
|
2
|
-
class XML < Plugin
|
3
|
-
|
4
|
-
def prepare_graph
|
5
|
-
gem "builder"
|
6
|
-
@builder = Builder::XmlMarkup.new(:indent => 2)
|
7
|
-
end
|
8
|
-
|
9
|
-
def build_graph
|
10
|
-
output << @builder.chart do |b|
|
11
|
-
b.chart_type(layout.style.to_s)
|
12
|
-
|
13
|
-
b.chart_data do |cd|
|
14
|
-
|
15
|
-
cd.row { |first|
|
16
|
-
first.null
|
17
|
-
data.column_names.each { |c| first.string(c) }
|
18
|
-
}
|
19
|
-
|
20
|
-
data.each_with_index { |r,i|
|
21
|
-
label = r.tags.to_a[0] || "Region #{i}"
|
22
|
-
cd.row { |data_row|
|
23
|
-
data_row.string(label)
|
24
|
-
r.each { |e| data_row.number(e) }
|
25
|
-
}
|
26
|
-
}
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
data/lib/ruport/layout.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "ruport/layout/component" #:nodoc:
|
data/lib/ruport/mailer.rb
DELETED
@@ -1,99 +0,0 @@
|
|
1
|
-
# mailer.rb
|
2
|
-
# Created by Gregory Brown on 2005-08-16
|
3
|
-
# Copyright 2005 (Gregory Brown) All Rights Reserved.
|
4
|
-
# This product is free software, you may distribute it as such
|
5
|
-
# under your choice of the Ruby license or the GNU GPL
|
6
|
-
# See LICENSE for details
|
7
|
-
require "net/smtp"
|
8
|
-
require "forwardable"
|
9
|
-
|
10
|
-
module Ruport
|
11
|
-
|
12
|
-
#
|
13
|
-
# === Overview
|
14
|
-
#
|
15
|
-
# This class uses SMTP to provide a simple mail sending mechanism.
|
16
|
-
# It also uses MailFactory to provide attachment and HTML email support.
|
17
|
-
#
|
18
|
-
# === Example
|
19
|
-
#
|
20
|
-
# Here is a simple example of a message which attaches a README file:
|
21
|
-
#
|
22
|
-
# require "ruport"
|
23
|
-
#
|
24
|
-
# Ruport.configure do |config|
|
25
|
-
# config.mailer :default,
|
26
|
-
# :host => "mail.adelphia.net",
|
27
|
-
# :address => "gregory.t.brown@gmail.com"
|
28
|
-
# end
|
29
|
-
#
|
30
|
-
# mailer = Ruport::Mailer.new
|
31
|
-
#
|
32
|
-
# mailer.attach "README"
|
33
|
-
#
|
34
|
-
# mailer.deliver :to => "gregory.t.brown@gmail.com",
|
35
|
-
# :from => "gregory.t.brown@gmail.com",
|
36
|
-
# :subject => "Hey there",
|
37
|
-
# :text => "This is what you asked for"
|
38
|
-
#
|
39
|
-
class Mailer
|
40
|
-
extend Forwardable
|
41
|
-
|
42
|
-
#
|
43
|
-
# Creates a new Mailer object. Optionally, you can select a mailer
|
44
|
-
# specified by Ruport::Config.
|
45
|
-
#
|
46
|
-
# Example:
|
47
|
-
#
|
48
|
-
# a = Mailer.new # uses the :default mailer
|
49
|
-
# a = Mailer.new :foo # uses :foo mail config from Ruport::Config
|
50
|
-
#
|
51
|
-
def initialize( mailer_label=:default )
|
52
|
-
select_mailer(mailer_label);
|
53
|
-
mail_object.from = @mailer.address if mail_object.from.to_s.empty?
|
54
|
-
rescue
|
55
|
-
raise "you need to specify a mailer to use"
|
56
|
-
end
|
57
|
-
|
58
|
-
def_delegators( :@mail, :to, :to=, :from, :from=,
|
59
|
-
:subject, :subject=, :attach,
|
60
|
-
:text, :text=, :html, :html= )
|
61
|
-
|
62
|
-
#
|
63
|
-
# Sends the message.
|
64
|
-
#
|
65
|
-
# Example:
|
66
|
-
#
|
67
|
-
# mailer.deliver :from => "gregory.t.brown@gmail.com",
|
68
|
-
# :to => "greg7224@gmail.com"
|
69
|
-
#
|
70
|
-
def deliver(options={})
|
71
|
-
options.each { |k,v| send("#{k}=",v) if respond_to? "#{k}=" }
|
72
|
-
|
73
|
-
Net::SMTP.start(@host,@port,@host,@user,@password,@auth) do |smtp|
|
74
|
-
smtp.send_message((options[:mail_object] || mail_object).to_s, options[:from], options[:to] )
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
private
|
79
|
-
|
80
|
-
def select_mailer(label)
|
81
|
-
@mailer = Ruport::Config.mailers[label]
|
82
|
-
@host = @mailer.host
|
83
|
-
@user = @mailer.user
|
84
|
-
@password = @mailer.password
|
85
|
-
@address = @mailer.address
|
86
|
-
@port = @mailer.port || 25
|
87
|
-
@auth = @mailer.auth_type || :plain
|
88
|
-
@mail_klass = @mailer.mail_klass
|
89
|
-
end
|
90
|
-
|
91
|
-
def mail_object
|
92
|
-
return @mail if @mail
|
93
|
-
return @mail ||= @mail_klass.new if @mail_klass
|
94
|
-
require "mailfactory"
|
95
|
-
@mail ||= MailFactory.new
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# renderer/graph.rb
|
2
|
-
# Generalized graphing support for Ruby Reports
|
3
|
-
#
|
4
|
-
# Written by Gregory Brown, Copright December 2006, All Rights Reserved.
|
5
|
-
#
|
6
|
-
# This is free software. See LICENSE and COPYING for details.
|
7
|
-
|
8
|
-
module Ruport
|
9
|
-
|
10
|
-
# This class implements the basic graphing engine for Ruport.
|
11
|
-
#
|
12
|
-
# == Supported Format Plugins
|
13
|
-
#
|
14
|
-
# * Format::XML
|
15
|
-
# * Format::SVG
|
16
|
-
#
|
17
|
-
# == Default layout options
|
18
|
-
#
|
19
|
-
# * height #=> 350
|
20
|
-
# * width #=> 500
|
21
|
-
# * style #=> :line
|
22
|
-
#
|
23
|
-
# == Plugin hooks called (in order)
|
24
|
-
#
|
25
|
-
# * prepare_graph
|
26
|
-
# * build_graph
|
27
|
-
# * finalize_graph
|
28
|
-
class Renderer::Graph < Renderer
|
29
|
-
|
30
|
-
include Renderer::Helpers
|
31
|
-
|
32
|
-
add_formats :svg,:xml
|
33
|
-
|
34
|
-
layout do |l|
|
35
|
-
l.height = 350
|
36
|
-
l.width = 500
|
37
|
-
l.style = :line
|
38
|
-
end
|
39
|
-
|
40
|
-
prepare :graph
|
41
|
-
stage :graph
|
42
|
-
finalize :graph
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
data/lib/ruport/report/graph.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
#!/usr/local/bin/ruby -w
|
2
|
-
|
3
|
-
# system_extensions.rb
|
4
|
-
#
|
5
|
-
# lovingly ganked from HighLine 1.2.1
|
6
|
-
#
|
7
|
-
# The following modifications have been made by Gregory Brown on 2006.06.25
|
8
|
-
#
|
9
|
-
# - Outer Module is changed from HighLine to Ruport
|
10
|
-
# - terminal_width / terminal_height added
|
11
|
-
#
|
12
|
-
# The following modifications have been made by Gregory Brown on 2006.08.13
|
13
|
-
# - removed most methods, preserving only terminal geometry features
|
14
|
-
#
|
15
|
-
# All modifications are under the distributions terms of Ruport.
|
16
|
-
# Copyright 2006, Gregory Brown. All Rights Reserved
|
17
|
-
#
|
18
|
-
# Original copyright notice preserved below.
|
19
|
-
# --------------------------------------------------------------------------
|
20
|
-
#
|
21
|
-
# Created by James Edward Gray II on 2006-06-14.
|
22
|
-
# Copyright 2006 Gray Productions. All rights reserved.
|
23
|
-
#
|
24
|
-
# This is Free Software. See LICENSE and COPYING for details.
|
25
|
-
|
26
|
-
module Ruport
|
27
|
-
module SystemExtensions #:nodoc:
|
28
|
-
module_function
|
29
|
-
|
30
|
-
#
|
31
|
-
# This section builds character reading and terminal size functions
|
32
|
-
# to suit the proper platform we're running on. Be warned: Here be
|
33
|
-
# dragons!
|
34
|
-
#
|
35
|
-
begin
|
36
|
-
require "Win32API" # See if we're on Windows.
|
37
|
-
|
38
|
-
# A Windows savvy method to fetch the console columns, and rows.
|
39
|
-
def terminal_size
|
40
|
-
m_GetStdHandle = Win32API.new( 'kernel32',
|
41
|
-
'GetStdHandle',
|
42
|
-
['L'],
|
43
|
-
'L' )
|
44
|
-
m_GetConsoleScreenBufferInfo = Win32API.new(
|
45
|
-
'kernel32', 'GetConsoleScreenBufferInfo', ['L', 'P'], 'L'
|
46
|
-
)
|
47
|
-
|
48
|
-
format = 'SSSSSssssSS'
|
49
|
-
buf = ([0] * format.size).pack(format)
|
50
|
-
stdout_handle = m_GetStdHandle.call(0xFFFFFFF5)
|
51
|
-
|
52
|
-
m_GetConsoleScreenBufferInfo.call(stdout_handle, buf)
|
53
|
-
bufx, bufy, curx, cury, wattr,
|
54
|
-
left, top, right, bottom, maxx, maxy = buf.unpack(format)
|
55
|
-
return right - left + 1, bottom - top + 1
|
56
|
-
end
|
57
|
-
rescue LoadError # If we're not on Windows try...
|
58
|
-
# A Unix savvy method to fetch the console columns, and rows.
|
59
|
-
def terminal_size
|
60
|
-
size = `stty size 2>/dev/null`.split.map { |x| x.to_i }.reverse
|
61
|
-
return $? == 0 ? size : [80,24]
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
def terminal_width
|
67
|
-
terminal_size.first
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
end
|