Monday, November 08, 2010 at 12:03 AM.
system.verbs.builtins.html.tenderRender
on tenderRender (adr) { //turn an object into HTML
<<This does the low-level object rendering that html.buildObject needs.
<<This code used to be in html.data.standardMacros.renderObject, which calls this routine.
<<And then passes the resulting text thru html.processMacros.
<<Changes:
<<Tue, Apr 23, 1996 at 7:48:33 AM by DW
<<implement #directives, sets fields of html.data table
<<#title sets adrPageTable^.title
<<#ftpSite sets adrPageTable^.ftpsite
<<#template sets adrPageTable^.template
<<work with a local copy of the object
<<we will modify the object before rendering it if it contains #directives
<<Thu, Dec 12, 1996 at 5:28:51 PM by DW
<<Allow outline renderers to run from the tools table
<<10/12/98; 7:47:08 PM by DW
<<implement #renderTableWith
<<it can reference either a script or an outline
<<does the same kind of thing as #renderOutlineWith
<<we used to copy the object into a local before rendering it
<<but near as I can tell, only the outline renderers care
<<it would be wasteful to do this for tables, and for other large-ish types
<<I'm going to try using it without making the copy and see if it hurts
<<9/13/99; 2:33:10 PM by PBS
<<Bug fix: you can use outlines as renderers when rendering tables via #renderTableWith.
<<The locateRenderer subroutine now takes an optional parameter, flOutlinesOkay, which is false by default, but true when rendering a table via #renderTableWith.
<<If flOutlinesOkay is true, then the locateRenderer subroutine will correctly locate renderers that are outlines.
<<9/20/99; 12:07:14 PM by PBS
<<Table renderers can be wp-text objects also. The locateRenderer routine now takes an additional optional parameter -- flWpTextOkay -- if true then the renderer can be a wp-text object. When rendering tables, this is true, otherwise it's false (by default).
on locateRenderer (name, flOutlinesOkay=false, flWpTextOkay=false) { //returns the address of the renderer
local (adr);
on isValidRenderer () {
<<PBS 9/13/99: bottleneck script for determining if an address points to a valid renderer.
<<Renderers must be a script -- unless this is a table rendered via #renderTableWith, in which case a renderer may be an outline.
if not defined (adr^) { //if it's not defined, it's not a valid renderer
return (false)};
local (objectType = typeOf (adr^));
if objectType == scriptType { //scripts are always okay
return (true)};
if flOutlinesOkay and objectType == outlineType { //outlines are okay for tables
return (true)};
if flWpTextOkay and objectType == wpTextType { //wp-text objects are okay for tables
return (true)};
return (false)};
try { //try it first as an address
adr = address (name);
if isValidRenderer () {
return (adr)}};
if defined (adrPageTable^.tools) { //see if it's in the tools table
if defined (adrPageTable^.tools^) { //PBS 9/13/99: was: try //tools might not be a table
adr = @adrPageTable^.tools^.[name];
if isValidRenderer () {
return (adr)}}};
bundle { //see if it's in user.html.renderers
adr = @user.html.renderers.[name];
if isValidRenderer () {
return (adr)}};
scriptError ("Can't find a rendering script named \"" + name + "\".")};
local (adrPageTable = html.getPageTableAddress ());
local (objectType = typeOf (adr^));
local (s = "");
case objectType {
tableType {
if defined (adrPageTable^.renderTableWith) { //a table renderer has been defined
local (name = adrPageTable^.renderTableWith);
local (adrRenderer = locateRenderer (name, flOutlinesOkay:true, flWpTextOkay:true));
case typeOf (adrRenderer^) {
scriptType {
s = adrRenderer^ (adr)}}
else {
adrPageTable^.adrTable = adr; //to be picked up by macros in the text
s = html.runDirectives (string (adrRenderer^), adrPageTable)}}
else {
local (i);
s = "<table width = 66% cellpadding=3 border = 1>\r<td><b>Name</b></td> <td><b>Value</b></td> <td><b>Kind</b></td>\r";
for i = 1 to sizeOf (adr^) {
local (itemaddress = @adr^ [i]);
local (itemname = nameOf (itemaddress^));
local (itemsize = sizeOf (itemaddress^));
local (itemtype = typeOf (itemaddress^));
local (flnowrapvalue = true);
local (namestring, typestring, valuestring);
s = s + "<tr>";
<<namestring = "<a href=\"aretha.www.getpage.fcgi$" + string.urlEncode (string (itemaddress)) + "\">" + itemname + "</a>"
namestring = itemname;
valuestring = "---";
case itemtype {
directionType { <<added 4/27/96 DW
valuestring = string (itemaddress^);
typestring = "direction"};
rgbType { <<added 4/27/96 DW
valuestring = string (itemaddress^);
typestring = "rgb"};
pointType { <<added 4/27/96 DW
valuestring = string (itemaddress^);
typestring = "point"};
rectType { <<added 4/27/96 DW
valuestring = string (itemaddress^);
typestring = "rect"};
filespecType { <<added 4/27/96 DW
valuestring = string (itemaddress^);
typestring = "filespec"};
aliastype {
valuestring = string (itemaddress^);
typestring = "alias [" + itemsize + "]"};
binarytype {
valuestring = itemsize + " bytes";
typestring = "binary [" + getBinaryType (itemaddress^) + "]"};
booleantype {
valuestring = string (itemaddress^);
typestring = "boolean"};
chartype {
valuestring = itemaddress^;
typestring = "character"};
datetype { <<added 12/11/95 DW
valuestring = string (itemaddress^);
typestring = "date"};
addresstype { <<added 12/11/95 DW
valuestring = string (itemaddress^);
typestring = "address"};
listtype {
valuestring = itemaddress^;
typestring = "list [" + itemsize + "]"};
longtype {
valuestring = string (itemaddress^);
typestring = "number"};
menubartype {
valuestring = itemsize + " lines";
typestring = "menu"};
outlinetype {
valuestring = itemsize + " lines";
typestring = "outline"};
scripttype {
valuestring = itemsize + " lines";
typestring = "script"};
shorttype {
valuestring = string (itemaddress^);
typestring = "number"};
string4type {
valuestring = string (itemaddress^);
typestring = "string4"};
stringtype {
valuestring = itemaddress^;
typestring = "string [" + sizeof (valuestring) + "]"};
<<flnowrapvalue = false <<let the browser client wrap this cell
tabletype {
local (itemcount = itemsize);
if defined (itemaddress^.["{aretha stats}"]) {
itemcount--};
if itemcount == 1 {
valuestring = itemcount + " item"}
else {
valuestring = itemcount + " items"};
typestring = "table"};
wptexttype {
valuestring = itemsize + " chars";
typestring = "wptext"};
<<flnowrapvalue = false <<let the browser client wrap this cell
picturetype {
valuestring = itemsize + " bytes";
typestring = "picture"}};
local (maxvaluelen = 80, valuelen);
valuelen = sizeof (valuestring);
if valuelen > maxvaluelen {
valuestring = string.mid (valuestring, 1, maxvaluelen) + "..."};
on td (flnowrap, itemtext) {
local (s = "<td");
if flnowrap {
s = s + " NOWRAP"};
s = s + ">" + itemtext + "</td>";
return (s)};
<<valuestring = string.replaceAll (valuestring, "<", "<") <<make sure HTML codes are readable
s = s + td (true, namestring);
<<s = s + td (flnowrapvalue, html.cleanforexport (valuestring))
if sizeof (valuestring) == 0 {
valuestring = "."};
s = s + td (flnowrapvalue, valuestring);
s = s + td (true, typestring);
s = s + "\r"};
s = s + "</table>\r"}};
outlineType {
local (localOutline = adr^); //work with a copy of the outline
adr = @localOutline;
html.runOutlineDirectives (adr, adrPageTable); //deletes the #attributes
if defined (adrPageTable^.renderOutlineWith) {
local (name = adrPageTable^.renderOutlineWith);
local (adrScript = locateRenderer (name)); //scriptErrors if it fails
local (oldTarget = target.set (adr));
s = adrScript^ (adr);
try {target.set (oldTarget)}}
else {
s = html.getOutlineHtml (adr, "\r<ul>", "\r</ul>", "\r<li>", "</li>")}};
stringType;
wpTextType {
s = html.runDirectives (string (adr^), adrPageTable)};
scriptType {
s = string (adr^ ())}; //call the script, return the string it returns
fileSpecType {
local (f = adr^);
if file.isAlias (f) {
f = file.followAlias (f)};
if true {
s = s + html.runDirectives (string (file.readWholeFile (f)), adrPageTable)}
else {
scriptError (file.fileFromPath (f) + " is not a text file")}};
addressType {
return (html.tenderRender (adr^))}} //recurse
else {
try {
s = "<pre>" + string (adr^) + "</pre>"}
else {
scriptError ("Can't render \"" + string (adr) + "\" because its type is \"" + objectType + "\"")}};
return (s)}
This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.