[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Parsing a nested set another way

Adam Neeley

4/25/2009 8:42:00 PM

Hello, new user here.

I am trying to render a nested set a certain way. I have code that
renders it as a list. But I want to render it another way that I know is
possible, but just can't figure out how to do it. (Look at the
attachment for a sketch)

Here is my current code: http://pastie.... . This works, but is
not what I want. I think it might be close, though.

(I am using Ramaze & DataMapper with nested_set plugin.)

Any advice is appreciated. Thanks in advance.

Attachments:
http://www.ruby-...attachment/3622/Ph...

--
Posted via http://www.ruby-....

2 Answers

Ian Hobson

4/25/2009 11:29:00 PM

0

Adam Neeley wrote:
> Hello, new user here.
>
> I am trying to render a nested set a certain way. I have code that
> renders it as a list. But I want to render it another way that I know is
> possible, but just can't figure out how to do it. (Look at the
> attachment for a sketch)
>
> Here is my current code: http://pastie.... . This works, but is
> not what I want. I think it might be close, though.
>
> (I am using Ramaze & DataMapper with nested_set plugin.)
>
> Any advice is appreciated. Thanks in advance.
>
> Attachments:
> http://www.ruby-forum.com/attachment/3622/Ph...
>
>
Hi Adam,

Your source appears to be eruby (which I don't know), so I will limit
myself to generalities, and pseudocode.

You wish to render the data, which is a tree, as a table, you need to
know two things before you can start.

a) The number of columns in the table (equals the depth of the tree)

b) The total number of leaves under each node. (The rowspan or depth of
that cell).

You will have to compute these by walking the tree. Visit the child
nodes before the parent node, telling each child node its depth. It is
to increase a global Depth variable if it finds itself deeper than the
global depth variable. Thus the global depth variable ends up containing
the number of columns the table must have.

Each child should return
1 if it has no children
The sum of the numbers returned by its children if it has children.
so that its parent can accumulate the rowspan of the cell it has to be
drawn in. A cell with two children will have to span two rows, one for
each child. Its parent will also have to span those two rows.

The table generation code then processes the nodes in "pre-order",
generating the content of this node before all of its children.

A table starts with "<table params>", and sets a global flag to say
that "<tr>" is required (or "between rows", before calling the top level
nodes one after the other (passing in column No 1).
Then each node genereates for itself
if the flag is set, it clears it, and generates "<tr>".
generates <td rowspan="x"> where x it the number of leaves
calculated above.
generates its contents, and closes itself with </td>
If it has children
it calls each of its children in turn (passing in the column number
it received, plus 1)
otherwise (it has no children),
generate the hashed cells to its right...
for i in range colNo + 1 to TableWidth
generate <td class="hash">&nbsp;</td>
then it must close the row with </tr>
and sets the flag to say a "<tr>" is needed
Then it exits

When the last child exits, generates the </table>

Set up the css to shade the hashed cells appropriately, and you are done.

You can mess with column widths and depths, but I would do as little of
this as possible. The default will probably be just fine, and be driven
by the size of the content.

Regards

Ian
























devilphish

11/17/2011 7:44:00 PM

0

On Nov 16, 8:56 pm, booie <bababooie...@gmail.com> wrote:
> On Nov 16, 7:12 pm, "sweetbac" <sweet...@sbcglobal.net> wrote:
>
> > "booboo" <ba_ba_b0...@webtv.net> wrote in message
>
> > > Old ladies shopping for sheets (Lord have mercy)
>
> > >http://www.youtube.com/watch?v=pEsVz2FEy78&feature=mfu_in_order&a...
>
> > Do ya think all the great minds that helped invent, what we
> > now call the "Internet", 30-40 years ago would have even
> > bothered to fuck with it if they knew THIS would be the outcome?
> > Who's the bigger ree-tod?...the old lady or the MF'er who filmed this?
>
> .
> .
> .
> the person who responded to it.
> Looks like you R the only one who responded.
> I thinks you R the ree-tod.
> doah!!!

booie, seriously, you need reality check, a reset on what you consider
post-worthy. That clip was beyond lame, and the fact that you thought
it would entertain others is, well, just Wereo-ish. Next thing ya
know you'll try to peddle this to Getty films.

I'm just trying to help you not make yourself look like a fool,
consider this constructive feedback.

devilphish