1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>hsc - Features - Macros</TITLE>
<LINK REV="owns" TITLE="Thomas Aglassinger" HREF="mailto:agi@giga.or.at">
<LINK REL="Next" HREF="flag.html">
<LINK REL="Copyright" HREF="../copy.html">
<LINK REL="Previous" HREF="../features/expressions.html">
<META name="ROBOTS" content="NOINDEX, NOFOLLOW">
</HEAD>
<BODY>
<A HREF="../index.html"><IMG SRC="../image/main.gif" ALT="Contents" ALIGN="middle" WIDTH="70" HEIGHT="16"></A>
<IMG SRC="../image/noindex.gif" ALT="-----" ALIGN="middle" WIDTH="70" HEIGHT="16">
<A HREF="../copy.html"><IMG SRC="../image/copy.gif" ALT="Copyright" ALIGN="middle" WIDTH="70" HEIGHT="16"></A>
<A HREF="../index.html"><IMG SRC="../image/back.gif" ALT="Up" ALIGN="middle" WIDTH="70" HEIGHT="16"></A>
<A HREF="../features/expressions.html"><IMG SRC="../image/prev.gif" ALT="Previous" ALIGN="middle" WIDTH="70" HEIGHT="16"></A>
<A HREF="flag.html"><IMG SRC="../image/next.gif" ALT="Next" ALIGN="middle" WIDTH="70" HEIGHT="16"></A>
<HR>
<H1>Macros</H1>
Macros are a powerful feature which enables you to create shortcuts
for often used text. As you can also pass arguments to macros, it is
even possible to create templates for whole pages.
<H2>General Syntax</H2>
Macros can be defined like
<BLOCKQUOTE><CODE><$macro</CODE> <I>MacroName</I>
[ <I><A HREF="flag.html">modifiers</A></I> ]
[ <I><A HREF="attrib.html">attributes</A></I> ]
<CODE>></CODE><BR>
<BR>
<I>...macro text...</I><BR><BR>
<CODE></$macro></CODE></BLOCKQUOTE>
Here are some examples of macro definitions:
<H2>Use As Shortcuts</H2>
You can define a macro called <CODE>Hugo-Address</CODE> that only is a
shortcut for your email-address like
<PRE><$macro Hugo-Address>
hugo@some.where
</$macro>
</PRE>
So every time, you insert the macro-tag <CODE><Hugo-Address></CODE> in your
hsc-source, it will be replaced by
<PRE>
hugo@some.where
</PRE>
in the html-object.
<H2><A NAME="container">Container Macros</A></H2>
<P>Container macros allow you to create a macros with a text before
and after the content. While the preceding/succeeding text is
specified with the macro declaration, the content is assigned during
the macro call.</P>
<P>To declare a macro as container, you have to specify the modifier
``<CODE>/CLOSE</CODE>''. To insert the contents, use the special tag
<CODE><$content></CODE>. Alternatively, you can access the content with
the special attribute <CODE>HSC.Content</CODE>.</P>
<P>You can use <CODE><$content></CODE> multiple times inside the same macro,
too.</P>
<P>To call a container macro, act the same as with the simple macro you
have seen in the above example. But different to before, now also
a end-tag has to show up. Everything between the corresponding start- and
end-tag will be interpreted as content.</P>
<P>You should be aware of the fact that <KBD>hsc</KBD>, when scanning for the
end-tag for the macro, does not in process other macros or
<CODE><$include></CODE>-tags, but only looks at the text. Therefor the
end-tag has to show up within the same input file as the
start-tag.</P>
<P>Ok, that was a bit much. Probably a good time for an example...</P>
<H2>Declare Your Own Logical Styles</H2>
<P>One of the most laughable stories about html is the one about
physical and logical styles: It is possible to render text in bold or
italic letters using tags like <CODE><B></CODE> or <CODE><I></CODE>, which are
known as physical styles. Furthermore, you can also use some logical
styles like <CODE><CODE></CODE> or <CODE><KBD></CODE>, which should be used to
mark sequences of code or user input. Both are usually rendered same
as the physical style <CODE><TT></CODE> (typewriter font).</P>
<P>As everyone with a brain implemented could have told from the
beginning, the number of physical styles increased with every new html
release. In the draft to (never released) html-3.0 tags appeared to
render names of authors, acronyms, persons etc. The lack behind these
concepts became that obvious that even w3c found out it sucks. And so,
probably only soon before tags like
<CODE><Tim-Berners-Lee-s-favourite-tag-to-render-his-name></CODE> made it
into the specifications, this concepts has been abandoned.</P>
<P>However, it has not been replaced by anything more useful, and
this has not changed much until today; except that many people are
waiting for a new holy cow called Style Sheets.</P>
<P>So makes sense to use container macros as substitute for logical
styles, which will do nothing but enclose the content in a physical
style. Below a macro <CODE><FILE></CODE> will be created, which can be used
to render filenames:</P>
<PRE><$macro FILE /Close><I><$content></I></$macro>
</PRE>
Your new style can be used like all other styles:
<PRE>
..open the file <FILE>hugo.txt</FILE> and..
</PRE>
In this case, filenames will be rendered <I>italic</I>:
<BLOCKQUOTE>
..open the file <I>hugo.txt</I> and..
</BLOCKQUOTE>
<P>It should be rather obvious how this one works: When calling the
macro using <CODE><FILE></CODE>hugo.txt<CODE></FILE></CODE>, hsc will scan the
input until it reaches a <CODE></FILE></CODE>. Anything between the
corresponding start and end tag will be used as content, in this case
``hugo.txt''.</P>
<P>Now the macro text will be interpreted: The first part is easy, a
simple <CODE><I></CODE> will be inserted. After that, a <CODE><$content></CODE>
shows up, and the content read before will be inserted. In this case,
this is a simple plain text, but of course you could also use tags or
even other (container) macros. At the end of the macro, a closing
<CODE></I></CODE> is appended, and the macro call exits.</P>
<H2>Nesting Container Macros</H2>
<P>You should be aware that the macro content (the text specified
between the corresponding start and end macro tag) can not access
attributes which have been declared for the macro text (the text which
is assigned to the macro while declaring it using
<CODE><$macro></CODE>).</P>
For example:
<PRE><$macro sepp /close hugo:string>
sepp : hugo=<(hugo)>
<$content>
sepp : hugo=<(hugo)>
</$macro>
<$define hugo:string="content's hugo">
<sepp hugo="sepp's hugo">
content: hugo=<(hugo)>
</sepp>
</PRE>
will result in
<PRE>
sepp : hugo=sepp's hugo
content: hugo=content's hugo
sepp : hugo=sepp's hugo
</PRE>
The line
<PRE>content: hugo=<(hugo)></PRE>
<P>does not - as some might have expected - access the attribute
<CODE>hugo</CODE> passed to the container macro <CODE><sepp></CODE> just
before, but still reads the attribute <CODE>hugo</CODE> declared above
using <CODE><$define></CODE>.</P>
The reason for this shows up soon when you start using container
macros inside container macros: every time a <CODE><$content></CODE> shows
up while just processing a <CODE><$content></CODE>, it does not make much
sense to include the same content as just before. Instead, the parser
uses the content passed to the previous but one container macro.
For example:
<PRE><$macro hinz /close>
hinz=( <$content> )
</$macro>
<$macro kunz /close>
kunz=( <$content> )
</$macro>
<hinz><kunz>...some text...</kunz></hinz>
</PRE>
will result in
<PRE>
hinz=( kunz=( ...some text... ) )
</PRE>
<H2>Macros With Attributes</H2>
Take a look at this example:
<PRE><$macro Button.Next NxtRef:uri>
<A HREF=(NxtRef)><IMG SRC=":image/next.gif" ALT="Next"></A>
</$macro>
</PRE>
This defines a macro that defines a button that references to the next
page. As every page has its own next page, you can set one attribute
for this macro: <CODE>NXTREF</CODE>, which is the URI that should be
referenced as the "next" page.<P>
So an example usage of this macro would be:
<PRE>
<Button.Next NXTREF=":features/rplcent.html">
</PRE>
which will give the button seen below:<P>
<A HREF="../features/rplcent.html"><IMG SRC="../image/next.gif" ALT="Next" WIDTH="70" HEIGHT="16"></A><P>
Note that the value of <CODE>NXTREF</CODE> is passed to the
<CODE>HREF</CODE> attribute within the <CODE><A></CODE> tag when the macro
is extracted.<P>
If you wonder, what <CODE>HREF=(NxtRef)</CODE> (see above) should
mean: This sets <CODE>HREF</CODE> with the value stored in
<CODE>NxtRef</CODE>. For details, read the section about <A
HREF="../features/expressions.html">expressions</A>.
<H2>Macros Inside Macros</H2>
Currently, locale macros are not supported. If you declare a macro
inside a macro, the inner macro will be declared when the outer macro
is called. For example:
<PRE><$macro outer-sepp>
now in outer sepp
<* define inner-sepp *>
<$macro inner-sepp>
now in inner sepp
</$macro>
<* use inner-sepp *>
<inner-sepp>
</$macro>
<outer-sepp>
</PRE>
will result in
<PRE>
now in outer sepp
now in inner sepp
</PRE>
<P>At the moment you can call <CODE><inner-sepp></CODE> even outside of
<CODE><outer-sepp></CODE>, as it is defined globally. When calling
<CODE><outer-sepp></CODE> another time, you will receive a <A HREF="../messages.html#message.59">message #59</A>,
as this tries to redefine <CODE><inner-sepp></CODE>.</P>
Obviously this behaviour doesn't make sense, but local macros are not
supported in this release.
</BODY></HTML>
|