![]() ![]() ![]() ![]() ![]() ![]() ![]() |
|||||||||||
|
Introduction
This sample describes a library for creating HTML pages. The library uses referents and silent referents. All output streams used with this library must be declared with referents-allowed defaulting {""}; programs that use this library should not create referents with the prefix "omhtml-". Because referents are used, the order in which functions are called, and objects are defined and used, does not matter.
If used in a server program, this library should be called from within a nested referents scope.
The internal library function omhtml-cell-name is used to calculate referent names for table cell contents.
define stream function omhtml-cell-name
( value stream table-name,
value counter row,
value counter col )
as
return "omhtml-%g(table-name)-%d(row)-%d(col)"
The internal library function omhtml-cell-attribute-name is used to calculate referent names for table cell attributes.
define stream function omhtml-cell-attribute-name
( value stream table-name,
value counter row,
value counter col )
as
return "omhtml-%g(table-name)-%d(row)-%d(col)-attribute"
The omhtml-new-table function creates a new HTML table with the specified number of rows and columns. The table is an omhtml-object that can be assiged to the cell of another table, just like any other object.
define function omhtml-new-table
( value stream table-name,
value counter rows,
value counter cols )
as
local counter row-count initial {1}
local counter col-count initial {1}
local stream s
open s with referents-allowed defaulting {""}
as referent "omhtml-obj-%g(table-name)"
using output as s
do
output "<table" || silent-referent
"omhtml-%g(table-name)-attributes" || ">%n"
repeat
output "<tr>%n"
set col-count to 1
repeat
output "<td" || silent-referent
omhtml-cell-attribute-name
(table-name, row-count, col-count)
|| ">%n" || silent-referent
omhtml-cell-name
(table-name, row-count, col-count)
||"%n</td>%n"
increment col-count
exit when col-count > cols
again
output "</tr>%n"
increment row-count
exit when row-count > rows
again
output "</table>%n"
done
close s
The omhtml-set-cell function sets the content of a cell of a named table to a named omhtml object. The cell is identified by row and column.
define function omhtml-set-cell
( value stream table-name,
value counter row,
value counter col,
value stream object )
as
set referent omhtml-cell-name (table-name, row, col)
with referents-allowed to referent "omhtml-obj-%g(object)"
The omhtml-cell-attributes function sets the attributes of a cell of a named table to a named omhtml attributes object.
define function omhtml-cell-attributes
( value stream table-name,
value counter row,
value counter col,
value stream cell-attributes )
as
set referent omhtml-cell-attribute-name (table-name, row, col)
with referents-allowed
to silent-referent ("omhtml-att-" || cell-attributes)
The omhtml-table-attributes function sets the attributes of a named table to a named omhtml attributes object.
define function omhtml-table-attributes
( value stream table-name,
value stream table-attributes )
as
set referent "omhtml-%g(table-name)-attributes"
with referents-allowed to
silent-referent ("omhtml-att-" || table-attributes)
The omhtml-output function sends the named omhtml objects to the current output. It takes any number of parameters, each with the name of an omhtml object.
define function omhtml-output
(remainder stream object-name ,...
)as
repeat over object-name
output referent "omhtml-obj-%g(object-name)"
again
The omhtml-new-text function creates a new HTML text object. Newlines are turned into <p> tags. Ampersands are turned into & entities. Tag start characters are turned into < entities. The function optionally takes a named omhtml format object and wraps the text in the specified formatting.
define function omhtml-new-text
( value stream object-name,
value stream text-to-add,
value stream format-name optional )
as
local stream s
open s with referents-allowed defaulting {""}
as referent "omhtml-obj-%g(object-name)"
using output as s
do
output referent "omhtml-fmt-start-%g(format-name)"
when format-name is specified
repeat scan text-to-add
match [any-text except "<&"]+ => matched
output matched
match "<"
output "<"
match "&"
output "&"
match "%n"
output "<p>"
again
output referent "omhtml-fmt-end-%g(format-name)"
when format-name is specified
done
close s
The omhtml-new-html function creates a new omhtml HTML object. This is just a place to store chunks of HTML as named objects. You cannot apply formatting to an HTML object.
define function omhtml-new-html
( value stream object-name,
value stream html-to-add )
as
set referent "omhtml-obj-%g(object-name)"
with referents-allowed defaulting {""}
to html-to-add
The omhtml-define-attributes function defines a named set of attributes.
define function omhtml-define-attributes
( value stream att-name,
value stream att-value )
as
set referent "omhtml-att-%g(att-name)" to " " || att-value || " "
The omhtml-define-format function defines a named set of format tags. The user suplies opening tags and the function calculates the end tags. The order of the end tags is reversed to ensure proper nesting.
define function omhtml-define-format
( value stream fmt-name,
value stream fmt-value )
as
local stream s initial {""}
set referent "omhtml-fmt-start-%g(fmt-name)"
to " " || fmt-value || " "
repeat scan fmt-value
match "<" letter+ => tag
set s to "</" || tag || ">" || s
match any
again
set referent "omhtml-fmt-end-%g(fmt-name)" to s
| ---- |