# Templates in Ruport class

**URL:** <https://www.ruby-forum.com/t/templates-in-ruport-class/86155>\
**Category:** Ruby\
**Created:** [February 20, 2007, 9:08am UTC](https://www.ruby-forum.com/t/templates-in-ruport-class/86155 "2007-02-20T09:08:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pfocchken](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/74df32/32.png) [@pfocchken](https://www.ruby-forum.com/u/pfocchken)\
**Post date:** [February 20, 2007, 9:08am UTC](https://www.ruby-forum.com/t/templates-in-ruport-class/86155/1 "2007-02-20T09:08:11Z")

</div>

Hello, all.

How can I use a templates in the ruport. Does the ruport class support  
templates?

Thank you.

---

<div class="post-metadata">

**Author:** ![pfocchken](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/74df32/32.png) [@pfocchken](https://www.ruby-forum.com/u/pfocchken)\
**Post date:** [February 20, 2007, 7:06pm UTC](https://www.ruby-forum.com/t/templates-in-ruport-class/86155/2 "2007-02-20T19:06:30Z")

</div>

On 2/20/07, Firstname S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

Hi Firstname,  
Try the Ruport group:  
[http://groups.google.com/group/ruby-reports](http://groups.google.com/group/ruby-reports)

---

<div class="post-metadata">

**Author:** ![pfocchken](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/74df32/32.png) [@pfocchken](https://www.ruby-forum.com/u/pfocchken)\
**Post date:** [February 20, 2007, 9:53pm UTC](https://www.ruby-forum.com/t/templates-in-ruport-class/86155/3 "2007-02-20T21:53:02Z")

</div>

On 2/20/07, Firstname S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello, all.
> 
> How can I use a templates in the ruport. Does the ruport class support  
> templates?

You mean ERb templates? Yeah, we support them, though I’ve never had  
any feature requests or suggestions about them so I tend to forget  
they’re even there. Here is a simple example

# foo.rb

require “ruport”

class MyReport \< Ruport::Report

def generate  
@html\_table = [[1,2,3],[4,5,6]].to\_table(%w[a b c]).to\_html  
erb “foo.rhtml”  
end

end

puts MyReport.run

# foo.rhtml
 \<%= @html\_table %\> 
* * *

If you’d like to chat about this some more, the best place to do it is  
the Ruport mailing list  
( [http://list.rubyreports.org](http://list.rubyreports.org) ) [ which is just a different URI for  
the same list Chris C. linked ]

warm regards,  
-greg

---

<div class="post-metadata">

**Author:** ![pfocchken](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/74df32/32.png) [@pfocchken](https://www.ruby-forum.com/u/pfocchken)\
**Post date:** [February 21, 2007, 4:06pm UTC](https://www.ruby-forum.com/t/templates-in-ruport-class/86155/4 "2007-02-21T16:06:49Z")

</div>

On 2/21/07, Artem L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> No, I mean, that if I have a query and I need to display data in  
> different formats(html, pdf, csv), can I describe data’s view in some  
> file such as test.xml:

No. But let’s talk about this over on the Ruport list. Sounds like a  
great idea for a plugin.

Those following along can find the thread here:

[http://tinyurl.com/2rqxb6](http://tinyurl.com/2rqxb6)

I’ll give a detailed reply there.

---

<div class="post-metadata">

**Author:** ![pfocchken](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/74df32/32.png) [@pfocchken](https://www.ruby-forum.com/u/pfocchken)\
**Post date:** [February 21, 2007, 11:26am UTC](https://www.ruby-forum.com/t/templates-in-ruport-class/86155/5 "2007-02-21T11:26:51Z")

</div>

Gregory B. wrote:

> On 2/20/07, Firstname S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Hello, all.
> > 
> > How can I use a templates in the ruport. Does the ruport class support  
> > templates?
> 
> You mean ERb templates? Yeah, we support them, though I’ve never had  
> any feature requests or suggestions about them so I tend to forget  
> they’re even there. Here is a simple example

No, I mean, that if I have a query and I need to display data in  
different formats(html, pdf, csv), can I describe data’s view in some  
file such as test.xml:

\<?xml version="1.0"?\> Something: Report's name ..................... .....................

or in yaml format, and after this when I generate my report in all  
formats, I will have data good looking.

Now, when I execute code somthing like this:

class MyRuport \< Ruport::Report  
include DogTag

attr\_accessor :main\_query  
attr\_accessor :parameters  
attr\_accessor :output\_format

prepare do

generate do

```
query(main_query, {:as => output_format.to_sym})

```

end

end

ruport = MyReport.new  
ruport.main\_query = “select \* from test\_table”  
ruport.output\_format = “html”

ruport.run{ |res| puts res.results }

I have results:

| id | test |
| --- | --- |

O something like this in pdf…

Can I put into my project some template file that will give outout data  
looks better? And how can I do this with ruport. And have the ruport  
some standart ways to solve this problem.

Thank you for answers. Artem L…
