Here is why you might want to do this. Here are two imaginary pages from a company website:
+----------------------------------------------+ | | | ABC and Co | | PRODUCTS | | | +----------------------------------------------+ | | ... rest of page, with product info here | | +----------------------------------------------+and
+----------------------------------------------+ | | | ABC and Co | | SALES | | | +----------------------------------------------+ | | ... rest of page, with sales info here | | +----------------------------------------------+I've not bothered to do the above in Html - instead I've roughed-out the pages. The main thing is that - like most websites - every page has a standard heading. This often deals with beginning some table definitions, navigation links, perhaps a logo etc.
Obviously, we don't wish to duplicate identical text in each file, because it makes it hard to apply consistent changes.
But look at the above two pages - the headings are not identical - one says SALES, the other PRODUCTS. In fact these could equally be an image of a warehouse, and an image of a banknote.
So - we have a standard heading ,with minor variations dependent on which page the heading prefixes.
You can use a program known as a macro-processor to do the insertion of standard text, and it can also use parameters, to allow for small variations. Don't get confused between a macro- processor and a keystroke recorder. We are talking about files of text here, not keystroke commands.
define $header <html> <title>ABC and Co - param1 </title> <center> <h1>ABC and Co <p> param2 </h1> </center> <table> <tr><td> ... etc enddefine define $trailer </td></tr> </table> ....etc </html> enddefine
The above file holds 2 macro definitions. Each one starts and ends with define and enddefine. The line after define is your choice of macro name, starting with $. These 3 special lines must not be indented. If you indent them, they will be treated as normal lines.
After the name, we get the 'body' - any text. Within the body, the strings param1 param2 ...up to param9 are treated specially. When we call the macro, they will be replaced by parameters.
Here is the sales.htm file, showing calls:
$header =Sales Page =SALES Here is our sales information... blah blah... $trailer
If a call is followed by lines starting with =, these items are regarded as parameters, and are inserted into the body in place of param1, param 2 etc.
In the above, the string 'Sales Page' replaces ' every occurence of param1'
and the string 'SALES' replaces 'param2'
The end of the parameters is shown by a line not starting with an =
A call and its parameters cannot be indented - if they are, they are copied to the output file as normal text.
The real benefit comes when we want a products page: it looks like this:
$header =Products Page =PRODUCTS Our company makes a wide range of items, ... blah blah... $trailer
webmacro defsFileName callsFileName outputFilenamethe output file is the html that you upload to your site.
Here is how I use it:
put webmacro.exe in a folder called ToProcess, among with your html files containing calls.
In ToProcess, create a bat file containing e.g:
webmacro def1.txt index.html ..\upload\index.html webmacro def1.txt music.htm ..\upload\music.htm webmacro def1.txt photos.htm ..\upload\photos.htm webmacro def1.txt downloads.htm ..\upload\downloads.htm webmacro def1.txt contact.htm ..\upload\contact.htm
When you run the above bat, all the files get expanded , and copied into upload.
Of Course, style sheets also reduce repetitive html as well - but you can us them alongside macros.
Undefined calls also cause an error, with an explanatory message.
define $ch3section Section 3.nextnumber enddefineHere are 2 calls:
$ch3section $ch3sectionThey produce:
Section 3.0 Section 3.1 etc
define $macro1 Start macro1 $macro2 =fish End macro1 enddefine define $macro2 in macro2 with a parameter of param1 enddefineThis is processed in 2 passes. First, macro1 is expanded. Then macro2 is expanded. The result from a call of macro1 is:
Start macro1 in macro2 with a parameter of fish End macro1This can be useful. You can build macros based on old macros you have created already, rather than having to duplicate large amouts of text.
2. Conditional output, based on the equality of 2 strings. The magic words doifequal and doifnotequal are used, along with the :: delimiter, as in
doifequal::fred::fred::see thisHere, 'see this' is copied to the output file, because fred = fred. This becomes more useful when the strings include parameters and thisfilename. Here is an example, which personalises a web page:
define $clicked doifequal::thisfilename::param1::doifnotequal::thisfilename::param1:: enddefine We call it by supplying a file name, as in $clicked =index.html $clicked =contact.htmlIf the calls are made within a file named contact.html, then the 'orange' html code is output. From another file, the blue html code is output.Obtaining it
Download webmacro.exe here (50 Kb only!)The program is zero-cost and open-source. The Delphi Pascal code is available on request.