Templating system for guile.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
build-aux/guile-baux
.gitignore
AUTHORS
COPYING
ChangeLog
INSTALL
Makefile.am
NEWS
README
README.org
autogen.sh
configure.ac
guile-template.texi
parser.scm
processor.scm
ref.texh
std.scm
template.scm
types.scm

README

-*- org -*-

guile-template: Guile Templating System

A flexible templating system for Guile.

Installation Instructions

There are two options for acquire the source code of `guile-template’. The first option is a tar-distribution, which should contain a pregenerated build system. This option should be used by users. The second option is cloning the repository. This option is for developers.

TAR Distribution

Use the standard workflow of the GNU build system.

./configure
make
make install

Code from Repository

The buildsystem has to be generated before the library can be installed. The `autogen.sh’ script is for this.

./autogen.sh
./configure
make
make install

Basic Usage

To load the module use:

(use-modules (template))

Parse a Template

To parse a template from a file use:

(parse-template-file "filename")

Replace `filename’ with the file name of your template.

Render a Template

To render a template to the current output port:

(render-template (parse-template-file "filename"))

Write a Template

Writing a template for the library is relatively easy. The template language can be embedded in any plain text file. There are some limitations which will be discussed later on in the section `Limitations’.

The template language consists of two different prefixes, each followed with an s-expression or a pair of braces containig a s-expression.

The Scheme Prefix (#:)

One of the prefixes is used to evaluate plain scheme code. In Action this could look like this:

some text ...
     
#:(display "inline scheme code")
     
some more text ...

The Guile Template Language Prefix (#!)

The other prefix is for the templating language implemented by this module. In the code the templating language is called GTL, which stands for Guile Template Language.

The GTL has following features:

  • wrapping argument lists around plain text and other template language expressions (GTL or SCM).
  • `for [var] in [seq]’-loops (std library)
  • `if [condition] [then] [else]’-statements (std library)
  • almost unlimited extensibility through `template-define’, `template-define*’, `template-define-native*’ and `template-define-native’ macros

An example of a template (excerpt of a HTML file):

<ul>
  #!(for i in '(1 2 3 4 5))
    #!(if (= i 3))
      <li>third item: #:{i}</li>
    #!(else)
      <li>#:{i}</li>
    #!(end)
  #!(end)
</ul>

The example produces an output similar to the following:

<ul>
  <li>1</li>
  <li>2</li>
  <li>third item: 3</li>
  <li>4</li>
  <li>5</li>
</ul>

Limitations

The library has following known limitations:

  • SCM macros can’t be used in GTL expressions

As a consequence of the prefix system used to find GTL and SCM expressions, none of these prefixes can be used in plain text. A possible workaround for this is using `#:{#\#}’ instead of `#’ if it is followed by a colon or an exclamation mark. This only affects the whole prefixes `#’ not followed by a colon or an exclamation mark can be used without any limitation.

License

This project is developed under the GPLv3 license. For more information look at the COPYING file.