prep
the ibiza preprocessor

prep evolved from a perl script that i wrote sometime in 1993 to manage my trilingual homepage. since i found it so useful i generalized it and even used it for unix systems administration.

it has found it's way into ibiza as late as 1998 after realizing that my early hands-on approach was overall more readable, flexible and understandable than trying to be "standards-compliant" using SGML (the XML predecessor) mixed with hard-to-distinguish HTML code.

prep consists of about ridiculous 180 lines of code, that do a simple job pretty well. there are hundreds of ways to manage HTML document trees, this is yet another. this is how it works:

just write your text in your desired output format, typically HTML, and intersperse prep commands as needed. there are 3 types of prep commands.

  1. line by line selectors
  2. i needed a practical syntax for keeping multiple languages in a single file. this is what i picked:
    	D)Dies ist ein deutscher Text.
    	I)Questo è un testo italiano.
    	E)This is english text.
    	F)Ça c'est en français.
    
    the flags to be used are defined by the project at hand, or not defined at all. so they need not necessarily be bound to languages, although some flags are set automatically if the output file contains the two-character ISO language code of a language, as for instance in index.en.html.

  3. # instructions
  4. chosen to look familiar, prep supports #if, #else, #endif, #include etc. but most importantly they can be extended with local instructions like #foo or #bar for the project at hand, or even for the current directory. these are the built-in instructions:

    #include <filename>
    this will fetch a file from the current directory and process it inline, including any prep commands if found.
    #if <flag>
    currently the #if / #else / #endif logic operates with the single-letter flags also used for language selection, so you can make a whole part of the document appear only in the german rendition for instance. very practical is the #if 0 (if zero) construct to comment out a large portion of a document.
    #endif or #fi
    terminate the portion of the document affected by the last #if. you can nest #if/endif's at will. #fi is the computer scientists way of saying #endif. it's the word backwards. you can use both.
    #else
    used if the #if condition did not apply
    #if !<flag>
    = if not
    #define <flag>
    usually not useful
    #require <extension>
    looks for an <extension>.pl file to contain perl functions that extend the prep instruction set according to the needs of the project.

  5. ((())) insertions
  6. insertions have unusual looks: a command, optionally with arguments, surrounded by triple braces. i chose the syntax for two reasons, it's unlikely to appear in a regular document and it sticks out of the crowd of HTML statements. the commands are typically defined for the project at hand. the difference to # instructions is that the result of the command is inserted inline into the output document. insertions can be used in the middle of HTML markup, even define parts of the url of a link or image. there are no built-in insertions as yet.

line continuation

if for some reason you want to have the next line of text in the output file to be attached to the current line without a newline inbetween, just place a \ (backslash) at the end of the line. you usually won't need this, but here's an example:
	<a href=home.html>\ 
	E)Homepage\ 
	D)Startseite\ 
	</a>
This makes a link multilanguage without producing ugly linked whitespace.

multiple arguments

both # and ((())) commands may have more than one argument. arguments are seperated in an unusual way: a comma followed and preceded by an empty space, like this:
	#<command> <arg1> , <arg2> ...
This permits you to make a sentence containing a comma a normal argument, as in this example:
	#box http://mp3.pages.de , Funk, Soul, Phorever
The box function may then produce something like this:

Funk, Soul, Phorever

as an often recurring stylistic item of your website. this is how the rounded boxes on www.zeit.de were done, by the way.

perlists info

More detailed information on how to write prep extensions is in the prep for developers document.