#doc:name(scribble/programs/template/tplexp/index.html):template(basic.template)# -- only set for top level index page --#topLevelPage:true# -- only set for pages having an index parent between themselves and the root #parentTarget:../index.html# #parentName:Template# -- the default background is an orange to black fade. Set this to override. --#backgroundImage:black_orangetoblack.jpg# -- include final '/' separator #pathToRoot:../../../../# #pageTitle:tplexp# -- default width is 40%: define to override --#titleWidth:40%# -- navigationBar clump: one row for each entry -- simple rows define navigationName, navigationTarget -- image rows also define navigationImgName, navigationImgX, navigationImgY, -- and navigationImgAlt -- all rows may define navigationHidden to comment out link definitions #clump:name(navigationBar)# #row# -- URL to navigate to #navigationTarget:#symbols# -- navigation text displayed in bar #navigationName:Symbol File# -- define to hide navigation potential (eg if content not ready yet) --#navigationHidden:true# #endrow# #row# -- URL to navigate to #navigationTarget:#usage# -- navigation text displayed in bar #navigationName:How I Use It# -- define to hide navigation potential (eg if content not ready yet) --#navigationHidden:true# #endrow# #row# -- URL to navigate to #navigationTarget:#licence# -- navigation text displayed in bar #navigationName:Licence# -- define to hide navigation potential (eg if content not ready yet) --#navigationHidden:true# #endrow# #endclump# -- pageSection clump: one row for each text section #clump:name(pageSection)# #row# -- title of section #sectionTitle:What It Is# -- defines bookmark within page for this section (used in some nav bars) --#sectionTarget:# -- the text of the section #sectionText:
tplexp is a program which takes two inputs: a template file,
and a symbol file defining token values for that template. It requires
Template.pm to be in the library path.
The usage text for this tool is:
tplexp[-t ] [-odir
I present this program as an example of using Template.pm, not as any kind of example of how to write a parser. Really, don't use this as an example of how to write a parser, or a Perl program in general.
Get tplexp.
The syntax of the symbol files which tplexp reads are designed
to be simple to parse. They support setting multiline
strings, comments, and setting default output.
The symbol file syntax is line-oriented. Blank lines are ignored (unless in a multiline text definition) and all line content must start in column 1. The line types are:
doc descriptor - this is the first line in a symbol file and is ignored if appearing elsewhere. It takes the form
#doc:name(<output file>):template(<template file>)#
... where <output file> is the name of the file where the output should be written (if this is omitted then it is written to stdout), and <template file> is the name of the template file to be used to frame the token values.
comments - any unrecognised lines are ignored, but by convention comments start with "--".
token definitions - the variable parts of the generated content. These have the form:
#<token name>:<value>#
... where <value> may be a short string or multiple lines. Multiline values are terminated with a '#' on the end of the last line. Thus:
-- a simple token value #characterName:Alf du Plex# -- a multiline token value #characterBio:Alf is a simple reporter on a newspaper when he is sent to the Isle of Man to cover the TT races. One morning he wakes up next to a dead body, and before he knows what is happening he is catapulted into combatting an ancient evil, the evil which destroyed Atlantis! #
clumps - clump data is defined using a clump construct. The
clump is opened by specifying its name in a clump, and ended with
an endclump line. The clump so defined is created as a token in
the current token context.
Clumps may be nested.
The clump constructs are of the form:
-- opening a clump #clump:<clump name># -- closing a clump #endclump#
clump rows - Each row of a clump must be defined. These are not identified in any way, being simply added to the clump in the order they are encountered. Row numbering is handled by Template.pm itself.
Rows may only be defined within a clump.
The row constructs are of the form:
-- opening a row #row# -- closing a row #endrow#
evaluated strings - Perl code may be embedded within the symbol
file for evaluation at the time of the symbol file's reading. The content of
an eval construct may be be on one or multiple lines as with a
token definition, but the value is not the text but the result returned from
the Perl code. This value is assigned to a named token.
The eval construct is of the form:
#eval:name(<token name>):<text>#
The text is evaluated as soon as the parsing of the construct has been completed, that is after the terminating '#' is encountered.
WARNING - this construct is the least used and least tested of all that are described here. Use extreme caution.
My primary use for tplexp is to generate most of
my static web content (anything that isn't a photo gallery). I use
make to control updates to the site and include a rule to go
from .symbol to .html.
Take a look at the symbol file for this web page: index.symbol (template)
# -- specifies the font size to be used for this section #sectionFontSize:+1# -- define if a 'top' button is to appear in the margin -- note that the first row of the text table includes the nav bar table, which -- means that the opening section must either be very long or not have a top -- button following it, otherwise things look a bit strange. --#topNavigation:true# -- define if the default horizontal rule is to be omitted #omitSeparator:true# #endrow# #row# -- title of section #sectionTitle:Licence# -- defines bookmark within page for this section (used in some nav bars) #sectionTarget:licence# -- the text of the section #sectionText:This software copyright (c) Duncan Ellis 1999-2005.
This is freely distributable software, but I'd appreciate your passing any fixes or improvements back to me so I can publish them here.
No warranty is offered for the fitness of this software for any particular purpose. Use it at your own risk.
# -- specifies the font size to be used for this section #sectionFontSize:+1# -- define if a 'top' button is to appear in the margin -- note that the first row of the text table includes the nav bar table, which -- means that the opening section must either be very long or not have a top -- button following it, otherwise things look a bit strange. --#topNavigation:true# -- define if the default horizontal rule is to be omitted #omitSeparator:true# #endrow# #endclump#