[REBOL] Table-Columns
From: al::bri::xtra::co::nz at: 3-Jan-2003 16:26
Hi!
I've been writing up a lot of tables in HTML lately (using my ML dialect)
and noticed that I've been repeating myself. So I worked out a function to
do the repetition for me:
Table-Columns: func [Columns [block!]] [
compose/deep [
thead [
tr [(
map Columns func [Column [word!]] [
compose [
th (form Column)
]
]
)]
]
tbody [(
map transpose reduce Columns func [Row [block!]] [
compose/deep [
tr [(
map Row func [Item] [
compose either any [
number? Item
money? Item
] [
[td/align "right" (form Item)]
] [
[td (form Item)]
]
]
)]
]
]
)]
]
]
'Table-Columns takes the names of 1 or more column block, and generate ML
dialect for the cells, rows, body and header of the table. One can use it
like this:
Area: iota 1 10
Radius: map Area func [Area] [square-root Area / pi]
Volume: map Radius func [Radius] [(4 * pi * power Radius 3) / 3]
Surface: map Radius func [Radius] [4 * pi * power Radius 2]
write File: %Geometry.html ML compose/deep [
html [
head [
title "Geometry"
]
body [
table/border/rules "border" "groups" [(
Table-Columns [Area Radius Volume Surface]
)]
]
]
]
browse File
Which produces a HTML file showing the relationships between area, radius,
surface.
Of course, you'll need my 'Arguments, 'Map, 'ML, 'Transpose functions to
make this work.
Andrew Martin
ICQ: 26227169 http://valley.150m.com/