Templates in Ruport class

F

Firstname Surname

Hello, all.


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



Thank you.
 
G

Gregory Brown

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>
<body>
<%= @html_table %>
</body>
</html>

--------------------------------------------------------

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 ) [ which is just a different URI for
the same list Chris Carter linked ]

warm regards,
-greg
 
A

Artem Lakin

Gregory said:
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"?>
<!DOCTYPE report >
<Report fontSize="9" orientation="landscape">
<ReportHeader>
<Output>
<Line/>
<Line fontSize="16">
<literal>Something:</literal>
</Line>
<Line/>
<Line fontSize="12">
<literal>Report's name</literal>
</Line>
<Line fontsize="4"/>
<HorizontalLine size="4" bgcolor="'white'"/>
<HorizontalLine size="2" bgcolor="'black'"/>
<HorizontalLine size="4" bgcolor="'white'"/>
</Output>
</ReportHeader>
.....................
.....................

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 :eek:utput_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:
<table>
<tr>
<th>id</th>
<th>test</th>
</tr>
</table>

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 Lakin.
 
G

Gregory Brown

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

I'll give a detailed reply there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

[ANN] ruport-util 0.1.0 0
Ruport problems 2
Ruport GraphReport 2
[ANN] Ruport Day has begun! 1
[ANN] Ruport 0.1.0 Released 1
[ANN] ruport-util 0.6.0 0
[ANN] Ruport 1.6 and Murdoch 1.0 4
Ruport 1.2 Released 0

Members online

No members online now.

Forum statistics

Threads
474,234
Messages
2,571,180
Members
47,812
Latest member
Robi2

Latest Threads

Top