Hatchet

Hatchet is a preprocessor for HTML designed to fill the gap between static webpages and full embedded languages. Instead of using special tags, it is capable of replacing ordinary html tags with any text. It will also merge the attributes of any tag it replaces with the attributes of the tag in the source text. In this sense, hatchet is more of a macro expansion tool.

Requirements

Hatchet requires Ruby to run. It has only been tested on linux, but should (theoretically *cough*) work fine in any environment which Ruby supports.

License

Hatchet is released under the GNU Public License. Freedom for the user is important to me as a developer - I want the users to be happy with what I do, not hold them in thrall to my every whim. I'd like to encourage everyone to work with me on this tool, that it may be the best in its class.

Download

hatchet-0.2.tar.gz contains the latest version

hatchet-0.1.tar.gz is also available for download.

Usage

The definitions for the macros are stored in a site.def file which is stored in the root of the html source directory. The site.def file contains many macro definitions. Every macro definition is in the following format:

tag {delimiter ...text... delimiter}

The tag may be an opening tag (like <head>) or a closing tag (like </body>), with the "angle brackets" omitted. You may use any tag, even those not included in html. It is often useful to replace html tags so that your source html can be just as correct as the output.

The delimiter next to the brace is a single character, and must be the same on both sides of the text. It may literally be any character, including a line break. This is to give maximum flexibility to whatever may be inside the braces.

When you've written your site.def file, you then run hatchet with your source directory and your destination directory:

$ hatchet private_html public_html

Hatchet will then copy all non-html files to their appropriate location, and process all html files. Only source files that have been modified more recently than their destination counterparts will be processed.

Example site.def

This is the site.def file I'm currently using for my own website. Notice how the originals may be perfectly legal html. Also notice that in this case, I'm using a line break as the delimiter on all except the closing body tag.

# This junk is required for the W3 commission to be happy with the page
html {
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
}

# Needs the title, base, and stylesheet
head {
<head>
<title>: : : b i t m u s e : : :</title>
<base href="http://www.bitmuse.com/"/>
<link rel="stylesheet" type="text/css" title="default" href="/~azimuth/site.css" media="all"/>
}

# Put the banner on every single page
body {
<body>
<div id="banner">
<img id="logo" src="/bitmuse.gif" alt=": : : b i t m u s e : : :"/><br/>
<a href="code/">code</a> :
<a href="creation/">creation</a> :
<a href="spirit/">spirit</a> :
<a href="misc.html">misc</a> :
<a href="resume.html">resume</a> :
<a href="mailto:azimuth+web@bitmuse.com">email</a>
</div>
<div id="content">
}

# This copyright notice is only displayed when printing out the page
/body {
</div><div id="footer">
<div class="copyright">All text and images copyright © 1998-2005 by Daniel Lowe (http://www.bitmuse.com/).
All rights reserved.</div>
<div class="w3cbuttons">
<a href="http://validator.w3.org/check/referer"><strong>W3C</strong> XHTML 1.1</a>
</div><div class="w3cbuttons">
<a href="http://jigsaw.w3.org/css-validator/check/referer"><strong>W3C</strong> CSS</a>
</div></div>

</body>
}

# Here I just make up my own tag.  I put <vivis-navbar/> in the vivis
# html files and it gets replaced
vivis-navbar {
<div class="navbar">
<a href="code/vivis/index.html">News</a> | 
<a href="code/vivis/about.html">About</a> |
<a href="code/vivis/screenshots.html">Screenshots</a> |
<a href="code/vivis/credits.html">Credits</a> |
<a href="code/vivis/help.html">Help Wanted</a>
</div>
}

To-do List