<wmmeta name="Title" value="How to Use WebMake" />
<wmmeta name="Section" value="01-intro" />
<wmmeta name="Score" value="40" />
<wmmeta name="Abstract">
how to write a WebMake file
</wmmeta>

Chances are, you already have a HTML site you wish to migrate to WebMake.
This document introduces WebMake's way of doing things, and how to go
about a typical migration.

---------------------------------------------------------------------------

Place The .wmk File
~~~~~~~~~~~~~~~~~~~

First, pick a top-level directory for the site; that's where you'll place your
**.wmk** file.  All the generated files should be beneath this directory. In
this example I'll call it **index.wmk**.

---------------------------------------------------------------------------

Make Templates
~~~~~~~~~~~~~~

Next, identify the page templates used in the site.  To keep it simple, let's
imagine you have only one look and feel on the pages, with the usual stuff in
it; high-level HTML document tags, such as &lt;html&gt;, &lt;head&gt;,
&lt;title&gt;, &lt;body&gt;, that kind of stuff.  There may also be some
formatting, such as a &lt;table&gt; with a side column containing links, etc.,
or a top-of-page title. All of these are good candidates for moving into a
template. I typically call these templates something obvious like
**page_template** or **sitename_template**, where **sitename** is the name of
the site.

For this example, let's imagine you have the HTML high-level tags and a page
title as your typical template items.

So edit the **index.wmk** file, and add a template content item, by cutting
and pasting it from one of your pages.  Instead of cutting and pasting the
__real__ title, use a metadata reference:
**&wmdollar;&etsqi;this.title&etsqo;**.  Also, replace the text of the page
with **&wmdollar;{page_text}**; the plan is that, before this content item
will be referenced, this content item will have been set to the text you wish
to use.

:: &lt;webmake&gt;
:: &lt;content name=page_template&gt;
::   &lt;html&gt;&lt;head&gt;&lt;title&gt;&wmdollar;&etsqi;this.title&etsqo;&lt;/title&gt;&lt;/head&gt;
::   &lt;body bgcolor=#ffffff&gt;&lt;h1&gt;&wmdollar;&etsqi;this.title&etsqo;&lt;/h1&gt;
::   &lt;hr&gt;
::     &wmdollar;{page_text}
::   &lt;hr&gt;
::   &lt;/body&gt;&lt;/html&gt;
:: &lt;/content&gt;

---------------------------------------------------------------------------

Grab The Pages' Text
~~~~~~~~~~~~~~~~~~

Next, run through the pages you wish to WebMake-ify, and either:

  1. move them into a ''raw'' subdirectory, from where WebMake can read them
  with a "&lt;contents&gt;" [$(contents)] tag, or;

  2. include them into the **index.wmk** file directly.

It's a matter of taste; I initially preferred to do 1, but nowadays 2 seems
more convenient for editing, as it provides a very easy way to break up long
pages, and it makes search-and-replace easy.  Anyway, it's up to you.  I'll
illustrate using 2 in this example.

Give each content item a name.  I generally use the name of the HTML file, but
with a **.txt** extension instead of **.html** to mentally differentiate the
input from the output.

Strip the template elements (head tag, surrounding eye-candy tables, etc.)
from each page, leaving just the main text body behind.  Keep the titles
around for later, though.

:: &lt;content name=''document1.txt''&gt;
::   ....your html here...
:: &lt;/content&gt;
:: &lt;content name=''document2.txt''&gt;
::   ....your html here...
:: &lt;/content&gt;
:: &lt;content name=''document3.txt''&gt;
::   ....your html here...
:: &lt;/content&gt;

---------------------------------------------------------------------------

Convert To EtText (OPTIONAL!)
~~~~~~~~~~~~~~~~~

Now, one of the best bits of WebMake (in my opinion) is EtText [$(ettext)],
the built-in simple text markup language; to use this, run the command-line
tool __ethtml2text__ [ethtml2text] on each of your HTML files to convert them
to EtText, then include that text, instead of the HTML, as the content items.
Don't forget to add **format=''text/et''** to the content tag's attributes,
though:

:: &lt;content name=''document1.txt'' format=''text/et''&gt;
::   ....your ettext here...
:: &lt;/content&gt;
:: ...

To keep things simple, I'll assume you haven't used EtText in the examples
from now on.

---------------------------------------------------------------------------

Add Titles
~~~~~~~~~~

Next, you need to set the titles in the content items, so that they can be
used in higher-level templates, such as the **page_template** content item we
defined earlier.

To really get some power from WebMake, use metadata to do this.

<blockquote>

---------------------------------------------------------------------------

**What is Metadata?**

A __metadatum__ is like a normal content item, except it is exposed to other
pages in the **index.wmk** file.  Normally, you cannot reliably read a dynamic
content item that was set from another page; if one content item sets a
variable like this:

:: &lt;{set foo=''Value!''}&gt;

Any content items evaluated after that variable is set can access
**&wmdollar;{foo}**, __as long as they occur on the same output page__.
However if they occur on another output page, they may not be able to access
**&wmdollar;{foo}**.

To get around this, WebMake includes "the **&lt;wmmeta&gt;** tag" [$(wmmeta)],
which allows you to attach data to a content item.  This data will then be
accessible, both to other pages in the site (as
**&wmdollar;&etsqi;__contentname__.__metaname__&etsqo;**, and to other content
items within the same page (as **&wmdollar;&etsqi;this.__metaname__&etsqo;**).

Think of them as like size, modification time, owner etc. on files; or member
variables in an object-oriented language.

---------------------------------------------------------------------------

</blockquote>

Anyway, titles of pages are a perfect fit for metadata. So convert your
page titles into &lt;wmmeta&gt; tags like so:

:: &lt;content name=''document1.txt''&gt;
::   &lt;wmmeta name=''title''&gt;Your Title Here&lt;/a&gt;
::   ....your ettext here...
:: &lt;/content&gt;
:: ...

Sometimes, for example if you plan to generate index pages or a sitemap later
on, you may wish to add a one-line summary of the content item as a metadatum
called **abstract**. I'll leave it out of the examples, just to keep them
simple.

Metadata should always be referred to in **&wmdollar;&etsqi;square
brackets&etsqo;**. I'll explain why in the next section.

---------------------------------------------------------------------------

Naming The Output URLs
~~~~~~~~~~~~~~~~~~~~~~~

Finally, you've assembled all the content items; now to tell WebMake
where they should go. This is accomplished using the &lt;out&gt; tag.

Each output URL, in this example, requires the following content items:

  * page_template, which refers to:

    * title

    * page_text

As you can see, both **title** and **page_text** rely on which output URL is
being written, otherwise you'll wind up with lots of finished pages containing
the same text. ;)

There are several ways to deal with this.

  1. Set a variable in the &lt;out&gt; text, using &lt;{set}&gt;, to the name
  of the content item that should be used for the **page_text**.

  2. Derive the correct value for **page_text** using the name of the
  &lt;out&gt; section itself.

The easiest way is the latter.  WebMake defines a built-in ''magic'' variable,
"&wmdollar;{WebMake.OutName}" [$(webmake_vars)], which contains the __name__
of the output URL.  (Note that output URLs have both a name __and__ a
filename; you'll see why in the next section.)

To do this, define another content item:

:: &lt;content name=out_helper&gt;
::   &lt;{set page_text=''&wmdollar;{&wmdollar;{WebMake.OutName}.txt}'' }&gt;
::   &wmdollar;{page_template}
:: &lt;/content&gt;

As you can see, this takes the name of the output URL, appends **.txt** to it,
and sets a variable called **page_text** to contain the content item named
thereby.

	BTW: you could simply skip defining this ''helper'' content item
	altogether, and just go to the top of the file and change the template
	to refer directly to **&wmdollar;{&wmdollar;{WebMake.OutName}.txt}**
	instead of **&wmdollar;{page_text}** . That's what I usually do.

But what about the title?  Handily, since we defined the titles as metadata,
and referred to them as **&wmdollar;[this.title&etsqo;** in **page_template**,
this is taken care of; once the **&wmdollar;{page_text}** reference is
expanded, **&wmdollar;&etsqi;this.title&etsqo;** will be set.

Remember I mentioned that metadata should always be referred to in
**&wmdollar;&etsqi;square brackets&etsqo;**? Here's why.  Square bracket
references, or "__deferred references__" [$(deferred_content_refs)], are
evaluated only after "normal, ''squiggly bracket'' content references"
[$(content_refs)].

The example page contains the following content references:

  * &wmdollar;{page_template}, which refers to:

    * &wmdollar;&etsqi;this.title&etsqo;

    * &wmdollar;{page_text}

This allows **&wmdollar;{page_text}** to be expanded first, which causes
**this.title** to be set.  Finally, **&wmdollar;&etsqi;this.title&etsqo;** is
expanded last.

If **page_template** had used a normal content reference to refer to
**&wmdollar;{this.title}**, WebMake would have tried to expand it before
**&wmdollar;{page_text}**, since it appeared in the file earlier.

Anyway, I digress.

---------------------------------------------------------------------------

Writing The &lt;out&gt; Tags
~~~~~~~~~~~~~~~~~~~~~~

Each output URL needs an &lt;out&gt; tag, with a __name__ and a __file__.  The
__name__ provides a symbolic name which one can use to refer to the URL; the
__file__ names the file that the output should be written to.

Typically the name should be similar to the page's main content item's name,
to keep things simple and allow the shortcut detailed in the previous section
to work.

Also, sites typically use a pretty similar filename to the name, for obvious
reasons.  At least, they do, to start with; further down the line, you may
need to move one (or more) pages around in the URL or directory hierarchy;
since you've been referring to them by name, instead of by URL or by filename,
this means changing only one attribute in the &lt;out&gt; tag, instead of
trying to do a global search and replace throughout hundreds of HTML files.

Anyway, here's a sample &lt;out&gt; tag:

:: &lt;out name=''document1'' file=''document1.html''&gt; &wmdollar;{out_helper} &lt;/out&gt;

But what about multiple outputs? Two choices:

  1. Simply list all the output HTML files, one after the other.
  Works fine for small sites, and it's simple.

  2. Use a "&lt;for&gt;" [$(for)] tag.

I don't think you need to see how 1. works, it's pretty obvious.
Let's see how 2. does it:

:: &lt;for name=''page'' values=''document1 document2 document3''&gt;
::   &lt;out name=''&wmdollar;{page}'' file=''&wmdollar;{page}.html''&gt; &wmdollar;{out_helper} &lt;/out&gt;
:: &lt;/for&gt;

Simple.

---------------------------------------------------------------------------

Putting &lt;out&gt; Names To Work
~~~~~~~~~~~~~~~~~~~~~~~~~~~

So you've named the output URLs.   However all your content items contain
static URLs in the HREFs!  Let's fix that.

This really is up to you; it's a global search-and-replace.  Let's say
you want to fix all links to ''document1.html''.  Replace this:

:: &lt;a href=''document1.html''&gt;foo&lt;/a&gt;

with an "URL reference" [$(url_refs)], like this:

:: &lt;a href=''&wmdollar;(document1)''&gt;foo&lt;/a&gt;

Now, even if ''document1.html'' is renamed to ''blah/whatever/doc1.cgi'', you
won't have to do a search-and-replace again.

---------------------------------------------------------------------------

Getting Advanced - Adding Navigation and a Sitemap
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This hasn't been written yet. Sorry!  (TODO)

