fleipold / xtpl

uniX TemPLating

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

% xtpl(1) templating utitiliy % Felix Leipold % May 2012

Description

xtpl is a templating mechnism in the spirit of unix. It was developed to help with document preparation, but could also be used in other circumstances, where text needs to be enriched with output from other utilities.

xtpl takes a template text and substitutes special expressions with the output from external tools. It also allows to filter parts of the document through an external filter.

Including output from a utility

The most basic usecase for xtpl is to simply include the output from a utility into the document. Consider the following example document (readme.txt.xtpl):

The basic structure of the project looks like this:

<<<<
tree -d --charset=ASCII
>>>>

When invoked like this:

xtpl < readme.txt.xtpl

we will get the following output:

The basic structure of the project looks like this:

.
|-- classes
|   |-- lang4j
|   `-- templates
|-- dist
|-- gen-src
|   |-- lang4j
|   `-- ws
|-- lib
|-- src
|   |-- doc
|   |-- generated
|   |-- java
|   |-- templates
|   `-- test
|-- test-results
|-- testclasses
|   `-- lang4j
`-- testout
    `-- lang4j

Filtering parts of the document

Now we do not only want to get the output from an external utility, we also want to pipe input into that process. Like the following example:

A sorted list of names:

<<<<
sort
Michael
Mark
Paul
Andrew
>>>>

Piping this through xtpl will yield:


A sorted list of names:

Andrew
Mark
Michael
Paul

Redirecting the output of a utility into a separate file - e.g. Images

Sometimes we also might want to include only a link to a resource into our text. A classical example would be a graph generated by dot:

An example graph rendered using dot:

<img href="<<<<
dot -Tpng >>> graph.png
digraph g{
    a -> b
    c -> b
}
>>>>">

Now this yields the following output:

An example graph rendered using dot:

<img href="graph.png">

Also there is now a file called graph.png, so that when we look at the file with the browser we will see the graph.

About

uniX TemPLating


Languages

Language:Ruby 100.0%