Serious First Steps In UserTalk Scripting
by Matt Neuburg
Author of the book Frontier: The Definitive Guide

Prev | TOC | Next


A Real-Life Problem

Welcome to Los Angeles

As promised, we conclude the tutorial by bringing to bear what we have learned, to write a genuine, working, useful script.

To be honest, we are not the first people to write this script; Dave Winer has already written it. But he wrote it as an example of something you could have written with very little UserTalk training.

He also wrote it to wow the audiences at Internet World in Los Angeles, in March 1997. I was watching, and I think it succeeded admirably in doing so. This is a script with plenty of power, plenty of razzle-dazzle, and plenty of practical utility.

If you like, you can read Dave's little speech that he gave along with the demonstration at the Expo. The demonstration itself was part of Gil Amelio's keynote speech. The speech is at:

http://www.scripting.com/davenet/stories/amelioDemoScript.html

In any case you will need to download the demo material from:

http://www.scripting.com/downloads/amelioWeb.sit.hqx

or:

http://www.scripting.com/downloads/AmelioWeb.zip

This gives you Dave's original version of the script we'll be developing (buildSite), but you can throw that away, since we'll be creating it ourselves. The important thing is the rest of the amelioWeb folder, which contains the objects on which our script will operate.

Defining the problem

The problem is as follows:

Now, those of you who have gone through the Web Tutorial or are familiar with Frontier's Web site management capabilities are probably thinking of using those capabilities to perform this task. But no. We are going to perform this job as a one-off, developing the script from the ground up. In essence, we'll be writing a mini-version of Frontier's own Web site management routines. We will take advantage of only one pre-existing Web site routine: the verb html.processMacros. This will perform the basic HTML generation familiar to users of Frontier's Web facilities: it will put <p> where it comes across two returns in a row, cause any URLs to become live links, and Latin-encode any high-ASCII characters in our text.

Otherwise, everything that this script is to do, we ourselves will cause it to do, step by step.

More detail

Let's look at the problem in some more detail.

Open, with any word-processor, the first of the files in the Source Files folder, face_time.txt. This has the features that we will assume all the textfiles have.

Two returns in a row are significant for separating paragraphs; a single return is not, since this represents merely the wrapping introduced by the file's once having been an email message.

The first paragraph is assumed to be the title; the second paragraph is a byline; the third paragraph will be assumed to be a kind of significant lead, to which we will give some special formatting just to make the page look good, and we will also use it as a subtitle in the table-of-contents page.

The HTML template into which we are to copy this material has already been written for us, based on the look of Apple's Web site. You can open and examine the template, which is called template.html, in a word-processor if you like; but let me summarize for you what it contains. In effect, it goes like this:

<HTML>
    <HEAD>
        <TITLE><<title>></TITLE>
        blah blah blah
    </HEAD>
    <BODY BGCOLOR="white" TEXT="#000000">
    blah blah blah
    <TABLE BORDER=0 WIDTH=500>  
        <TR>
            <TD VALIGN=top WIDTH="100"><br>
                <img src="images/gil.gif" BORDER="0"
                 WIDTH="90" HEIGHT="90" ALT="Next Link">
            </TD>
            <TD VALIGN=top ALIGN="LEFT" WIDTH="385">
                <HR>
                <H1><I><<title>><BR><BR></I></H1>
                <H4><<subtitle>></H4>
                <HR>
                <<bodytext>>
            </td>
        </tr>
    </table>
    blah blah blah
    </BODY>
</HTML>

The template describes a header area and a footer area, and between them, a table. This table has two columns: the first holds a picture of Gil Amelio looking appropriately feisty, and the second is to contain our text.

Into the template have been inserted markers showing where the various pieces of each email are to go. These markers are delimited with "<<" and ">>", since we may reasonably assume that these collocations of characters do not occur for any other purpose in the template.

So, "<<title>>" has been put in two places: between the <TITLE> tags, to generate the titlebar of the browser's window, and after the first horizontal rule in the text part of the table, with <H1> and <I> formatting, to give a visible title. The "<<subtitle>>", the lead paragraph, follows the visible title, in <H4> formatting. Then, after a second horizontal rule, "<<bodytext>>" shows where the balance of the email's contents should be placed.

(There is, in fact, also a "<<url>>" marker in the <META> material at the top, but we'll ignore this for purposes of the tutorial.)

Making a plan

The problem is now very easily defined. Let us ignore the matter of the table-of-contents page for the moment. Then we are faced with a batch-processing problem: we must do what amounts to the same thing to a bunch of files in a folder.

But this, as we know, is trivial; thanks to UserTalk's fileloop() construct, if we can do something to one file, we can do it to them all.

For each email file, what we want to do is this. We want to read the template into memory, as a string, and we want to read an email file into memory, also as a string. We want to parse the email string into its title, its subtitle, and its bodytext.

Then we want to find the markers in the template string, and substitute for each one the corresponding stuff we just parsed from the email string. Finally, we want to write the template string out as a new textfile.

Basically, that's all there is to it. We already know enough about the basic structures of UserTalk to develop a program to do this; verbs that we don't know, we can discover with the helps discussed earlier. Let's get started.


Prev | TOC | Next

All text is by Matt Neuburg, phd, matt@tidbits.com.
For information about the book Frontier: The Definitive Guide, see my home page:
http://www.tidbits.com/matt
All text copyright Matt Neuburg, 1997 and 1998. ALL RIGHTS RESERVED.
No one else has any right to copy or reproduce in any form, including electronic. You may download this material but you may not post it for others to see or distribute it to others without explicit permission from the author.
Downloadable versions at http://www.ojai.net/matt/downloads/scriptingTutorial.hqx and http://www.ojai.net/matt/downloads/scriptingTutorial.zip.
Please do not confuse this tutorial with a certain other Frontier 5 tutorial based upon my earlier work.
This page created with Frontier, 2/11/2000; 6:58:58 PM.