Introduction
What is terp™?
terp improves ANT builds | terp is a templating engine |
---|---|
|
|
terp improves ANT builds
Here is a little snippet of an ANT script that uses terp to build a C++ shared library. It uses g++ 3.4, but it would be easy to use a different compiler by simply changing the property definition. You could even put the compiler task into a <terp.foreach>
loop and build with several different compilers.
<target name="compile-cpp" description="Build the shared library"> <terp.property name="cpp.comp" expression="^gcc(3.4)" /> <terp.cpp compiler="cpp.comp" targetDir="${basedir}/lib" tempDir="${java.io.tmpdir}/gcc" > <target name="funcs" type="shared" version="1.0.5" /> <relocatable /> <multithreaded /> <rtti value="false" /> <sources dir="${basedir}" includes="*.cpp" /> </terp.cpp> </target>
terp is a templating engine
The "Hello world!" example in terp looks like this:
Hello ${name}!
You can expand this template, for example by using the terp command line utility:
C:\terp\bin>terp -Dname=world -t "Hello ${name}!${eol}" Hello world! C:\terp\bin>
You can deduce the basic template syntax from the above example. Text is simply text; embedded statements start with a ${, end with a }, and surround the terp statement or expression.
We added the pre-defined end-of-line constant eol to the text to make the output look nicer, but this is still a very simple template example that does not require a lot of explanations.
There are many other templating engines, but terp has a number of nice features to distinguish itself from others:
- host reflection for a wide range of pre-defined variables.
- custom executors (active components with specialized knowledge of the application or tool they are invoking).
- tight ANT integration.
- very easily expandable.
terp is a software engineer's template engine. Use it to
- generate source code
- generate reports
- generate web pages
- generate XML documents
So, what is terp?
terp stands for "modular template interpreter." terp is a templating engine with a separate ANT module that takes advantage of the engine. Think of a modular template interpreter as server pages outside of a webserver or as a report generator on steroids. Combine the text generation functionality with powerful host-system experts that understand development tools, including C++ compilers, and the ability to invoke arbitrary Java methods, and you have a very powerful tool. It is modular because you can extend the functionality with your own types. You can even overload the built-in operators for your own types.
Is that all it is?
No, of course not. For some people, the ANT tasks that come with terp will be all they want. A portable C++ compiler task and an iterator task can solve many build problems all by themselves. But maybe you're not interested in that aspect of terp.
If terp statements were limited to simple variable names or mathematical expressions, terp would not be a very exciting tool. You could probably hack up something like that yourself with a couple of days of work. Fortunately, terp is much more powerful.
The following list highlights just a few of terp's basic capabilities:
- support for dynamic file and template inclusion,
for example ${import("nested.tpl")}. - support for advanced text formatting,
for example ${#center}CENTERED TEXT${end}. - support for conditional template expansion,
for example ${if(x>4)}conditional${end}. - support for object enumeration,
for example ${foreach(i:aList)}${i}${end}. - support for Java object fields and methods,
for example ${localhost.name.touppercase()}. - built-in variables for system reflection,
for example ${localhost.procarchs.first.name}. - built-in datatypes,
for example for versions ${^gcc().version.major}.