| 1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
|---|
| 2 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|---|
| 3 |
|
|---|
| 4 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
|---|
| 5 |
<head> |
|---|
| 6 |
<meta http-equiv="content-type" content="text/html;charset=UTF-8" /> |
|---|
| 7 |
<title>Ruby Reports</title> |
|---|
| 8 |
<link href="ruport.css" rel="stylesheet" type="text/css" /> |
|---|
| 9 |
|
|---|
| 10 |
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> |
|---|
| 11 |
</script> |
|---|
| 12 |
<script type="text/javascript"> |
|---|
| 13 |
_uacct = "UA-2193841-1"; |
|---|
| 14 |
urchinTracker(); |
|---|
| 15 |
</script> |
|---|
| 16 |
</head> |
|---|
| 17 |
|
|---|
| 18 |
<body> |
|---|
| 19 |
<div id="wrapper"> |
|---|
| 20 |
<div id="mainNav"> |
|---|
| 21 |
<ul> |
|---|
| 22 |
<li><a href="ruport.html">Overview</a></li> |
|---|
| 23 |
<li><a href="examples.html">Examples</a></li> |
|---|
| 24 |
<li><a href="http://api.rubyreports.org/">API Docs</a></li> |
|---|
| 25 |
<li><a href="http://ruportbook.com">Book</a></li> |
|---|
| 26 |
<li><a href="http://list.rubyreports.org">Mailing List</a></li> |
|---|
| 27 |
<li><a href="resources.html">Resources</a></li> |
|---|
| 28 |
<li><a href="http://code.rubyreports.org">Development</a></li> |
|---|
| 29 |
</ul> |
|---|
| 30 |
</div> |
|---|
| 31 |
<div id="logo"> |
|---|
| 32 |
<h1><span>Ruport: Ruby Reports</span></h1> |
|---|
| 33 |
<h2>A simple, extensible reporting system built for Rubyists</h2> |
|---|
| 34 |
</div> |
|---|
| 35 |
<div id="mainContent"> |
|---|
| 36 |
<h2>Examples</h2> |
|---|
| 37 |
|
|---|
| 38 |
<p> |
|---|
| 39 |
Though the ruport package includes a number of more in depth sample |
|---|
| 40 |
applications, here a few basic examples and sample reports to give |
|---|
| 41 |
you an idea of how Ruport works. |
|---|
| 42 |
</p> |
|---|
| 43 |
|
|---|
| 44 |
<a name="csv"><h3>Basic Grouping of CSV data</h3></a> |
|---|
| 45 |
|
|---|
| 46 |
<p> |
|---|
| 47 |
Say you want to load in a CSV from file and group it by people's names, |
|---|
| 48 |
and get a PDF report back. This is easy in Ruport. |
|---|
| 49 |
</p> |
|---|
| 50 |
|
|---|
| 51 |
<p>Below is some sample data: (foo.csv)</p> |
|---|
| 52 |
|
|---|
| 53 |
<pre> |
|---|
| 54 |
name,login time,machine |
|---|
| 55 |
Gregory,10:00,bittle |
|---|
| 56 |
Joe,11:45,soda |
|---|
| 57 |
Jim,9:00,kitten |
|---|
| 58 |
Joe,12:15,soda |
|---|
| 59 |
Gregory,5:00,kitten |
|---|
| 60 |
Joe,12:45,bittle |
|---|
| 61 |
</pre> |
|---|
| 62 |
|
|---|
| 63 |
<p>To do the report we mentioned before, we'd just do something like this:</p> |
|---|
| 64 |
|
|---|
| 65 |
<pre> |
|---|
| 66 |
t = Table("foo.csv") |
|---|
| 67 |
grouping = Grouping(t,:by => "name") |
|---|
| 68 |
puts grouping.to_pdf |
|---|
| 69 |
</pre> |
|---|
| 70 |
|
|---|
| 71 |
<p> |
|---|
| 72 |
Directing the output of that script to a file results in nice output like this: |
|---|
| 73 |
</p> |
|---|
| 74 |
<div align="center"> |
|---|
| 75 |
<a href="samples/csv_simple.pdf"><img src="samples/csv_simple.png"></a> |
|---|
| 76 |
</div> |
|---|
| 77 |
|
|---|
| 78 |
<p> |
|---|
| 79 |
There are actually several styles for output, and also, it's trivial to do HTML, |
|---|
| 80 |
Text, or CSV formatted output as well. |
|---|
| 81 |
</p> |
|---|
| 82 |
|
|---|
| 83 |
<a name="aar"><h3>A trivial dump of an ActiveRecord model to CSV</h3></a> |
|---|
| 84 |
|
|---|
| 85 |
<p> |
|---|
| 86 |
If you're looking to just grab a CSV dump of some model in your Rails app, |
|---|
| 87 |
Ruport might be the easiest way to do it. Just add <tt>require "ruport"</tt> |
|---|
| 88 |
in your <tt>environment.rb</tt> file, and then the following code to your |
|---|
| 89 |
model: |
|---|
| 90 |
</p> |
|---|
| 91 |
|
|---|
| 92 |
<pre> |
|---|
| 93 |
class MyModel < ActiveRecord::Base |
|---|
| 94 |
acts_as_reportable |
|---|
| 95 |
end |
|---|
| 96 |
</pre> |
|---|
| 97 |
|
|---|
| 98 |
<p> |
|---|
| 99 |
If you want a full dump, just do this: |
|---|
| 100 |
</p> |
|---|
| 101 |
|
|---|
| 102 |
<pre> |
|---|
| 103 |
puts MyModel.report_table.to_csv |
|---|
| 104 |
</pre> |
|---|
| 105 |
|
|---|
| 106 |
<p> |
|---|
| 107 |
If you want to reduce via an AR find, you can pass along any of those options |
|---|
| 108 |
as well. |
|---|
| 109 |
</p> |
|---|
| 110 |
|
|---|
| 111 |
<pre> |
|---|
| 112 |
puts MyModel.report_table(:all, :conditions => ["name = ?", "gregory"]).to_csv |
|---|
| 113 |
</pre> |
|---|
| 114 |
|
|---|
| 115 |
<p> |
|---|
| 116 |
Ruport can do a whole lot more tricks with ActiveRecord / Rails, including |
|---|
| 117 |
handle all types of associations and model methods. For details, see |
|---|
| 118 |
the <a href="http://stonecode.svnrepository.com/ruport/trac.cgi/wiki/ActsAsReportable"> |
|---|
| 119 |
AAR wiki page.</a> |
|---|
| 120 |
</p> |
|---|
| 121 |
|
|---|
| 122 |
<a name="svg"><h3>SVG Graphs with ruport-util</h3></a> |
|---|
| 123 |
|
|---|
| 124 |
<p> |
|---|
| 125 |
If you're using the ruport-util package, it's very easy to generate beautiful |
|---|
| 126 |
SVG graphs. The functionality is still a bit basic, but for the most common |
|---|
| 127 |
needs, the output is quite nice (Thanks to Scruffy!) |
|---|
| 128 |
</p> |
|---|
| 129 |
|
|---|
| 130 |
<p> |
|---|
| 131 |
Here is a trivial graphing example: |
|---|
| 132 |
</p> |
|---|
| 133 |
|
|---|
| 134 |
<pre> |
|---|
| 135 |
require "rubygems" |
|---|
| 136 |
require "ruport" |
|---|
| 137 |
|
|---|
| 138 |
require "ruport/util" |
|---|
| 139 |
|
|---|
| 140 |
class GraphReport < Ruport::Report |
|---|
| 141 |
|
|---|
| 142 |
renders_as_graph |
|---|
| 143 |
|
|---|
| 144 |
def renderable_data(format) |
|---|
| 145 |
graph = Graph(%w[a b c d e]) |
|---|
| 146 |
graph.series [1,2,3,4,5], "foo" |
|---|
| 147 |
graph.series [11,22,70,2,19], "bar" |
|---|
| 148 |
return graph |
|---|
| 149 |
end |
|---|
| 150 |
|
|---|
| 151 |
end |
|---|
| 152 |
|
|---|
| 153 |
GraphReport.generate do |r| |
|---|
| 154 |
r.save_as("foo.svg", :template => :graph) |
|---|
| 155 |
end |
|---|
| 156 |
</pre> |
|---|
| 157 |
|
|---|
| 158 |
<p>The output ends up looking something like this:</p> |
|---|
| 159 |
<div align="right"> |
|---|
| 160 |
<a href="samples/foo.svg"><img src="samples/graph.png"/></a> |
|---|
| 161 |
</div> |
|---|
| 162 |
|
|---|
| 163 |
<p> |
|---|
| 164 |
Of course, if you need to display this easily in a browser, you might want |
|---|
| 165 |
to convert it to another format such as PNG or JPG. You can do this by simply |
|---|
| 166 |
changing the extension of your output filename, so long as you have Gruff |
|---|
| 167 |
installed. |
|---|
| 168 |
</p> |
|---|
| 169 |
|
|---|
| 170 |
<h3>Enough Flashy Examples for Now</h3> |
|---|
| 171 |
|
|---|
| 172 |
<p> |
|---|
| 173 |
Hopefully we've at least sold you on the <em>idea</em> of using Ruby Reports |
|---|
| 174 |
for your project. Still, we'd like to take this chance to remind you that |
|---|
| 175 |
the real gains you'll see from Ruport are not at this high of a level, but |
|---|
| 176 |
rather deeper in the trenches. We're aiming to provide a super light weight |
|---|
| 177 |
foundation to build reporting apps on top of, because we feel that's what |
|---|
| 178 |
Rubyists will best benefit from. Hopefully, you'll find that to be true for |
|---|
| 179 |
your work. |
|---|
| 180 |
</p> |
|---|
| 181 |
|
|---|
| 182 |
<p> |
|---|
| 183 |
If you're convinced and ready to give Ruport a spin, have a look at some of |
|---|
| 184 |
the available <a href="resources.html">resources</a>, and then come say hello |
|---|
| 185 |
on the <a href="http://list.rubyreports.org">Ruport mailing list</a>. |
|---|
| 186 |
</p> |
|---|
| 187 |
|
|---|
| 188 |
<p> |
|---|
| 189 |
Happy Hacking! |
|---|
| 190 |
</p> |
|---|
| 191 |
</div> |
|---|
| 192 |
<div id="secondaryContent"> |
|---|
| 193 |
<p><a href="#csv">Basic Grouping of CSV data</a></p> |
|---|
| 194 |
<p><a href="#aar">A trivial dump of an ActiveRecord model to CSV</a></p> |
|---|
| 195 |
<p><a href="#svg">SVG Graphs with ruport-util</a></p> |
|---|
| 196 |
</div> |
|---|
| 197 |
<div id="footer"> |
|---|
| 198 |
<p> |
|---|
| 199 |
Ruby Reports is free software under the |
|---|
| 200 |
<a href="http://www.ruby-lang.org/en/LICENSE.txt">License of Ruby</a>. |
|---|
| 201 |
</p> |
|---|
| 202 |
<p> |
|---|
| 203 |
Site designed by Michael Milner. |
|---|
| 204 |
Ruport logo designed by |
|---|
| 205 |
<a href="http://fashionpirat.de/">Daniel Dormann</a>. |
|---|
| 206 |
</p> |
|---|
| 207 |
<p> |
|---|
| 208 |
All web content is licensed under the |
|---|
| 209 |
<a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative |
|---|
| 210 |
Commons Attribution-Sharealike License</a>. |
|---|
| 211 |
</p> |
|---|
| 212 |
</div> |
|---|
| 213 |
</div> |
|---|
| 214 |
</body> |
|---|
| 215 |
</html> |
|---|