Ruby Report Templates: Documatic

Report generation is a crucial part of many business applications and yet this part of the application development process is often treated like an ugly step-child. In the Ruby world, one project is well on the way to becoming the de facto standard on the not so glamorous reporting catwalk: Ruport.
Ruport is a great project and is undergoing substantial development in a push towards a 2.0 release. The thing is, sometimes you need to be able to visualise the report during the building process. Wouldn’t it be great if you had some sort of visual report building mechanism to help you as you sculpt your Ruport management information masterpieces? Well, you do have such a beast because Ruport has teamed up with the ‘template-driven formatter’, Documatic.
Install it like so -
sudo gem install documatic
Documatic allows you to create report templates in OpenOffice.org (or in my case NeoOffice) that are used in conjunction with Ruport to generate your reports. Ruby code is embedded in the template to specify the format of your data, then you simply tell Documatic which template to use and where you want the output to go.
screenshot of Documatic tutorial.odt template
excerpt from Documatic tutorial.rb
require 'rubygems' require 'documatic' # Let's make a trivial table. data = Ruport::Data::Table.new( :column_names => %w(Name Phone), :data => [ ['Madchili Restaurant', '(02) 9805 1287'], ['Shiraz Restaurant', '(02) 9858 2004'], ['The Ranch Bistro Grill', '(02) 9887 2411'], ]) # Now let's generate an OpenDocument text file using Documatic. # (Note: the output directory will be created if it does not exist # yet. If the output file already exists it will be overwritten.) data.to_odt_template(:template_file => 'tutorial.odt', :output_file => 'output/tutorial.odt')
screenshot of output from Documatic tutorial.rb
Just in case you are worried about having to deploy OpenOffice.org with your apps, don’t be. OpenOffice.org is only required to create the templates, not to perform the generation, so the templates are deployed as standalone files.
This strikes me as a significant addition to Ruport’s capabilities that can only help to attract new users. Reporting could almost be getting sexy.



