# tmplpool.icn: Template pool object for webstyler.icn #-- $ifndef __TMPLPOOL_ICN__ $define __TMPLPOOL_ICN__ $define TMPL_POOL_REVISION "$Revision: 1.4 $" $define TMPL_POOL_DATE "$Date: 1996/10/10 18:15:34 $" #================================================================ # Class TmplPool: An instance of this object is a facility for # obtaining template objects, given a template's file name. # Digested templates are cached so that each source file need be # read only once. #---------------------------------------------------------------- # tmplPool := Tmpl_Pool_New ( log ) # [ returns a new template pool object that will use `log' # for error logging when templates are read # ] #-- # template := Tmpl_Pool_Lookup ( tmplPool, fileName ) # [ if fileName is &null and file DEFAULT_TEMPLATE_FILE_NAME # is a valid template file -> # returns the Template object corresponding to that file # | else if fileName points to a valid template file, relative # to the starting directory -> # returns the Template object representing that file # | else -> # tmplPool.log ||:= error message(s) # fail # ] #---------------------------------------------------------------- record tmplPoolTag ( # State for a TmplPool object log, # The log object for template scanning errors templateMap ) # Table: maps fileName |-> template #================================================================ # INVARIANTS #---------------------------------------------------------------- # .templateMap is a table, with a &null default value, that # maps a fileName that names a valid template file |-> the # corresponding template object #---------------------------------------------------------------- $define DEFAULT_TEMPLATE_FILE_NAME "Template" # - - - T m p l _ P o o l _ N e w - - - procedure Tmpl_Pool_New ( log ) local tmplPool tmplPool := tmplPoolTag ( ); tmplPool.log := log; tmplPool.templateMap := table ( ); return tmplPool; end # --- Tmpl_Pool_New --- # - - - T m p l _ P o o l _ L o o k u p - - - procedure Tmpl_Pool_Lookup ( tmplPool, fileName ) #-- 1 -- #-[ template := &null #-] local template #-- 2 -- #-[ if fileName is &null -> # fileName := DEFAULT_TEMPLATE_FILE_NAME #-] / fileName := DEFAULT_TEMPLATE_FILE_NAME; #-- 3 -- #-[ if fileName is a key in .templateMap -> # return the corresponding value # | else -> I #-] if ( template := \ tmplPool.templateMap [ fileName ] ) then return template; #-- 4 -- #-[ if fileName names a valid template file -> # template := a Template object representing that file # | else -> # tmplPool.log ||:= error message(s) # fail #-] if not ( template := Template_New ( fileName, tmplPool.log ) ) then fail; #-- 5 -- #-[ tmplPool.templateMap +:= an entry mapping fileName |-> template # return template #-] tmplPool.templateMap [ fileName ] := template; return template; end # --- Tmpl_Pool_Lookup --- $endif