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

system.verbs.builtins.html.data.standardMacros.embedStyleSheet

on embedStyleSheet (sheetName="default", adrPageTable=nil) {
	<<Embed a style sheet in the <head> of a page.
		<<Call this macro from within your #pageHeader attribute.
		<<This macro renders the style sheet and returns the text.
		<<Style sheets are stored in a #styleSheets table.
		<<You can have multiple, named style sheets.
		<<The #styleSheets are searched hierarchically.
		<<Thu, May 14, 1998 at 4:08:22 PM by PBS
	
	local (nomad, adrStyleSheet, s);
	
	if adrPageTable == nil {
		adrPageTable = html.getPageTableAddress ()};
	
	nomad = adrPageTable^.adrObject;
	
	loop { //search for the named style sheet object
		nomad = parentOf (nomad^);
		if nomad == nil or nomad == @root {
			break};
		if defined (nomad^.["#styleSheets"].[sheetName]) {
			adrStyleSheet = @nomad^.["#styleSheets"].[sheetName];
			break};
		if defined (nomad^.["#prefs"].styleSheets.[sheetName]) {
			adrStyleSheet = @nomad^.["#prefs"].styleSheets.[sheetName];
			break};
		if defined (nomad^.["#prefs"].["#styleSheets"].[sheetName]) {
			adrStyleSheet = @nomad^.["#prefs"].["#styleSheets"].[sheetName];
			break}};
	
	if adrStyleSheet == nil { //Didn't find it
		scriptError ("Can't embed style sheet \"" + sheetName + "\" because it wasn't found.")};
	
	bundle { //render the style sheet object
		case typeOf (adrStyleSheet^) {
			outlineType {
				<<We cache rendered sheets based on modification dates.
				local (adrCache = @temp.renderedStyleSheets);
				local (adrCachedSheet);
				if not defined (adrCache^) {
					new (tableType, adrCache)};
				adrCachedSheet = @adrCache^.[adrStyleSheet];
				if defined (adrCachedSheet^) {
					local (modDateSheet = timeModified (adrStyleSheet));
					local (modDateCache = timeModified (adrCachedSheet));
					if modDateSheet < modDateCache {
						s = string (adrCachedSheet^)}};
				if s == "" {
					s = html.utilities.renderStyleSheet (adrStyleSheet);
					wp.newTextObject (s, adrCachedSheet)}};
			scriptType {
				s = adrStyleSheet^ ()}}
		else {
			s = string (adrStyleSheet^)}};
	
	<<Build the html.
	s = "<style type=\"text/css\">\r<!--\r" + s + "\r-->\r</style>";
	s = string.replaceAll (s, "\r", "\r\t");
	
	return (s)} //return the style sheet



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.