Monday, November 08, 2010 at 12:03 AM.


local (adrPageTable = @websites.["#data"]);
local (adrSite = parentOf (table.getCursorAddress ()^));
local (flDisplayEachRendering = false);

if not defined (adrSite^) {
	dialog.alert ("Can't publish table because the frontmost window is not contained by a table.");
	return (false)};

bundle { //prevent #-prefixed tables from being published
	<<Sun, May 3, 1998 at 6:03:44 PM by PBS
	on checkTable (adr) {
		<<Check if this object is or is enclosed by a table whose name begins with #
		local (nomad = adr);
		loop {
			if nomad == nil or nomad == @root {
			if nameOf (nomad^) beginsWith "#" {
				return (false)};
			nomad = parentOf (nomad^)};
		return (true)};
	if not checkTable (adrSite) {
		dialog.alert ("Can't publish \"" + nameOf (adrSite^) + "\" because it does not contain web pages.");
		return (false)}};

if not dialog.confirm ("Publish all web objects in \"" + nameof (adrSite^) + "\"?") {
	return (false)};

<<on publishTable (templateName = nil) //PBS 12/6/98: moved code to html.ftpTable
	<<local (f = "", url = "", siteTableAdr)
	<<local (flDisplay = true)
	<<html.callFileWriterStartup (adrSite, adrPageTable)
	<<on doTable (adrTable)
		<<local (i, ct = sizeOf (adrTable^), adr)
		<<for i = 1 to ct
			<<adr = @adrTable^ [i]
			<<window.msg (adr)
			<<if not html.traversalSkip (adr)
				<<if typeOf (adr^) == tableType
					<<doTable (adr)
					<<local (s)
					<<s = html.buildObject (adr, adrPageTable, templateName)
					<<If this is the default page for this site, save the path.
					<<local (default = html.getPref ("defaultFileName", adrPageTable))
					<<if string.lower (nameOf (adr^)) == string.lower (default)
						<<if f != "" and url != ""
							<<if adr == @adrPageTable^.adrSiteRootTable^.[default]
								<<f = adrPageTable^.f
								<<url = adrPageTable^.url
							<<f = adrPageTable^.f
							<<url = adrPageTable^.url
					<<html.ftpText (s, adrPageTable)
	<<doTable (adrSite)
	<<html.callFileWriterShutdown (adrSite, adrPageTable)
	<<window.msg ("")
	<<Should this page be displayed in the browser?
	<<if templateName != nil
		<<if not flDisplayEachRendering
			<<flDisplay = false
	<<Display in browser.
	<<if flDisplay
		<<siteTableAdr = html.getSiteTable (adrPageTable)
		<<if f == "" or url == "" //didn't find default, get last page rendered
			<<f = adrPageTable^.f
			<<url = adrPageTable^.url
		<<if string.lower (html.getPref ("fileWriter")) == "file"
			<<webBrowser.openDocument (f)
			<<webBrowser.openUrl (url)
		<<if user.webBrowser.bringToFrontOnPreview
			<<webBrowser.bringToFront ()

bundle { //are there additional templates that should be used?
	local (templateList = html.getExtraTemplates (adrSite));
	if templateList {
		<<Get the displayEachRendering pref.
		flDisplayEachRendering = html.getPagePref ("displayEachRendering", adrSite, adrPageTable);
		<<Loop through list of templates.
		local (i);
		for i = 1 to sizeOf (templateList) {
			html.ftpTable (adrSite, false, flDisplayEachRendering, adrPageTable, templateList [i])}}};

<<Publish with the default template last.
html.ftpTable (adrSite, false, true, adrPageTable);

return (true)

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.