User:Krauss/arXiv-1/Simplest examples

Complete technical description of the simplest exemples of template systems.

Document generation
For reference to concrete typical applications we can remember form letters and letter frames.
 * Form letter: a letter written from a template, frequently used for "spam", by marketing campaigns. It allows a mass production of very similar letters -- ex. changing destinatary name, "Dear mr. John", "Dear ms. Mary".


 * Letter frame: any content is filled in the blank of a "header and footer" frame template. It allows a mass production of non-similar content letters, with a "standard frame". Both are examples of (production of) a set of "template generated documents".

C simplest template system
This set of files satisfy the "black box criteria". There are 4 files representing the system,
 * The C source code file: represent the template.
 * The "bash file": represent the content.
 * The output files: out1.htm and out2.htm represent the output documents.
 * "data model": a programmer restriction that "all output are simple printf or printf with argv parameters", and "all logic depend only of the argv parameter".

With this mapping and model considerations, many other complex C program can view as template. This example implements a "Letter form" or "Mail merge" simple applications.

FORM LETTER TEMPLATE (simplestTS.c): CONTENTS (simplestTS.sh): OUTPUT-1 (out1.htm): OUTPUT-2 (out2.htm):

Perl simplest template engine
This set of files satisfy the "black box criteria" and the "strict syntax criteria" (for a simple replace script template language).

This Perl simplest template system do the some thing that the C simplest. It is, perhaps, the tiniest software for template engine. There are 4 files representing the system, The sintax of the templates are very simple, there are only document output source code and simple place holders, "_ARG1_", "_ARG2_", etc.
 * The Perl processing with the Perl template interpreter: represent the template engine and its source code.
 * The template: a "strict" template file (!).
 * The "bash file": represent the content.
 * The output files: out1.htm and out2.htm represent the output documents.
 * "data model": it is expressed (enbodyed) by the template engine.

TEMPLATE ENGINE (<tt>simplestTS.pl</tt>): FRAME LETTER TEMPLATE (<tt>simplestTS_frame.tpl</tt>):

FORM LETTER TEMPLATE (<tt>simplestTS_letter.tpl</tt>):

Running the template engine with the <tt>simplestTS_letter.tpl</tt> template file, we obtain the letters, %perl simplestTS.pl John < simplestTS_letter.tpl > out1.htm %perl simplestTS.pl Mary < simplestTS_letter.tpl > out1.htm

We obtain the same out1.htm and out2.htm files, as the "C simplest". The main difference is that the "template script" is processed by a specialized engine (the Perl software), not by the "Perl interpretor language" (see C and PHP simplest cases).

Running the template engine with the <tt>simplestTS_frame.tpl</tt> template file, we obtain the letters with frames, %perl simplestTS.pl ...ALL_THE_CONTENT... < simplestTS_frame.tpl > out.htm

OUTPUT (<tt>out.htm</tt>):

Dynamic web page generation
Dynamic web page applications, for reference to concrete ones.

PHP simplest template system
This set of files satisfy the "black box criteria" and the "strict syntax criteria" (for a unrestrited script template language).

There are 4 files representing the system,
 * The PHP source code file: represent the template.
 * The "URLs": represent the content.
 * The output files at each URL.
 * "data model": a programmer restriction that "all not static output are a GET parameter", and "all logic depend only of the GET parameter".

Many other (also complex) PHP program can viewed as template, with this mapping and model considerations.

TEMPLATE (<tt>simplestTS.php</tt>): CONTENTS (<tt>URLs</tt>): simplestTS.php?arg=John simplestTS.php?arg=May these URLs at the browser produce the same HTML source code as the "C simplest example".

Template-author interfaces: translating template scripts
... script parsers... from a standard (for designers) language to a specific template language. ... The translator with the processor is also a processor, in the black-box model.

PLACEHOLDER TEMPLATE, authored by designer:

A simple C template transducer
... using K-array to

TEMPLATE from programmer: same as designer, is a simple placeholder template.

TEMPLATE translated to C It transformed a "document template" into a "print template".

running the template at a template engine1 (a shell script), %gcc tpl1.c %./a.out inputA1 inputA2 > outA.htm %./a.out inputB1 inputB2 > outB.htm

A simple C unrestritect template script
COMPLEX TEMPLATE, the designer's original template reviwed by programmer (adding a include comand and a if block to tpl.c) Converter (<tt>convT2C.pl</tt> perl program converts T into a C program) that generates C-templates (like the C simplest exemple) from a unrestrited template as input:

TEMPLATE translated to C

running the template at a template engine2 (a shell script), %gcc tpl.c %./a.out inputA1 inputA2 > outA.htm %./a.out inputB1 inputB2 > outB.htm