/*
** Template macro library
**
** By Samuel D. Crow
*/
; NOTE: ALL TEMPLATE DEFINITIONS MUST BE INCLUDED AFTER THIS FILE
Global template={}
Global template["macro$"]={}
/*
** Pattern Pipeline
**
** Does all pattern substitutions between an XML input and src$ table
**
** The following XML comment strings are interpreted as macros by the engine:
** <!--localestr[number][default$]--> is a locale string substitution
** <!--macro[name$][enumeration]--> is a macro substitution for macro$[name$]
** applying then enumeration number Keep track of the enumeration because
** it will be used to differentiate between multiple instances of events.
*/
Function template:PatternPipeline$(xml$, prefix$)
;define source as UTF8 compliant XML after catalog substitution first
Local src$=PatternReplaceStr(xml$,
"<!--%s*localestr%s*%[(%d+)%]%s*%[([^%]]*)]%s*-->", GetCatalogString)
Local out$=PatternReplaceStr(src$,
"<!--%s*macro%s*%[(%w+)%]%s*%[(%d+)%]%s*-->",
Function(name$, count$)
; fetch template
Local temp$=self.macro$[name$]
; add prefix and enumeration to all id assignments
Return(PatternReplaceStr(temp$, "id%s*=%s*\"(%w+)\"",
"id=\""..prefix$.."_%1_"..count$.."\""))
EndFunction)
Return(out$)
EndFunction
It's a 3 stage pipeline process. FIrst it generates all of the locale strings from the catalog file, next it substitutes all of the macros but internally to the macro substitution, it also macro substitutes the prefix and enumeration to each id="idname" string to create id="prefix_idname_1" for each ID. The fanciest part of the macro engine is that each substitution is supplied as an XML comment so there is never a clash between XML and the macros or locale strings. On down the road, I'll add support for this code into the editor.
Major BUGFIX!
I just rediscovered that table keys assigned with strings are case sensitive while method names are always forced lowercase by Hollywood. The load routine in RapaEdit fell prey to this one because it strips out the methods from the save buffer table before serialization and adds them back in when loading. Now that the methods are added back in with the names all lowercase the code works on documents after they have been loaded.