Steve.org.uk

Steve Kemp's Homepage

 

 

Templer

templer is a simple static-site generator, written in perl.

Templer is a very simple system which works on the following concepts:

  • A site is made up of "pages" and "assets".
  • A "page" is processed to build HTML output.
  • An "asset" is copied from the input-directory to the output directory with zero changes.

The input pages can be written in Textile, Markdown, or plain HTML. (The latter being useful if you've just switched from doing things "by hand".)

A lot more documentation is available upon the github repository where development occurs.

About Pages

Each input page of your templer site consists of a header, a deliminator ( "----"), and the content. This is an example page:

Title: This is the page title.
----

<p>This is my page body.</p>
<p>My title is <-- tmpl_var name='title' -->.</p>

The page declares the variable "title", which may be used in the body or in the layout file - typically a page would have a title to insert in the <title> section of the generated HTML file.

As you can see the title is also displayed in the middle of the page using the standard HTML::Template markup.

The flexible approach to variables is part of the reason why templer exists, because it allows a lot of clever things to be done.

Layouts

The pages that you write will be wrapped inside a layout prior to being output. The layout is how you define your sites appearance.

If you wish you may change the layout on a per-page basis, by adding a special layout file to your page:

Title: This is the page title.
Layout: another.template
----

<p>This is my page body, it uses a different layout!</p>

Getting Started

When you install templer you'll also install a script called templer-generate which is used to initiate a new site. Given a directory name it will create :

  • A configuration file.
  • A layout.
  • Some trivial input pages

From the generated site you can tweak the layout, add your content, and rebuild by merely running templer in the top-level directory.

Variables

As we've already seen simple variables can be defined and used within pages. (They can also be defined globally in the templer configuration file. To allow you to set a copyright date, visible to all pages for example.)

The declaration of variables is flexible due to the templer plugin-support, so you can declare variables which are simple strings, or which can contain the output of running shell commands, or even matching file patterns.

The following example uses a file-pattern variable to generate a simple gallery including all images beneath img/:

Title: This is the title of my page.
images: file_glob( "img/*.jpg" )
----

Here is my page body.  Here are the images:

<!-- tmpl_loop name='images' -->
 <p>
   <img src="<!-- tmpl_var name='file' -->" />
 </p>
</!-- /tmpl_loop -->

Download

templer is developed and hosted upon Github.com, where you can find both the code and a lot more documentation:

There are packages available for the Squeeze & Wheezy release of Debian GNU/Linux in this repository.

 

Sitemap | Contact Me © 2014 Steve Kemp