Re: [ruport] Rails + Ruport app [++WARNING++]

7 views
Skip to first unread message

Gregory Brown

unread,
Jul 12, 2007, 2:53:07 PM7/12/07
to ruby-r...@googlegroups.com
On 7/12/07, EmmanuelOga <emman...@gmail.com> wrote:
>
> Hi! My name is emmanuel. I made a dead simple rails+ruport app. Here
> it is:
>
> http://up-file.com/download/3a8b0b890162/RailedRuport.rar.html

Emmanuel, I almost scrapped this due to the porn advertisements on
that download page. After downloading the source and seeing that
there is useful content there, I'm glad you shared this but please
just attach the file next time or use a service that won't get people
in trouble if they click the link in work!

> Is not "finished"... ie I need to add graphing capabilities to it.
>
> Let me know what you thnk about it!

I've attached the project so anyone interested can take a look, and
converted it to a zip and tarball (rar is not exactly open source
friendly, despite the existence of unix unrar)

I see that you have some notes in the reports of different things not
working. Perhaps you can post those bits of code here so we can
discuss them on list.

The general application definitely seems promising as a demonstration
so I'd like to be able to help however I can, just let us know what
you need.

RailedRuport.tar.bz2
RailedRuport.zip

EmmanuelOga

unread,
Jul 12, 2007, 3:41:23 PM7/12/07
to Ruby Reports
> Emmanuel, I almost scrapped this due to the porn advertisements on
> that download page. After downloading the source and seeing that
> there is useful content there, I'm glad you shared this but please
> just attach the file next time or use a service that won't get people
> in trouble if they click the link in work!

Whooa! That's awful!!!

I'm very sorry, since i use adblock on my firefox, i missed the
ads!!!
Sorry again and thanks for fixing it. I also will use zip the next
time.

The problems i have in my report relates to two general subjects:

1) How can i create data on a renderer accesible in a formatter of
that renderer that
don't come directly from parameters to
SomeRenderer.render_aformat { |d| d.parameters } ?

2) How can i more elegantly print a Grouping to avoid doing this: ?

Grouping(events, :by => "user_name").each do |name, group|
pad(10) { draw_table(group, :title => name, :width => 300) }
end


I further document the problems directly from my app reports:

Part 1)

class CompleteReport < Ruport::Renderer
required_option :users, :events
option :event_grouping # <<< I ADDED THIS TO "CREATE" THE
VARIABLE

prepare :standard_report

stage :standard_header, :report_users, :report_events, :standard_footer
finalize :standard_report

def setup
# ... code

events.rename_column "verbal_type", "Event Type"
events.rename_column "description", "Description"
events.reorder(2, 0, 1)

# The following does not work!!! Why???
event_grouping= Grouping(events, :by => "user_name")
end
end

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

My intent is to create a variable pointing to a Grouping:

event_grouping= Grouping(events, :by => "user_name")

but it does not work because when i try to access it in my formatter,
rails strikes me with a "you have a nil object where not expected"
error:

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

class CompletePDFFormatter < Ruport::Formatter::PDF
renders :pdf, :for => CompleteReport

opt_reader :users, :events, :event_grouping # The last one is for my
created Grouping

include StandardPdfFormat

#... code

def build_report_events
# event_grouping HERE does not work! Why?
# draw_table(event_grouping, :title => "User Events
Details", :width => 300)

Grouping(events, :by => "user_name").each do |name, group|
pad(10) { draw_table(group, :title => name, :width => 300) }
end
end
end

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

As event_grouping var is nil, i have no choice but to use the events
var (that _is_ working)
and "massage" the data on my formatter:

Grouping(events, :by => "user_name").each do |name, group|
pad(10) { draw_table(group, :title => name, :width => 300) }
end

Why can be this happening?

Part 2) There you can also see the code to print the Grouping's
tables.
Can i print the Grouping more directly?

Thank you!!!

Gregory Brown

unread,
Jul 12, 2007, 3:54:12 PM7/12/07
to ruby-r...@googlegroups.com
On 7/12/07, EmmanuelOga <oga_emma...@yahoo.com.ar> wrote:
>
> > Emmanuel, I almost scrapped this due to the porn advertisements on
> > that download page. After downloading the source and seeing that
> > there is useful content there, I'm glad you shared this but please
> > just attach the file next time or use a service that won't get people
> > in trouble if they click the link in work!
>
> Whooa! That's awful!!!
>
> I'm very sorry, since i use adblock on my firefox, i missed the
> ads!!!
> Sorry again and thanks for fixing it. I also will use zip the next
> time.

Ah, I suspected that might be the case, thanks.

> The problems i have in my report relates to two general subjects:
>
> 1) How can i create data on a renderer accesible in a formatter of
> that renderer that
> don't come directly from parameters to
> SomeRenderer.render_aformat { |d| d.parameters } ?

Any hash options will automatically be set on the options object in
the renderer / formatter

e.g.

SomeRenderer.render_aformat(:foo => "bar") will make it so options.foo #=> "bar"

if you want to be able to set options in the block form, you either
can access them via .options, e.g.

SomeRenderer.render_aformat { |d|
d.options.foo = "bar"
}

or if you want to clean that up a little, use something like this in
your renderer definition:

class SomeRenderer
option :foo
end

which will allow:

SomeRenderer.render_aformat { |d| d.foo = "bar" }

It only creates attribute writers, though.

> 2) How can i more elegantly print a Grouping to avoid doing this: ?
>
> Grouping(events, :by => "user_name").each do |name, group|
> pad(10) { draw_table(group, :title => name, :width => 300) }
> end

In your PDF formatter, right?

try: render_grouping with any options you'd pass to Grouping#to_pdf, eg

e.g.

class MyPDF < Ruport::Formatter::PDF
def build_some_stage
render_grouping Grouping(events, :by => "user_name"),
:table_format => { :width => 300 }
end
end

That should do the trick.


> I further document the problems directly from my app reports:
>
> Part 1)
>
> class CompleteReport < Ruport::Renderer
> required_option :users, :events
> option :event_grouping # <<< I ADDED THIS TO "CREATE" THE
> VARIABLE
>
> prepare :standard_report
>
> stage :standard_header, :report_users, :report_events, :standard_footer
> finalize :standard_report
>
> def setup
> # ... code
>
> events.rename_column "verbal_type", "Event Type"
> events.rename_column "description", "Description"
> events.reorder(2, 0, 1)
>
> # The following does not work!!! Why???
> event_grouping= Grouping(events, :by => "user_name")

This is a ruby issue. It does not know whether you are setting a
local variable or using an accessor, and defaults to a local variable.
instead, use:

self.event_grouping = ...

or

options.event_grouping = ...

> end
> end
>
> ---------------------------------------------------------------------------------------
>
> My intent is to create a variable pointing to a Grouping:
>
> event_grouping= Grouping(events, :by => "user_name")
>
> but it does not work because when i try to access it in my formatter,
> rails strikes me with a "you have a nil object where not expected"
> error:

Right, it's because you only set a local variable, not an option. In
your Formatter, you will still need to call it options.event_grouping,
unless you add a call to opt_reader like so:

class MyFormatter < Ruport::Formatter
opt_reader :event_grouping
end

this is to avoid clashes, since we open the options up for arbitrary
modifications, we don't want to pollute the formatter namespace by
default.

> ---------------------------------------------------------------------------------------
>
> class CompletePDFFormatter < Ruport::Formatter::PDF
> renders :pdf, :for => CompleteReport
>
> opt_reader :users, :events, :event_grouping # The last one is for my
> created Grouping

Ah, you did this correctly. :) The object is just nil because of the
local variable issue

> include StandardPdfFormat
>
> #... code
>
> def build_report_events
> # event_grouping HERE does not work! Why?
> # draw_table(event_grouping, :title => "User Events
> Details", :width => 300)
>
> Grouping(events, :by => "user_name").each do |name, group|
> pad(10) { draw_table(group, :title => name, :width => 300) }
> end
> end
> end
>
> ---------------------------------------------------------------------------------------
>
> As event_grouping var is nil, i have no choice but to use the events
> var (that _is_ working)
> and "massage" the data on my formatter:
>
> Grouping(events, :by => "user_name").each do |name, group|
> pad(10) { draw_table(group, :title => name, :width => 300) }
> end
>
> Why can be this happening?
>
> Part 2) There you can also see the code to print the Grouping's
> tables.
> Can i print the Grouping more directly?

Yeah, see the advice above to use render_grouping.

---

By the way, I noticed in some of your code that you use @output
instead of output, please don't do that :)

The accessor isn't just an attr_reader, it does some logic.

These are good questions, hopefully this has been helpful.
-greg

EmmanuelOga

unread,
Jul 12, 2007, 4:33:53 PM7/12/07
to Ruby Reports
Ok, i fixed the two accesor things:

1) I use ouput instead of @output
2) In this case I use self.event_grouping= Grouping(events, :by =>
"user_name") instead of
event_grouping= Grouping(events, :by =>
"user_name") to let
ruby know i want an accesor.

About this subject i'm wondering... if i use

option :event_grouping

in my Renderer definition, the user of the class my think is for
passing an "event_grouping"
as option, when the thing i want is to create a _new_ variable to
pass to the formatter. Should
I do this in other way?

The last issue is that this:

render_grouping event_grouping, :table_format => { :width =>
300 }
# => Outputs Nothing!

Is not having the same effect that this:

event_grouping.each do |name, group|


draw_table(group, :title => name, :width => 300)
end

# => Outputs the right thing

What do you think about it?

Gregory Brown

unread,
Jul 12, 2007, 5:50:15 PM7/12/07
to ruby-r...@googlegroups.com
On 7/12/07, EmmanuelOga <oga_emma...@yahoo.com.ar> wrote:

> About this subject i'm wondering... if i use
>
> option :event_grouping
>
> in my Renderer definition, the user of the class my think is for
> passing an "event_grouping"
> as option, when the thing i want is to create a _new_ variable to
> pass to the formatter. Should
> I do this in other way?

Oh, just leave out the option accessor then, and set
options.event_grouping instead of self.event_grouping.

This way, even if the user passes in a value, it would be overridden (IIRC)

> The last issue is that this:
>
> render_grouping event_grouping, :table_format => { :width =>
> 300 }
> # => Outputs Nothing!

Oh, hmm... Try this:

render_grouping event_grouping, :table_format => { :width => 300 },
:formatter => pdf_writer

That render_grouping() hook has had some fishy behaviour lately, but
the above *should* work, let me know if it doesn't, and I'll
investigate.

Emmanuel Oga

unread,
Jul 13, 2007, 8:54:19 AM7/13/07
to ruby-r...@googlegroups.com
Greg:


render_grouping event_grouping, :table_format => { :width => 300 },
:formatter => pdf_writer
That did the trick! :)

Thank you, i'm going to do a little write up about my experience in this little incursion to ruport + rails.

Expect to hear other questions from me later...  :)

Bye!

Emmanuel Oga

Gregory Brown <gregory...@gmail.com> escribió:

Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!

Gregory Brown

unread,
Jul 13, 2007, 9:51:16 AM7/13/07
to ruby-r...@googlegroups.com
On 7/13/07, Emmanuel Oga <oga_emma...@yahoo.com.ar> wrote:
> Greg:
>
> render_grouping event_grouping, :table_format => { :width => 300 },
> :formatter => pdf_writer
> That did the trick! :)
>
> Thank you, i'm going to do a little write up about my experience in this
> little incursion to ruport + rails.
>
> Expect to hear other questions from me later... :)

Great. If you continue to work on the demo app, please feel free to
send updates, if it becomes generally helpful I'd be happy to make it
available for download on either the wiki or ruport site.

Also, point us at your write up when it's done. Are you planning on
doing it in English or Spanish?

Emmanuel Oga

unread,
Jul 13, 2007, 10:43:38 AM7/13/07
to ruby-r...@googlegroups.com
I will do it first in english, i think it would be accesible both for english and spanish speakers that way. I'm just investigating how to render a graph, then i will do the write up.

P.D.: I tried to send you the zip but google rejected it ( ?? )

Gregory Brown <gregory...@gmail.com> escribió:

Gregory Brown

unread,
Jul 13, 2007, 10:49:07 AM7/13/07
to ruby-r...@googlegroups.com
On 7/13/07, Emmanuel Oga <oga_emma...@yahoo.com.ar> wrote:
> I will do it first in english, i think it would be accesible both for
> english and spanish speakers that way.

Great. All of the core team's documentation, including the Ruport
Book, are under a free documentation license, so anyone who wishes to
translate any of our documents is welcome to.

> I'm just investigating how to render a graph, then i will do the write up.

http://groups.google.com/group/ruby-reports/browse_thread/thread/e1c14203f8f3fe64/0b1c4c954744cf2b?lnk=gst&q=graph&rnum=1#0b1c4c954744cf2b

you'll need to install ruport-util, though.

> P.D.: I tried to send you the zip but google rejected it ( ?? )

Oh, yes. Remove that batch file you've included, as it's not needed
for people running the app anyway. Google thinks it's a virus,
hehehe.

(alternatively, you can probably just remove the .bat extension)

Reply all
Reply to author
Forward
0 new messages