Monday, November 08, 2010 at 12:03 AM.
system.verbs.builtins.html.data.standardMacros.linkStyleSheet
on linkStyleSheet (sheetName="default", sheetTitle="", adrPageTable=nil) { <<Create a link to an external style sheet of the form: <<<link rel=stylesheet href="../defaultStyleSheet.css" type="text/css"> <<Call this macro from within your #pageHeader attribute. <<Style sheets are stored in a #styleSheets table. <<You can have multiple, named style sheets. <<The #styleSheets are searched hierarchically. <<This macro also renders the style sheet and writes it to disk. <<Thu, May 14, 1998 at 3:35:12 PM by PBS local (nomad, s, urlPrefix, adrStyleSheet); local (folder, styleSheetText, fname); local (templateName); if adrPageTable == nil { adrPageTable = html.getPageTableAddress ()}; <<Are we using an alternate template? <<Saturday, May 30, 1998 at 5:04:32 PM by PBS try { if adrPageTable^.indirectTemplate { templateName = html.getPref ("template", adrPageTable)}}; bundle { //find the address of the style sheet on getStyleSheetAddress (altTemplate=nil) { nomad = adrPageTable^.adrObject; folder = file.folderFromPath (adrPageTable^.f); urlPrefix = ""; loop { //search for the named style sheet object nomad = parentOf (nomad^); if nomad == nil or nomad == @root { break}; if altTemplate != nil { if defined (nomad^.["#styleSheets"].[altTemplate].[sheetName]) { adrStyleSheet = @nomad^.["#styleSheets"].[altTemplate].[sheetName]; break}; if defined (nomad^.["#prefs"].styleSheets.[altTemplate].[sheetName]) { adrStyleSheet = @nomad^.["#prefs"].styleSheets.[altTemplate].[sheetName]; break}; if defined (nomad^.["#prefs"].["#styleSheets"].[altTemplate].[sheetName]) { adrStyleSheet = @nomad^.["#prefs"].["#styleSheets"].[altTemplate].[sheetName]; break}} else { 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}}; folder = file.folderFromPath (folder); urlPrefix = "../" + urlPrefix}}; if templateName != nil { getStyleSheetAddress (templateName)}; //alternate template if adrStyleSheet == nil { getStyleSheetAddress ()}; //default template if adrStyleSheet == nil { //Didn't find it scriptError ("Can't link to style sheet \"" + sheetName + "\" because it wasn't found.")}}; bundle { //build the html local (maxLen = number (html.getPref ("maxFileNameLength", adrPageTable))); if sizeOf (sheetName) > (maxLen - 4) { //make sure the file name isn't too long sheetName = string.mid (sheetName, 1, maxLen - 4)}; fname = sheetName + ".css"; s = "<link rel=stylesheet href=\"" + urlPrefix + fname + "\""; if sheetTitle != "" { s = s + " title=\"" + sheetTitle + "\""}; s = s + " type=\"text/css\">"}; 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 { styleSheetText = string (adrCachedSheet^)}}; if styleSheetText == "" { styleSheetText = html.utilities.renderStyleSheet (adrStyleSheet); wp.newTextObject (styleSheetText, adrCachedSheet)}}; scriptType { styleSheetText = adrStyleSheet^ ()}} else { styleSheetText = string (adrStyleSheet^)}}; bundle { //write the style sheet to disk if needed local (f = folder + fname, flWrite = true); if file.exists (f) and (string.lower (html.getPref ("fileWriter", adrPageTable)) == "file") { if file.modified (f) > timeModified (adrStyleSheet) { if typeOf (adrStyleSheet^) != scriptType { flWrite = false}}}; if flWrite { html.writeFile (f, @styleSheetText, 'TEXT', html.getPref ("textFileCreator"), clock.now (), adrPageTable)}}; return (s)} //return the link text
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.