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.
Create a JSON file called data.js with this content:
Create a StringTemplate file called first.st with this content:
From a command prompt in the same folder as the above two files type
The output is
It also works with group files and can use the angle bracket lexer. For command usage type: stst -h
- 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.
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.
- Download stst.zip
- 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
- 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.
- Make sure JAVA_HOME is defined or java.exe can be found on the PATH.
- (optional) copy stst.bat to a folder on the path or update the path to include the STST_HOME folder.
- From a command prompt type stst -h for usage. Then try out some of the samples.