HMarc's Webpage Building & Publishing Tool

Version 0.5 — 01/15/09

Overview

I've created a few simple tools for maintaining and publishing Webpages from any of three platforms: Microsoft Windows, Apple's OS/X, or any of the Linux variants. The basic idea is you create a 'template' file with the boilerplate for all the pages, then create the 'body' of each of the pages you want to publish. One part of the tool creates HTML pages (or PHP pages if you're that sophisticated) by wrapping your body pages in the template. Another part of the tool will push the files to a Webserver via the FTP protocol.

This allows you to keep the 'Master Copy' of your Website files on your desktop or laptop, edit and test them there, and only when you are confident they are production-ready then you can push them up to your Webserver. Of course this means you need some basic working knowledge of HTML and CSS. If you don't have that, this probably isn't for you and I suggest you use one of the many build-your-own-Website tools available on the 'net via a simple Google search. Your ISP (or the place that hosts your Website) quite likely offers such a tool.

Perl Required!

These tools require 'perl', a interpreted programming language which comes pre-installed on OS/X and Linux systems, but not on Windows. An excellent Windows implementation is available as a free download from ActiveState, at the URL below. Just download it and install it with the default options. My tools won't run without it.

http://activestate.com/activeperl/

The 'make' tool

The tool that does 50% of the work is a Perl script called ws-make and it gets invoked by a 'make' script. On OS/X and Linux you can use the built-in 'make' utility, but you'll have to make some other changes (notably, changing the control file's name and writing your own Makefile). If you know what I'm talking about, you'll know what needs to be tweaked to do it that way. Otherwise, just follow along and I'll tell you how to make it work on any system.

The make tool is invoked by a script as shown below:

MS Windows
make.bat perl ws-make %1
Note the "%1" which allows an argument to the 'make' command (necessary for instances when you want to publish your changes).
OS/X & Linux
make ws-make $1
Here the O/S knows that ws-make is a perl script, so the 'perl' isn't necessary. Note the dollar sign instead of the percent sign.

The 'control' file

You tell the tool what files to build, and what files to publish, via a control file which is read and interpreted by ws-make. The control file is called make.cfg and here is a simple example:

# -------------------------------------------------------------
#  The 'BUILD' part, each of these is a command line to be run
# -------------------------------------------------------------
do:	perl make-page proto index
do:	perl make-page proto about-us 
do:	perl make-page proto links 
do:	perl make-page proto thanks 
do:	copy blank.html template

# ------------------------------------------------------------
#  The info needed to make an FTP connection to the Webserver
#  Ignored unless 'publish' argument specified.
# ------------------------------------------------------------

host:       www.yourdomain.com
user:       yourid
password:   yourpassword
homedir:    /

# ----------------------------------------------------------------
#  The 'PUBLISH' part. 
#  Ignored unless 'publish' argument specified.
# ----------------------------------------------------------------
put:	about-us.html
put:	contact-us.html
put:	links.html
put:	thanks.html
ascii:  template

changedir: images
put:	logo-250.png
binary:	logo.png

changedir: 
changedir: docs
put: Instructions.doc
put: Instructions.rtf

The control file explained

# Any blank line, or line beginning with the '#' character is ignored. You can use this to comment your file (as I have done) or to comment out command lines you don't want executed.
do: The rest of the line is a command to be executed. It will ALWAYS be executed, even if you do a 'publish'. In the example above, the perl interpreter is invoked to run the make-page script with a couple of arguments. See documentation below.
host: This identifies the domain name where you want your pages published. Leave off the http:// prefix. The four lines concerned with the FTP host are not used unless you specify 'publish'.
user: This is the user login ID you use for FTP or for Telnet.
password: This is the password that goes with your user ID. Sorry, I can't hide it as the script needs it in plain text. Note that passwords are generally case-sensitive!
homedir: Often, once you get FTP'd into your Web host, you need to change into a subdirectory (e.g. 'html', but without the quotes). If that is the case, do that here. If not, just put a single '/' character here.
put: The rest of this line is the name of a file to be uploaded to the Webserver. The file will be transmitted in binary mode. If you don't know what that means, just use 'put:' for all files, and ignore the 'binary:' and 'ascii:' commands.
ascii: If you know a file is pure ASCII, you can use this command instead of 'put:' and the line-terminators will be translated appropriately as needed. Beware, both Windows and OS/X tools often generate text files (or HTML files) which contain non-ASCII characters.
binary: This will transmit an exact bit-for-bit copy of the file to the Webserver.
changedir: This changes the working directory of the tool to the named directory, which must exist in the current directory on your local machine. If it doesn't exist on the Webserver, it will be created there. Use this to descend into an images directory, for example, to copy your image files. To return to the parent directory, use the command with no argument, or with two periods, e.g. changedir: ..

The make-page utility

The subject of a "do:" line will generally be a make-page command, though any valid command recognized by your operating system is okay too. make-page takes two arguments, the first is the name of a 'prototype' file. The second is the name of an ascii file that contains the HTML you want blended into the resulting HTML file. For example:

perl make-page myproto index

will create a new output file called 'index.html', and open and read a file called 'myproto'. It will copy lines from myproto into index.html until it finds a special HTML comment line that looks like:

<!-- INSERT-HERE -->

It then copies the contents of the 'index' file into index.html, and continues adding the remainder of the 'myproto' file. Thus a file called 'xxx' will produce an output file of 'xxx.html'. This means you never edit 'xxx.html' directly, just 'xxx' (for example).

The fixcr utility

There's another ad hoc tool, called fixcr which takes a single argument which should be an ascii text file (or HTML file). It converts, if necessary, the line terminator(s) of the orignal file to match the convention of your O/S. OS/X and Linux systems use a single 'newline' character, but Windows uses two characters for that: a 'newline' and a 'carriage-return'. So on Windows systems, if you use Notepad on an ascii file that came from a Mac or a Linux system, it will likely all appear to be one long line with no line breaks. The fixcr tool corrects that. Just run it on any files you need to like this:

perl fixcr somefile

Of course on OS/X and Linux systems you could leave off the 'perl' part, but then you probably wouldn't need to run the command at all on those O/S'es...

Getting the tools

The following links will display the perl source code in a window. Just select the entire window contents, open a new file on your system with the appropriate name as shown (ws-make, make-page, make.cfg or fixcr) and paste the contents into it and save it.

make (for OS/X and Linux)
make.bat (for Windows)
ws-make
make.cfg
make-page
fixcr

On Windows, save the make program as 'make.bat'. On OS/X or Linux, save it in the current directory and name it 'make', then chmod it to 770 (it will run instead of the built-in 'make', though it you don't want that behavior you can create your own Makefile and use the real 'make'). And don't forget to edit the 'make.cfg' file appropriately for your project (the one above obviously won't work as-is).

Running the tools

Generally this is the easiest part. To build all your HTML files so you can test them on your local system before uploading, just run the following command. It will tell you what it's doing, so you'll know if it is working:

make

Of course you should test your site thoroughly, which you can do by telling your browser to open the index.html (or default.htm) file in the current directory. If you've used relative links (not absolute links) then it should all work just like it will on the real Webserver. To publish them to the Webserver at your domain, just run:

make publish

That's it!

But I don't want to do it that way!

Of course you may not want to use the make-page tool at all and just create your HTML, images, documents and other files some other way. You can still use my tool to publish the results. Just comment out (or leave out entirely) all the "do:" commands. Running make by itself then won't do anything, but make publish will upload all your files and documents while you go fix another cuppa joe...

Copyright © 2009, by H Marc Lewis. All rights reserved.