3.3 The First Page

3.3.1 Covered Topics

This section will teach you

3.3.2 Writing Sources

The sources described in this section can be found inside directory tutorial-1 in the examples archive downloadable from http://www.g-cows.org/.

Create an empty directory called tutorial/ and cd into it:

$ mkdir tutorial
$ cd tutorial

Now, let's create a directory called lib/ to store files which will be included from other scripts and not processed directly with Cows, nor viewed directly as HTML files.

$ mkdir lib

Now, let's create two scripts: header_html and footer_html. The former will create all the HTML code before page content, while the latter will create all the HTML code after page content. Since page elements flow from top to bottom and from left to right, header_html will create page elements located above the contents and at the left of it; footer_html will create page elements located below the contents and at the right of it.

Every page will include script header_html at the beginning, and footer_html at the end. Between the include directives, we'll write page content. This is a good way to build a site: contents and layout are separated and site maintenance will be very easy.

Create files lib/header_html and lib/footer_html with the following contents.

File lib/header_html:

<center>
[
  <a href="index.html">Home (Animal Rights)</a> |
  <a href="vegetarianism.html">Vegetarianism</a> |
  <a href="vivisection.html">Vivisection</a> |
  <a href="hunting.html">Hunting</a> |
  <a href="furs.html">Furs & Leather</a> |
  <a href="entertainment.html">Animals in Entertainment</a>
]
</center>
<hr>

File lib/footer_html:

<hr>
Webmaster: <a href="mailto:webmaster@your-domain">webmaster@your-domain</a>

Now, let's create our first Cows source file:

File index.cws:

<html>
<head><title>Animal Rights</title></head>

<body>

<cows verbatim ("lib/header_html"); />

<h1>Animal Rights</h1>

<p align="right">
Because the heart beats under a covering of hair,<br>
of fur, feathers, or wings, it is, for that reason,<br>
to be of no account?<br>
<em>-- Jean Paul Richter</em>
</p>

<cows verbatim ("lib/footer_html"); />

</body>
</html>

So, we've just introduced the first Cows function: verbatim(). It simply inserts a copy of an external file within the page.

3.3.3 Creating Resulting Files

The files created so far are:

In order to create a standard HTML page, simply run Cows and check the newly created file:

$ cows index.cws index.html
$ ls -F
lib/  index.cws  index.html

This is the resulting file index.html:

<html>
<head><title>Animal Rights</title></head>

<body>

<center>
[
  <a href="index.html">Home (Animal Rights)</a> |
  <a href="vegetarianism.html">Vegetarianism</a> |
  <a href="vivisection.html">Vivisection</a> |
  <a href="hunting.html">Hunting</a> |
  <a href="furs.html">Furs & Leather</a> |
  <a href="entertainment.html">Animals in Entertainment</a>
]
</center>
<hr>


<h1>Animal Rights</h1>

<p align="right">
Because the heart beats under a covering of hair,<br>
of fur, feathers, or wings, it is, for that reason,<br>
to be of no account?<br>
<em>-- Jean Paul Richter</em>
</p>

<hr>
Webmaster: <a href="mailto:webmaster@your-domain">webmaster@your-domain</a>


</body>
</html>

Let's see how it looks with the Lynx text browser:

$ lynx index.html


      [ Home (Animal Rights) | Vegetarianism | Vivisection |
      Hunting | Furs & Leather | Animals in Entertainment ]
     _______________________________________________________

                            Animal Rights

              Because the heart beats under a covering of hair,
            of fur, feathers, or wings, it is, for that reason,
                                           to be of no account?
                                           -- Jean Paul Richter
     _______________________________________________________

   Webmaster: webmaster@your-domain

3.3.4 Conclusions

We've just seen how to include external HTML files within Cows. This is a quick way to reuse fragments of code without having to copy them from file to file. So, when you change the included file, it's much easier to update contents: time wastes and chances of an error are greatly reduced.

Note: we used two extensions throughout this example:

.cws

files containing Cows-scripts

.html

generated HTML files

HTML fragments included verbatim have been called header_html and footer_html because they are not complete HTML files and, most important, to avoid confusion with HTML files generated by Cows.

This manual can be downloaded from http://www.g-cows.org/.