OO!! Tooo many oo's round here.
Any way here is a cool self-generating HTML table make I wrote
that demonstrated some of the cool things you can do with objects
but also helps investigate the same topic of arrays of objects...
This script works great for building tables of up to several hundred rows.
To try it out set the path to your current REBOL directory.
Also set the path to where you want the HTML output to go.
It will attempt to write a file called "test-vlib.htm"
I am tossing this script out as a discussion starter...
Check out how it self gens the HTML at the bottom.
With this same technique, you can build HTML tables very quickly....
...however, it may be a memory hog..accoding to recent discussions
..... but who cares since it works so cool....
The self-gen table calls a self-gen row which calls a self-gen data-cell...
And you can use it for a lot more than just documenting REBOL scripts...
By the way... the current version is 0.1.0 because it blows up on invalid
rebol headers. Need to try the "try" function on the various header elements...
;;------------------------------------------------------------------------------------------------
REBOL [
Title: "vHTML Objects"
Date: 30-Nov-1999
Version: 0.1.0
Author: "Doug Vos"
Email: [EMAIL PROTECTED]
File: %vhtml-lib3.r
Purpose: { A library or collection of objects and functions for html...}
]
new-table: func [
{Create a new, empty html table object.
Assign the table a unique id upon creation for later reference.}
t-id [string!]
][
make object! [
align: "center"
bgcolor: #ffffff
border: 0
caption: none
cellspacing: 0
cellpadding: 1
id: t-id
otype: "table"
row: make block! 1000
width: "100%"
html: ""
append-row: func [
"Create html rows out of a series"
a-data
/local xdata tdata
][
tdata: make block! 100
foreach xdata a-data [
append tdata new-td xdata
]
append row new-tr tdata
]
;----------------------------------------------
self-gen: func [
/local xrow
] [
html: rejoin [ html
build-tag [
table
align (align)
bgcolor (bgcolor)
border (border)
cellspacing (cellspacing)
cellpadding (cellpadding)
width (width)
]
newline
]
if not (none? caption) [
html: rejoin [html <caption> caption </caption> newline ]
]
foreach xrow row [
html: rejoin [html xrow/self-gen ]
]
html: rejoin [ html </table> newline ]
];self-gen
];object
];new-table
;---------------------------------------------------------
new-tr: func [
{Create a new table ROW object.}
d-cells
][
make object! [
otype: "tr"
cell: d-cells
html: ""
self-gen: func [
/local td
] [
html: rejoin [ html <tr> newline ]
foreach td cell [
html: rejoin [html td/self-gen ]
]
html: rejoin [html </tr> newline ]
] ;self-gen
] ;make
] ;new-tr
;---------------------------------------------------------
;---------------------------------------------------------
new-td: func [
{Create a new data element TD object.}
t-data
][
make object! [
align: "center"
bgcolor: #ffffff
valign: "middle"
data: t-data
otype: "td"
html: " "
self-gen: func [] [
html: rejoin [
html
build-tag [
td
align (align)
bgcolor (bgcolor)
valign (valign)
]
data </td> newline
]
] ;self-gen
] ;make
]
;----------------------------------------------------------------
;----------------------------------------------------------------
table: new-table "rebol/dir"
table/caption: "The REBOL Directory"
table/border: 1
table/append-row [
"<B>File Name</B>" "<B>Size</B>" "<B>Date / Time</B>" "<B>Title / Purpose
</B>" "<B>Author</B>"
]
path: "/c/rebol/new/"
files: read to-file path
files: sort files
inc: 2
foreach file files [
print file
xfile: to-file rejoin [path file]
info: info? to-file rejoin [path file]
either find/match/any file "*.r" [
xhead: first load/header xfile
xtpur: rejoin [ " " <B> xhead/title </B> <BR> xhead/purpose ]
table/append-row [ (file) info/size info/date (xtpur) xhead/author ]
table/row/:inc/cell/1/bgcolor: "yellow"
][
table/append-row [(file) info/size info/date " " " " ]
table/row/:inc/cell/4/bgcolor: "gray"
table/row/:inc/cell/5/bgcolor: "gray"
]
inc: inc + 1
]
table/row/1/cell/1/bgcolor: #66ccff
table/row/1/cell/2/bgcolor: #66ccff
table/row/1/cell/3/bgcolor: #66ccff
table/row/1/cell/4/bgcolor: #66ccff
table/row/1/cell/5/bgcolor: #66ccff
htm-file: %/h/htm/test-vlib.htm
if exists? htm-file [delete htm-file]
write/lines htm-file rejoin [
newline
<html> newline
<title> "This is my test of composing html tables." </title> newline
<body> newline
table/self-gen
</body> newline
</html>
]