Today I decided to learn more about the Template-Toolkit. I am the kind of person that can learn the first steps better when I read things on paper. Reading from screen is fine for me for looking up a reference, but reading long texts is a pain. Regardless if it is a CRT or a TFT display.
The docs of Template Toolkit are, as of many Perl modules, splitted in many small chunks, which is also fine for reference, but a pain to print out.
So I decided to put the stuff together in a Word (/me ducks) file and make a pdf out of it, so i can share it with people. I planned to make it in three parts.
- The Manual
- The Tutorial
- The Reference
The manual and the tutorial consist of a few documents so i did them by hand. I copied the relevant parts from the HTML-doc and inserted them into Word, changed headings, inserted pagebreaks, did some pageformatting and printed it to a pdf.
So far so good. But when I came to the reference I realized that there are far too many files to do it conviniently by hand. Solution: script it.
Here is the script I used for the issue. It uses regexes to deal with the html, but since Active States HTML-Docs are computer generated I think that is ok in this case :-D
my @f =
open OUT, ">ref.html";
print OUT <<"HTML";
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w
<title>Template::Config - Factory module for instantiating other TT2 m
<link rel="stylesheet" href="Active.css" type="text/css" />
<link rev="made" href="mailto:" />
<table border="0" width="100%" cellspacing="0" cellpadding="3">
<tr><td class="block" valign="middle">
<big><strong><span class="block"> Template::Config - Factory modu
+le for instantiating other TT2 modules</span></strong></big>
for my $f ( @f )
open IN, $f or die "$f: $!";
while ( <IN> )
$i=1 if /<!-- INDEX END -->/;
$i=0 if /<h1><a name="authors?">/;
#tweak the NAME heading
my $ff = $f;
$ff =~ s/^.+Template/Template/;
$ff =~ s/\.html//;
$ff =~ s/\//::/g;
s/<h1><a name="name">NAME<\/a><\/h1>/[[[PB!]]]<h0><a name="nam
#tweak headings one step smaller
print OUT $_ if $i;
print OUT "</body></html>";
That worked fine. All I had to do manually was replacing the [[[PB!]]]
parts with pagebreaks using the "search and replace" functionality of Word, formatting the pages and adding a autogenerated Table of Contents. Et voila, a full fledged book. :-)
As you may have noticed, the html relies on a external stylesheet, so you can even tweak the formatting to you your liking.
I will put the six Files (TT-Manual-Single, TT-Manual-Double, TT-Tutorial-Single, TT-Tutorial-Double, TT-Reference-Single and TT-Reference-Double) on my webspace at holli.perlmonk.org
as soon as I get home, since I cannot ssh from work.
The difference between "Double" and "Single" here is that one is optimized for double paged print, the other for single page print.Update:
The files are now available at http://holli.perlmonk.org/TTdocs
. There is a 20MB transfer limit per day on jcwren
's server, so please be kind if it does not work for you. Just try the other day.
Are you posting in the right place? Check out Where do I post X? to know for sure.
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
Want more info? How to link
or How to display code and escape characters
are good places to start.