STST - StringTemplate Standalone Tool

StringTemplate Standalone Tool (STST) is a command line utility for processing templates written in the StringTemplate template language. It uses JSON format for the data the template uses. JSON is easy to learn. If you know JavaScript then you already know it.

The STST command takes the name of a template and the name of a file containing JSON format data, makes
the JSON data available to the template as attributes and processes the template with the data to produce
output text. The JSON data must have an object as its root.

Example of how it is used

Create a JSON file called data.js with this content:

{ "audience": "World" }

Create a StringTemplate file called first.st with this content:

Hello $audience$!

From a command prompt in the same folder as the above two files type

> stst first data.js

The output is

Hello World!

It also works with group files and can use the angle bracket lexer. For command usage type: stst -h

Uses and Benefits

  • It is a quick way to try out template syntax without having to write or modify a program. This can benefit seasoned template authors as well as beginners.
  • It could be part of a test framework for StringTemplate itself or for a set of templates in an application. The templates can easily be processed with known data and the expected results asserted.
  • It enables development of the templates before or in parallel with code by creating a JSON data file that represents what the code will produce.
  • It could be used as part of shell scripts where some existing program outputs JSON data and STST is used to generate text from it. The data could come from a web service for example.

The motivation for this tool was first described in On Learning StringTemplate.

This is the very first release of this program. It is version 0.1 Feedback is welcome. The license is BSD just like StringTemplate. Source is included. Use at your own risk. See license (in the zip file) for details.

Install Instructions

Download the stst zip file from the file sharing area or here

Save the zip file and extract it to a directory of your choosing. In the top directory there is a README.txt file. It will have instructions much like the following.

  1. Download stst.zip
  2. Unzip stst.zip into a folder of your choice. For example C:\util\stst. This folder is referred as STST_HOME in the rest of the steps
  3. In the STST_HOME folder copy stst.bat.init to stst.bat. Then edit stst.bat and replace  (HOME) with the path for STST_HOME. For example C:\util\stst. NOTE: if you are using another OS such as Linux you should be able to figure out how to run the program by looking at stst.bat.
  4. Make sure JAVA_HOME is defined or java.exe can be found on the PATH.
  5. (optional) copy stst.bat to a folder on the path or update the path to include the STST_HOME folder.
  6. From a command prompt type stst -h for usage. Then try out some of the samples.