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

system.verbs.builtins.html.buildObject

on buildObject (adrObject, adrPageTable=@websites.["#data"], templateName=nil) {
	local (pc = file.getPathChar (), adrFiltersTable);
	
	local (flSemaphores = true);
	
	bundle { //store the page table address
		html.setPageTableAddress (adrPageTable)};
	
	if not (html.getPref ("useSemaphores", adrPageTable)) {
		flSemaphores = false};
	
	if defined (adrPageTable^) {
		if adrPageTable == @websites.["#data"] { //DW 3/4/98
			table.emptyTable (adrPageTable)}}
	else {
		new (tableType, adrPageTable)};
	
	html.buildPageTable (adrObject, adrPageTable, templateName);
	
	bundle { //handle binary objects
		if typeOf (adrObject^) == binaryType {
			return (html.publishBinaryObject (adrObject, adrPageTable, templateName))}};
	
	if defined (adrPageTable^.filters) { //call firstFilter
		adrFiltersTable = adrPageTable^.filters;
		if defined (adrFiltersTable^.firstFilter) {
			adrFiltersTable^.firstFilter (adrPageTable)}};
	
	local (ro);
	bundle { //semaphore lock around call to render object
		if flSemaphores {
			semaphore.lock ("html.data.adrPageTable", 3600)};
		html.data.adrPageTable = adrPageTable; //see html.refGlossary
		ro = html.tenderRender (adrObject);
		try {delete (@html.data.adrPageTable)};
		if flSemaphores {
			semaphore.unlock ("html.data.adrPageTable")}};
	bundle { //make sure f, fname, and URL reflect page-based directives
		adrPageTable^.fname = html.getFileName (nameOf (adrObject^), adrPageTable); //4.0.1
		local (adrSiteTable = html.getSiteTable (adrPageTable));
		if not defined (adrSiteTable^) {
			scriptError ("Site table is missing at " + adrSiteTable + pc)};
		with adrPageTable^ {
			local (folder = html.getSiteFolder (adrPageTable));
			f = folder + subDirectoryPath + fname;
			if not defined (adrPageTable^.requestHeaders) { //PBS 12/3/98
				<<Don't create the folders if this is a dynamic page.
				file.sureFilePath (f)};
			if not (url endsWith fname) {
				url = string.popSuffix (url, '/');
				url = url + "/" + fname}}};
	if defined (adrFiltersTable^.pagefilter) {
		adrPageTable^.bodytext = ro;
		adrFiltersTable^.pagefilter (adrPageTable);
		ro = adrPageTable^.bodytext};
	local (s);
	adrPageTable^.renderedText = "";
	with adrPageTable^ { //build the page
		bundle { //get the template text into s
			local (adrTemplate);
			if indirectTemplate {
				try {
					adrTemplate = @adrPageTable^.templates^.[template];
					if not defined (adrTemplate^) {
						scriptError ("")}}
				else {
					adrTemplate = @user.html.templates.[template]};
				if not defined (adrTemplate^) {
					scriptError ("There is no template named \"" + template + "\".")}}
			else {
				adrTemplate = @adrPageTable^.template};
			if typeOf (adrTemplate^) == outlineType { //DMB: 2/25/98
				local (outlinecopy = adrTemplate^);
				html.runOutlineDirectives (@outlinecopy, adrPageTable);
				s = s + string (outlinecopy)}
			else {
				s = s + html.runDirectives (string (adrTemplate^), adrPageTable)};
			if defined (adrPageTable^.fileExtension) { //make sure f, fname, and URL reflect template-based directives
				if not (fname endsWith fileExtension) { //there was a #fileExtension directive in the template
					fname = string.popSuffix (fname, '.');
					fname = fname + fileExtension;
					f = siteRootFolder + subDirectoryPath + fname;
					url = string.popSuffix (url, '/');
					url = url + "/" + fname}}};
		local (t = string.replaceAll (title, "\"", "\\\"")); //4.0.1 -- handle titles that contain double quotes
		if html.getPref ("tagSubstitution", adrPageTable) {
			s = string.replaceall (s, "<title>", t);
			s = string.replaceall (s, "<meat>", ro); //grandfathered in, for perpetuity
			s = string.replaceall (s, "<bodytext>", ro); <<4.0.1
			s = string.replaceall (s, "{bodytext}", ro)}; <<5.0
		bundle { //call to html.processMacros
			if flSemaphores {
				semaphore.lock ("html.data.adrPageTable", 3600)};
			html.data.adrPageTable = adrPageTable; //see html.refGlossary
			s = string.replaceAll (s, "\n", ""); //work around Windows problem -- 11/8/97 DW
			s = html.processMacros (s, false, adrPageTable);
			try {delete (@html.data.adrPageTable)};
			if flSemaphores {
				semaphore.unlock ("html.data.adrPageTable")}};
		bundle { //4.2 -- relative addresses are supported directly
			<<Mon, Dec 30, 1996 at 6:26:26 AM by DW
			renderedtext = s;
			s = html.data.standardMacros.glossaryPatcher (adrPageTable);
			s = renderedtext};
		bundle { //5.0 -- support for the #pageHeader attribute
			if defined (adrPageTable^.pageHeader) {
				if flSemaphores {
					semaphore.lock ("html.data.adrPageTable", 3600)};
				html.data.adrPageTable = adrPageTable; //see html.refGlossary
				if typeOf (adrPageTable^.pageHeader) == addressType {
					s = html.processMacros (string (adrPageTable^.pageHeader^), true, adrPageTable) + s}
				else {
					s = html.processMacros (string (adrPageTable^.pageHeader), true, adrPageTable) + s};
				try {delete (@html.data.adrPageTable)};
				if flSemaphores {
					semaphore.unlock ("html.data.adrPageTable")}}};
		bundle { //5.0 -- add linefeeds if the pref is set
			if html.getPref ("addLineFeeds", adrPageTable) {
				s = string.replaceAll (s, "\r", "\r\n")}};
		bundle { //5.0 -- add fatpage comment after everything else
			<<This used to be generated in the pageFooter macro
				<<But then it would get run thru html.processMacros.
				<<Usually not a problem, but sometimes...
				<<Also, grandfathering-in the noHintsInHeader attribute. 
				<<It's an old name for fatpages.
			local (flHints = not html.getPref ("noHintsInHeader", adrPageTable));
			local (flFatPageComment = html.getPref ("isFatPage", adrPageTable));
			if flHints or flFatPageComment {
				s = s + fatPages.buildPageAtts (adrPageTable)}};
		if defined (adrFiltersTable^.finalfilter) {
			renderedtext = s;
			adrFiltersTable^.finalfilter (adrPageTable);
			s = renderedtext}};
	
	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.