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

system.verbs.builtins.html.refGlossary

on refGlossary (name) {
	<<10/19/98; 6:51:19 AM by DW
		<<When generating a link to an object by its name (see the last case) we now won't generate links to tables.
		<<It was always generating an incorrect link in previous versions, so this can't break websites.
		<<Changes:
			<<03/28/00; 2:16:58 PM by PBS
				<<Added the refGlossary callback. If an script in the page table named refGlossaryCallback exists, call it when the glossary item is found. The callback script takes the address of the glossary entry that was found and the address of a variable in which to place text. If the callback returns true, the text it placed in glossaryText is returned, otherwise the normal expansion takes place.
	
	local (adrPageTable = html.getPageTableAddress ());
	local (adrObject = adrPageTable^.adrObject);
	local (adrParent = parentOf (adrObject^));
	on foundIt (adr) { //new in 5.0
		if defined (adrPageTable^.refGlossaryCallback) {
			local (glossaryText);
			if adrPageTable^.refGlossaryCallback^ (adr, @glossaryText) {
				return (glossaryText)}};
		case typeOf (adr^) {
			scriptType { //new in 5.0, glossary items can be scripts
				return (adr^ ())};
			tableType { //new in 5.0, convert a table (prettier to look at) to a glossPatch
				local (s = "[[#glossPatch ", path = adr^.path);
				if html.inResponder (adrPageTable) {
					path = string.popSuffix (path) + ".wsf"};
				s = s + adr^.linetext + "|";
				s = s + path + "|]]";
				return (s)}}
		else {
			local (s = string (adr^));
			if (s beginsWith "{") and (s endsWith "}") {
				return (html.processMacros (s, false, adrPageTable))}
			else {
				if html.inResponder (adrPageTable) and string (adr^) beginsWith "[[#glossPatch " {
					<<Substitute .wsf extension.
					local (path = string.popSuffix (string.nthField (s, '|', 2)) + ".wsf");
					s = string.nthField (s, '|', 1) + "|" + path + "|]]";
					return (s)}
				else {
					return (s)}}}};
	if defined (adrPageTable^.glossary) { //look in the default glossary
		local (adrElement = @adrPageTable^.glossary^ [name]);
		if defined (adrElement^) {
			return (foundIt (adrElement))}};
	try { //check the hierarchy for glossary tables
		local (nomad = adrParent, newNomad, found = false);
		on glossLookup (glossName) {
			if (defined (nomad^.[glossName])) { //the table has a glossary
				local (adrElement = @nomad^.[glossName].[name]);
				if defined (adrElement^) { //it defines the term
					found = true;
					return (foundIt (adrElement))}}};
		loop {
			s = glossLookup ("glossary");
			if found {
				return (s)};
			s = glossLookup ("#glossary");
			if found {
				return (s)};
			newNomad = parentOf (nomad^);
			if newNomad == "" {
				break};
			nomad = newNomad}};
	try { //check the user table glossary
		return (string (user.html.glossary [name]))};
	if not (name beginsWith "#") {
		try { //look for objects at the same level with the name
			local (normalizedName = html.normalizeName (name, adrPageTable));
			local (ext = html.getPref ("fileExtension", adrPageTable));
			local (adr = @adrParent^.[normalizedName]);
			if defined (adr^) {
				if typeof (adr^) != tabletype {
					return ("<a href=\"" + normalizedName + ext + "\">" + name + "</a>")}};
			adr = adrParent^.[name];
			if defined (adr^) {
				if typeof (adr^) != tabletype {
					return ("<a href=\"" + normalizedName + ext + "\">" + name + "</a>")}}}};
	scriptError ("There is no glossary entry named \"" + name + "\"")}



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.