|
|
|
|
|
Introduction to PPWIZARD, Part 3
By: Walter Metcalf
Date: 12/01/99
Last week we looked at how to use
PPWizard, the unusually flexible
and powerful Web page design tool from Dennis Bareis to build an actual web page from this site.1
This week we shall continue that tutorial
spirit by taking a detailed look at one of PPWizard's most powerful and best-supported features: the
macro.2 We shall define what a macro is and examine an actual macro and each
of its components in detail with a view to showing the macro's power.
Macro Described
The best way to describe a Macro is to compare it with a Function (or Procedure).
- Similarities
- Functions and Macros are both ways to reduce programming labour for scripts that occur, perhaps
with minor variations, over and over.
- Both are called by name.
- Both may or may not have parameters.
- Differences
- Macros are typically faster for shorter lengths of code (i.e. scripts).
- Note, however, that macros combined with the conditionals such as #ifdef, etc., can result
in entire sections of code disappearing as far as the HTML compiler (i.e. browser) is
concerned resulting in good net performance even with long macros.
- Macros are processed at preprocessor (build) time, and are gone once the browser is loaded.
- Functions are built by the compiler (using java or javascript) and continue to require computer
time while the browser is running.
- If macros become too big, they can become unwieldly, and it may be worth looking into a Javascript
function.
Macro Defined
- Define command
- The usual method of defining a macro is to write the command Define followed by a "\" or
other line continuation character, and then write the definition of the macro below.
3
Here is a simple example:
#define Major \
#if ['{$Color=''}' = ''] \
<H3><Font Color="Red">{$Head}</Font></H3> -\
#elseif \
<H3><Font Color={$Color}>{$Head}</Font></H3> -\
#endif
- Note: All PPWizard macros are conceptually one-line macros. If more than one line is
necessary, then a continuation string (typically "\" or "-\") must be used. This
applies both when defining and when calling.
- Before we begin detailed study of this macro itself, it's worth pointing out that the above
macro is the actual macro that produces the major red headings on this page--it is actual source
code used as an example, and yet you can read the special macro characters such as '<', '>',
and "#". This is because PPWizard includes commands and macros to automate the conversion of these
characters into browser-displayable sequences.
- Components of Macro Definition
- The first component of a macro definition is the macro name, and is required.
- The next element consists of one or more strings of text. This text can be either plain ASCII
or an HTML expression or string. At least one such string is required.
- In our example Major can best be thought of having three main elements: the first
is the string from #elseif to the end of the next line; the second consists of the string
from "#elseif" to "#endif"; and the third consists of the parameters.
- The macro is executed by testing the expression after the #if statement. If true, the value of
the macro is the second line; if it is false then the value of the macro is the line following
"#elseif". The value of the macro is displayed as the heading.
- The next element consists of zero or more parameters. They are not required.
- A simple example of a macro without a parameter would be:
#define EMailGuide "walter.os2@rogers.com"
Apart from being shorter, the obvious advantage to this approach is that whenever
the email address is changed, as it did when the Mining Co. changed its name to About.com,
the email address needs to be changed in just one place instead of hundreds or even
thousands of places.
- A parameter is indicated by an alphameric string preceded by $ included in braces (e.g. {$Color}).
Therefore in the Major macro, there are two parameters: Color and Head.
- Optional Parameter
-
The special notation {$Color=''} indicates that the parameter Color is optional: it may
be omitted. If the parameter is omitted it will be assigned an empty or null
value.
- Finally, as a result of the macro's execution, if the parameter is not supplied ($Color='')
the Font color is changed to Red; otherwise the font color is changed to the color specified
by the Color parameter.
Macro Called
One of the most important things to understand is the difference in format between a macro definition
and a macro call.
- A macro is called by prepending a $ and enclosing the result in angle brackets:
<$Major>
- Notice the angle brackets: it is sometimes easy to confuse these with macro parameters
in definitions which are enclosed in braces.
- Parameters, if any, are generally specified by typing the name of the parameter immediately after
the macro name, followed by an equal sign, and then followed by the value of the parameter in quotes,
or other delimiter.
- Example:
<$Major Head='This is a sample heading'>
- Although the macros we've looked at have been relatively simple, they have demonstrated the most
important points. The complexity of macros is almost unlimited, but then their length begins to
increase very quickly, and space prevents us from investigating them here.
4 If you wish to look at two complex macros that are very useful, I suggest you begin by
downloading the files Htmlpre and Footnote from the PPWizard Web site. These are two especially helpful, not overly complex
headers which contain several related and well-commented macros.
Walter Metcalf
Next week: Setting Up a SOHO Network on OS/2 Warp 4, Part 1
Notes
1 Although PPWizard is not restricted to HTML documents, but in fact can work with REXX, IPF, and plain text documents, I am strictly limiting our discussion to HTML for simplicity and conciseness. For more information on the other formats, see the PPWizard Web site.
2 In fact PPWizard's strong macro support was a key reason why I chose it over its competitors when I decided to switch HTML editors.
3 Several also commands can be used, but generally they are reserved for special situations, so they will not be dealt with here. For information on these commands, please see the on line PPWizard manual.
4 Perhaps at a later date when I have acquired more experience with PPWizard, I'll have another, more advanced tutorial on PPWizard, where we can investigate some of these more complex macros.
Unless otherwise noted, all content on this site is Copyright © 2004, VOICE
|
|
|
|
|
|
|