## ## WML Introduction ## Copyright (c) 1997 Ralf S. Engelschall, All Rights Reserved. ## =head1 NAME WML Introduction - An introduction to WML's basic concepts =head1 DESCRIPTION WML is a free HTML generation toolkit for Unix, internally consisting of 9 independent languages. The main idea of WML is a sequential filtering scheme where each language provides one of 9 processing passes. So the frontend F reads I (or from C if I is a dash or completely missing), applies passes 1-9 (or only the I specified by B<-p>) and finally produces one or more Is. WML implements a total of three essential concepts which interact with each other: =head2 CONCEPT 1: SEQUENTIAL FILTERING SCHEME This concept implements the various language features by making use of maximum software leverage, i.e. WML is built on top of 9 languages which are run in a well-ordered fashion by the F frontend. =over =item B Processing: explicit Implementation: Include Pre-Processor (IPP) Author: Ralf S. Engelschall See Also: wml_p1_ipp(1) B This first pass reads I and expands all inlined include file directives by (perhaps recursively) substituting them with the contents of the corresponding file. The file itself will be read from the current working directory or from a list of dedicated include directories (compiled in ones and also given via option B<-I>). When C pairs are appended to the include directive C<$(name)> is expanded to C in this particular include file and all its recursively included files. Additionally this Pass provides an End-Of-Line continuation feature and three special strings. ``C<__FILE__>'' and ``C<__LINE__>'' expand to the current include file and line number while ``C<__END__>'' terminates the reading of the current include file. B #include 'file.wml' [name[=value] ...] #include "file.wml" [name[=value] ...] #include [name[=value] ...] #use wml::category::file [name[=value] ...] some text which is \ continued at this line $(name) __FILE__, __LINE__ __END__ B #use wml::std::tags This FooBar, contained in file __FILE__, line __LINE__. __END__ Documentation of FooBar... =item B Processing: explicit Implementation: Macro Processor for HTML Documents (mp4h) Author: Denis Barbier See Also: wml_p2_mp4h(1) http://www.engelschall.com/sw/mp4h/ B This is the HTML-like macro definition and expansion pass. Here new HTML tags are defined via Cdefine-tag fooE> and later expanded at the location of their usage (CfooE>. The goal of this pass is to create new HTML tags which encapsulate either raw text or even programmed functionality of Pass 3 (ePerl). B ...%attributes... ...%attributes...%body... ... B RSE This is . =item B Processing: explicit Implementation: Embedded Perl 5 Language (ePerl) Author: Ralf S. Engelschall See Also: wml_p3_eperl(1) http://www.engelschall.com/sw/eperl/ B In this pass the real programming takes place. The used language is Larry Wall's Perl 5 scripting language. The language constructs are bristled into the HTML markup code by the use of begin (C:>) and end (C<:E>) delimiters. Additionally this pass provides some nice shortcut: First a <#if..#elsif..#else..#endif> construct which gets expanded to the corresponding Perl construct, second a shorthand (C:= ...:E>) for the construct (C: print ...:E> which is used most of the time. And there is a container tag in F which provides the more high-level container tag CperlE>. B ...Perl 5 constructs... <: ...Perl 5 constructs... :> <:= ... :> B #use wml::std::tags sub isotime { my ($time) = @_; my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($time); my ($str) = sprintf("%04d-%02d-%02d %02d:%02d:%02d", $year+1900, $mon+1, $mday, $hour, $min, $sec); return $str; } The current date is <:= &isotime(time()) :>. =item B Processing: explicit Implementation: GNU m4 Author: Ren'e Seindal (FSF) See Also: wml_p4_gm4(1) http://www.gnu.mit.edu/ B In this pass another macro processor run takes place. While in pass 2 a macro processor with a HTML-like syntax was used for high-level macro programming, this pass uses a macro processor for low-level programming. Mainly this pass is intended to provide low-level symbol and function definitions (C. There is a definition in F which provides a more high-level usage via the CsymbolE> tag. I This pass is run under a special environment: First, all m4 builtin macros have to be prefixed with "C". Second, all variables which are defined by WML (both internal ones and the ones from the B<-D> option) are directly accessible via symbols prefixed with C, i.e. variable C is interpolated when C occurs. Third, the quoting characters are disabled per default to prevent problems with the generated content. If you need quotes (for instance in include files) you have to enable them via CC<_quotes> and disable them later via CC<_noquotes>. B m4_quotes m4_define(`name', `value') m4_noquotes B #use wml::std::tags foo bar quux =item B Processing: explicit Implementation: Divert Author: Ralf S. Engelschall See Also: wml_p5_divert(1) B In this pass a flexible and powerful diversion filter is applied. This is intended to provide a mechanism to change and intermix the order of data blocks. Do not intermix this with neither the general macro mechanisms of pass 2 and 4 nor the less powerful C mechanism of GNU m4. The idea is to define I (via C<{#NAME#}>) at any point and fill such locations later by diverting the data flow to it (via C<{#NAME#:> and C<:#NAME#}>) at another point. What makes this filter such powerful is the fact that both the definition points and the diversion points can be done in any order and they can even be nested. Again WML provides high-level support tags in F for this functionality. B {#NAME#} {#NAME#: data for location `NAME' :##} data for location `NAME' data for location `NAME' B
Stuff for the left border Stuff for the right border The main data =item B Processing: explicit Implementation: Area Subst (ASubst) Author: Ralf S. Engelschall See Also: wml_p6_asubst(1) B In this pass single characters or substrings are substituted within dedicated areas (delimited by C<{: ... :}>). The intend is to support ISO-Latin-1 or other special characters which will be entered as 8 Bit character codes and are substituted by their HTML entity-encoding string. Do not intermix this with macro-expansion of Pass 2 or 4. This is generalized regular expression based substitution pass where you can use Perl's C and C commands to specify the substitutions. These can be placed anywhere inside the substitution area and just have to be marked by C<[[...]]> delimiters. But the commands are always applied to the whole area. B {: ...text..[[s/../../flags]].. ...text..[[tr/../../flags]].. :} B {: [[s|ä|ä|]] [[s|ü|ü|]] Foo Bar Baz Quux with Umlauts ä and ü :} =item B Processing: implicit Implementation: HTMLfix Author: Ralf S. Engelschall See Also: wml_p7_htmlfix(1) B In this pass some commonly known HTML markup code fixups are done. For instance missing C and C attributes for all C tags are calculated and added, C tags are added where missing, missing `C<#>' characters in front of hextriple color attributes are added, numeric attribute values are surrounded by quotes, obsolete HTML markup code like the proprietary CcenterE> tag is replaced by new standard HTML 3.2 tags (Cdiv align=centerE>), etc. pp. =item B Processing: implicit Implementation: HTMLstrip Author: Ralf S. Engelschall See Also: wml_p8_htmlfix(1) B Because macro definitions add newlines to the output (or you have to always use "C<...>ECEC<;;;>", etc), additional comments shell-style would be useful and whitespaces can often be stripped from HTML markup code without changing the result, this special HTML markup code reducement pass is done. The amount of stripping can be controlled by the WML option B<-O>. Default is B<-O2> which does a really good job without destroying anything. There is one special feature one should know: This pass recognizes pre-formatted areas ( CpreE..E/preE>) and skips them. Additionally when you want some area of your input file Threaten like pre-formatted, then this Pass also supports its own container tag named CnostripE...E/nostripE>. This has the same effect like CpreE> but is itself stripped, too. =item B Processing: implicit/explicit Implementation: Slice Author: Ralf S. Engelschall See Also: wml_p9_slice(1) http://www.engelschall.com/sw/slice/ B The last and final pass is a really tricky one again, because one feature is still not implemented. We need some way to conditionally create output to different output files. To accomplish this another source file construct (C<[NAME:...:NAME]>) is recognized which defines so-called I. Those slices are (possibly overlapped or nested) named areas of the input file which can be used via WML's B<-o> option. This option can contain a I in front of the filename which selects the slices to be written to the output file. Such slice-terms are actually set theory terms where slices with the same name define a set. B [NAME: ... :NAME] [NAME: ... :] B [EN:Welcome to:][DE:Willkommen zu:] Foo Bar Baz Quux! =back =head2 CONCEPT 2: WMLRC FILE HIERARCHY AND WMLOPTS VARIABLE The second essential idea of WML is the use of F<.wmlrc> files and a C environment variable for additionally command line options. On startup the frontend F first processes all options found in C, then it reads all options from F<$HOME/.wmlrc> followed by the options of all F<.wmlrc> files found in all parent directories (i.e. F<../.wmlrc>, F<../../.wmlrc>, etc) of the directory containing input file. And finally it processes all options given on the command line. For instance this feature provides you with the ability to setup defaults via B<-D> options in the F<.wmlrc> file at the top of your Webarea. And there is one more special case: The option form -DNAME~VALUE is always sticky to its location, i.e. it always gets evaluated for its local directory context instead of the current working directory where F was started. Use this to easily introduce path or URL variables which adjust automatically to the current context of the generated webpage. =head2 CONCEPT 3: AUTO-ADJUSTED URL AND FILENAME VARIABLES The third essential idea of WML is the above shortly described variable adjustment concept which can be used via variable interpolation. The frontend F provides a B<-D> option for defining variables which get interpolated in each pass: -DNAME=VALUE -DNAME~VALUE For both forms the value can be interpolated via ECE inside Pass 2 and via C:=$NAME:E> in Pass 3. The difference between the two forms is the tricky part of adjustment here: =over 4 =item C<-D NAME=VALUE> Here the variable NAME gets statically set to VALUE. Each time you interpolate the variable the result is exactly VALUE. =item C<-D NAME~VALUE> Here the variable NAME gets initialized with VALUE and VALUE will be treated as either a (not fully qualified) URL or filename. When you interpolate the variable the result is VALUE if the current working directory is the same as where you used the B<-D> option (either where you run the frontend F or a F<.wmlrc> file). Else the result is VALUE relative path-adjusted for the current working directory. =back On the first look this seems useless, but combined with CONCEPT 2 this provides a very essential feature. Here it provides a powerful mechanism to automatically let URLs or pathnames re-calculated for the local context. For instance when you define C<-DROOT~.> in your top-level F<.wmlrc> file then the variable C will be interpolated to `C<.>' at the top-level, to `C<..>' at the first subdir level, to `C<../..>' at the second subdir level, etc. Use this for creating navigation bars or URL references across subtrees. =head1 MORE INFORMATION Now you've seen the various core languages of WML. For a step-by-step introduction to this functionality and to see real examples, I recommend you to read the WML tutorial in wml_tutorial(7) now. Additionally can can step through the set of available standard include files WML ships with. Start with the top-level include file wml::all(3). =head1 SEEALSO wml_tutorial(7), wml_tags(7). wml_p1_ipp(1), wml_p2_mp4h(1), wml_p3_eperl(1), wml_p4_gm4(1), wml_p5_divert(1), wml_p6_asubst(1), wml_p7_htmlfix(1), wml_p8_htmlstrip(1), wml_p9_slice(1). wml::all(3) =cut ##EOF##