Basically, HTML has two kinds of components: HTML elements and HTML environments. An HTML element has the form `` <NAME Attributes >'' were NAME is the name of the element and Attributes is a (possibly empty) sequence of attributes, each of them being either an attribute name or an attribute assignment as name="Value".
An HTML environment has the form ``<NAME Attributes >
Text </NAME>
'' were NAME is the name of the
environment an Attributes has the same form as before.
The general Prolog structures that represent these two HTML constructions are:
img$[src='images/map.gif',alt="A map",ismap]
is translated into the HTML source
<img src="images/map.gif" alt="A map" ismap>
Note that HTML is not case-sensitive, so we can use lower-case
atoms. address('clip@dia.fi.upm.es')
is translated into the HTML source
<address>clip@dia.fi.upm.es</address>
a([href='http://www.clip.dia.fi.upm.es/'],"Clip home")
represents the HTML source
<a href="http://www.clip.dia.fi.upm.es/">Clip home</a>
Now we can rewrite the previous example as follows:
#!/usr/local/bin/lpshell :- use_module('/usr/local/src/pillow/pillow.pl'). main(_) :- get_form_input(Input), get_form_value(Input,person_name,Name), response(Name,Response), output_html([ 'Content-type: text/html', html([title('Telephone database'), img$[src='phone.gif'], h2('Telephone database'), hr$[], Response)]). response(Name, Response) :- form_empty_value(Name) -> Response = 'You have to provide a name.' ; phone(Name, Phone) -> Response = ['Telephone number of ',b(Name),': ',Phone] ; Response = ['No telephone number available for ',b(Name),'.']. phone(daniel, '336-7448'). phone(manuel, '336-7435'). phone(sacha, '543-5316').
Any HTML construction can be represented with these structures (except comments and declarations, which could be included as atoms or strings), but the PiLLoW library provides additional, specific structures to simplify HTML creation.