Adam Neeley wrote:
(I am using Ramaze & DataMapper with nested_set plugin.)
Any advice is appreciated. Thanks in advance.
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
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 “
”, and sets a global flag to say
” 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 “
| where x it the number of leaves
generates its contents, and closes itself with
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
then it must close the row with
and sets the flag to say a “
” is needed
Then it exits
When the last child exits, generates the
Set up the css to shade the hashed cells appropriately, and you are
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.