#define TITLE GTML Reference Page #include "header"
This is the reference page for the HTML pre-processor _gtml_. It describes
all the _gtml_ features and commands in detail. For more information about
getting _gtml_, see
_gtml_ features fall into four main areas, and we'll look at them in this order:
The original syntax of _gtml_ was stolen shamelessly from the C language pre-processor, and has been adapted to suit Web site management. It supports the following commands:
There are two ways of writing commands:
#include "header.txt"#literal OFF
<!-- ###include "header.txt" -->
The first method is simpler, and is the recommended way of writing _gtml_ , if possible. However, if you're using an HTML authoring tool which complains about _gtml_ commands, you can use the second method to hide the _gtml_ commands from the tool.
If you have some common text which you want inserted in more than one Web
page, put it in a separate file - say,
#literal on #include "common.txt" #literal off
_gtml_ replaces this line with the entire contents of the file
The name of the file can be defined in a named constant, as described next.
The directories in which the file may be looked for can be defined in a
This is a simple way to create shorthand definitions - what we call named constants, or macros - for your frequently-used text. For some text which you use often - say, an e-mail address - include a line like this:
#literal on #define MY_EMAIL gihan@pobox.com #literal off
This defines a named constant MY_EMAIL and its
value gihan@pobox.com. The value can be any text,
including spaces and HTML markup (leading spaces and tabs are ignored), as
long as it's all on one line or it's all on
multiple consecutives lines with a trailing
To use this named constant, whenever you want your e-mail address, specify it like this:
#entities ON
<>
#entities OFF
The double angle-brackets tell _gtml_ to substitute this with its
definition (You can
There are a few other things you should know about
#entities ON #literal on #define MAILTO #literal off #entities OFF
_gtml_ will happily do both substitutions.
Note: Definitions are evaluated at time of use, not time of
definition. This allows you to change the nested value to get a
different result. To get definitions body evaluated at time of
definition, you must use the
#entities on #literal on #define BLAH A #define! <> fred #literal off #entities off
(This doesn't achieve much here, but typically the second line is in a separate file, which is included by the file with the first line).
#literal on #define A foo #define+ A bar #literal off
#entities on #literal on #define url(x,y) y #literal off #entities off
Now the use of <<url(<<MY_EMAIL>>,Gihan)>> will give:
#entities on Gihan #entities off
#entities on #literal on #define+ url(x) Perera #literal off #entities off
Now guess what the following line will give:
#entities on <>,Gihan,www.pobox.com/~gihan)>> #entities off
Yeah, you find:
#entities on GihanPerera #entities off
If you want to use commas in your arguments you just have to quote the complete argument with single or double quotes.
This is identical to
Use this to remove the definition of a named constant:
#undef MY_EMAIL
If the named constant didn't exist previously, this does nothing.
These commands are used together for conditional output:
Conditional blocks can be nested.
The special named constant TIMESTAMP evaluates to the current date and time. But to use it, you must tell _gtml_ what format to use to print the date/time.
The format string is specified in the
#literal on #timestamp $dd/$MM/$yy at $hh:$mm:$ss #literal off
The value of <<TIMESTAMP>> will then be: 8/06/96 at 11:45:03.
As you can see, certain strings (like $dd) are replaced with
values. The full set of substitution strings is as follows (everything else is
left unchanged in the format string):
| $hh | Hour (00 to 23) |
| $mm | Minute (00 to 59) |
| $ss | Seconds (00 to 59) |
| $Day | Full weekday name (Sunday to Saturday) |
| $Ddd | Short weekday name (Sun to Sat) |
| $dd | Day of the month (1 to 31) |
| $ddth | Day of the month with ordinal extension (1st to 31th) |
| $MM | Month number (1 to 12) |
| $Month | Full month name (January to December) |
| $Mmm | Short month name (Jan to Dec) |
| $yyyy | Year (e.g. 1996) |
| $yy | Short year (e.g. 96) |
Monthnames are output in English by default; but they can be output in
other languages, according to the
This is identical to
The command
For example, this is useful for bracketing blocks of C code, which might
have lines beginning with
The command
This is useful for bracketing blocks of program code, which often contain these characters.
Basic HTML authorized characters may only be ASCII characters. Accentuated
characters are coded in HTML in a certain way. For instance the
#literal on #definechar é é #literal off
Sometimes you might want to input special characters that are not available
on your keyboard, but do not want to input its HTML code (Think of the German
#literal on #definechar ss ß #literal off
The command
When you specify a
See
Because _gtml_ is most useful for managing multiple files, it's quite
common to change something in a #include'd file, and then run _gtml_ on all
the
To make this procedure easier, _gtml_ supports a concept of a project
file. This is a simple text file with the extension
// ...These files can be in other directories below the current directory. Simply specify the file name relative to the current directory (e.g. sub/fred/index.gtm).
The file can be a defined alias filename. In this case use it as a filenamed constant, e.g.
filename FOO bar/foo #entities ON <> #entities OFF
The file name can be followed by a level number and a title, to be
used in
When you run _gtml_ with the project file as a command-line argument, it
will process all the source files in the project file. They will all inherit
the
You may use a project file, but process only selected source files
(declared in the project) with the
Note that
_gtml_ allows you to create a hierarchy of Web pages, with links between them. Each Web page can have a link to the previous page, the next page, or one level up in the hierarchy. Obviously, some of these links don't apply to some pages - _gtml_ generates only those that apply to each page.
You describe the document hierarchy to _gtml_ by listing the file names in the project file in a certain order, with a document level and title for each. Level 1 is for top-level documents, and 2, 3, 4, and so on are lower levels. File names without a level have no hierarchical information attached to them.
When _gtml_ processes a file, it defines special named constants which can
be used in exactly the same way as
For each file, _gtml_ generates the named constants, LINK_PREV, LINK_NEXT and LINK_UP. These correspond to the file names of the previous file, next file and one level up in the hierarchy. In addition, it also generates the corresponding named constants TITLE_PREV, TITLE_NEXT, TITLE_UP and TITLE_CURRENT to be the titles of these files (As stated above, the title follows the level number in the project file).
Some of these named constants may not be applicable to some files, in which case the named constant is not defined for that file.
Here's an extract from a hypothetical _gtml_ project file:
contents.gtm 1 Table of Contents
chapter1.gtm 2 Introduction
sec11.gtm 3 What's the Problem
sec12.gtm 3 Old Approaches
sec13.gtm 3 New Idea
chapter2.gtm 2 Historical Evidence
sec21.gtm 3 Early 1900's
sec22.gtm 3 Recent Findings
chapter3.gtm 2 Our Bright Idea
To take a simple case, the file
The links can be used to create navigation links between the documents. In other words, each document can have links up the hierarchy and to the next and previous documents.
Typically, you would place the navigation information in a common file and
Here's a simple example:
#entities on #literal ON #ifdef LINK_NEXTNext document: <
> #endif #ifdef LINK_PREVPrevious document: <
> ; #endif #ifdef LINK_UPUp one level: <
> ; #endif #literal OFF #entities off
When you have described a document hierarchy, and you use a
With the previous example it gives:
#entities on
<<__TOC_1__('
<<__TOC_1_ITEM__('contents.html','Table of Contents')>>
<<__TOC_2__('
<<__TOC_2_ITEM__('chapter1.html','Introduction')>>
<<__TOC_3__('
<<__TOC_3_ITEM__('sec11.html','What's the Problem')>>
<<__TOC_3_ITEM__('sec12.html','Old Approaches')>>
<<__TOC_3_ITEM__('sec13.html','New Idea')>>
')>>
<<__TOC_2_ITEM__('chapter2.html','Historical Evidence')>>
<<__TOC_3__('
<<__TOC_3_ITEM__('sec21.html','Early 1900's')>>
<<__TOC_3_ITEM__('sec22.html','Recent Findings')>>
')>>
')>>
')>>
#entities off
__TOC_#__(x), and __TOC_#_ITEM__(x,y) have the following default values:
#entities on #literal on #define __TOC_#__(x)
You may redefine this constant to whatever you want as long as you respect the number of variables.
All environment variables are defined as named constants by _gtml_.
The special named constants ROOT_PATH, BASENAME, FILENAME and PATHNAME are set to the current path to root of the project (where the project file resides), output file name without any extension and excluding any directory path information, output file name excluding any directory path information, and directory path information relative to the path to the root of the project.
_gtml_ always searches for include files in the directory of the processed source file first, then the current directory (where the _gtml_ command is executed).
In addition, if you define the named constant INCLUDE_PATH, _gtml_ will interpret it as a list of directories (separated by colons), to search for include files. Those directories may be absolute, or relative to the root path of the project.
By default, _gtml_ writes its output files to the same directory as the corresponding source file. You can override this by defining the named constant OUTPUT_DIR as the name of the output directory.
If you are doing this with a project file, specify OUTPUT_DIR as the top-level output directory. _gtml_ will create the same directory hierarchy for the output files as for the input files (It creates sub-directories as required).
By default all created files are created by changing the
You may change this behavior by defining the special constant EXTENSION to whatever extension you want.
The definition of this constant does not have sense in a source file, since
the output file is already created the moment GTML starts to parse the source
file. It makes sense however to define it in the
If the suffix is preceded by two dots as in
_gtml_ only processes files which are younger than the output files which
they might produce.
This is very useful, as it increases the generation speed of web
sites with a big number of pages, when only one of them has been changed. Same
kind of the way make works.
To enable this feature you just have to define the special constant
FAST_GENERATION. The use of this constant will work only in
This feature does not take into account included files, but only the main
gtml source, and the wanted output. To deal with more complex file
dependencies you may use the make tool in conjunction with the
By default all timestamps produce monthnames and daynames which are output in English. You can output them in other languages by defining the constant LANGUAGE to a value corresponding to an available language.
As of today seven languages are available. The default one is English. Following is the list of those language with the corresponding value for LANGUAGE constant:
fr for French ;
de for German ;
ie for Irish ;
it for Italian ;
nl for Dutch ;
no for Norvegian ;
se for Swedish.
If you can send me month and day names in other languages, just do it, I will integrate it in following versions of _gtml_.
The default delimiters for substituting named constants are
For example, if you had the following lines:
#literal ON
#define OPEN_DELIMITER {{
#define CLOSE_DELIMTER }}
#define MY_EMAIL gihan@pobox.com
#literal OFF
then GTML substitutes MY_EMAIL when it finds the text {{MY_EMAIL}} instead of the default <<MY_EMAIL>>.
As described above, _gtml_
You may embed Perl code into your _gtml_ source file, and have the result of the last evaluated expression inserted in your output file, with the help of the one argument macro __PERL__.
Here is an example inserting the size of the source file:
#entities on <<__PERL__(return (stat(<>< >.".gtm"))[7];)>> #entities off
You may embed system command output into your _gtml_ source file, with the help of
the one argument macro
Here is an example inserting the list of files in the current directory:
#entities on <<__SYSTEM__(dir)>> #entities off
When you run _gtml_ from the command line, you can define named constants like this:
-DMY_EMAIL=fred
This is the same as #define MY_EMAIL fred in the file.
These definitions can occur anywhere within the command-line options, but only affect the files after them. For example, if your command line is:
perl gtml.pl fred.gtm -DMY_EMAIL=fred bill.gtm harry.gtm
then the MY_EMAIL definition doesn't apply to
When you run _gtml_ from the command line on a project file you may want
to process only some of the files used in it. This may be very useful in
conjunction with make for page regeneration based on complex
files dependencies (induced by
To process only one file of a project you can use the
Let us suppose we have this project file, called
// Beginning of foo.gtp define MAIL beaufils@lifl.fr foo.gtm bar.gtm // End of foo.gtp
If you just want to regenerate the
perl gtml -Fbar.gtm foo.gtp
List of files to processed is cleared after each project file treatment.
When you run _gtml_ with the
If you do not specify a filename, the generated makefile is created under
the
To specify a filename, just add it after the
To get a small command line usage description you can use the
If you specify the
To get the version number of the _gtml_ you are currently using you can
use the