-
Notifications
You must be signed in to change notification settings - Fork 0
Home
STELETO is a simple cross-platform command line application to convert textual input data into other textual formats, via a custom template. It takes either a delimited text or JSON formatted data file as input, applies the specified template and creates a text file as output. STELETO uses the DotLiquid templating engine, so for further details of the template syntax to use refer to http://dotliquidmarkup.org/. STELETO passes two objects into the template:
- 'data' contains the data read from the input data file
- 'options' contains any additional data items passed in via the -p parameter (see below)
Some example comma-delimited text input data (save as 'c:\path\to\mydata.csv'):
ref,name,qty
A1234,apples,5127
A2345,bananas,235
A3456,pears,8756
OR - JSON format input data (save as 'c:\path\to\myinputdata.json'):
[
{
"ref":"A1234",
"name": "apples",
"qty": 5127
},
{
"ref":"A2345",
"name": "bananas",
"qty": 235
},
{
"ref":"A3456",
"name": "pears",
"qty": 8756
}
]
An example template to be applied to each record in the input data (save as 'c:\path\to\data2text.liquid':
{%- for row in data -%}
Reference : {{ row.ref }}
Description : {{ row.name }} [{{ row.qty }}]
{%- endfor -%}
Windows batch command to perform the conversion:
cd \path\to\steleto
STELETO -i:"c:\path\to\mydata.csv" -o:"c:\path\to\output.txt" -t:"c:\path\to\data2text.liquid" -h -d:,
Contents of the resultant output file (c:\path\to\output.txt):
Reference : A1234
Description : apples [5127]
Reference : A2345
Description : bananas [235]
Reference : A3456
Description : pears [8756]
The STELETO command line options may be present in any order, and may be expressed in a number of ways: (STELETO -? for help):
-i|input [required] - the name of the input data file (including path)
-o|output [required] - the name of the output data file (including path)
-t|template [required] - the name of the DotLiquid template file (including path)
-d|delimiter [optional] - the delimiter character used in the input data file, if applicable (default is tab delimited)
-p|param [optional] - named parameters, passed through to the template file as 'options.name' (usage -p:name:value e.g. -p:age:"42")
-h|header [optional] - presence indicates the first line of the input data file is a header row containing field names
-w|wait [optional] - by default the console would close after processing, this pauses so you can review the output
-?|help - show all available command line options
Note: if your input data file is delimited text but does not have a header row containing field names, STELETO will produce default numbered field names of 'field1', 'field2', 'field3' etc. to identify the fields for use in the template
Now an alternative template, to create XML from the same input data (save as 'c:\path\to\data2xml.liquid'):
<?xml version="1.0" encoding="UTF-8"?>
<items>
{%- for row in data -%}
<item rdf:about="{{ options.uri }}{{ row.ref }}">
<description>{{ row.name }}</description>
<quantity>{{ row.qty} }</quantity>
</item>
{%- endfor -%}
</items>
Windows command to perform the conversion:
STELETO -i:"c:\path\to\mydata.csv" -o:"c:\path\to\output.xml" -t:"c:\path\to\data2xml.liquid" -h -d:, -p:uri:"http://temp1/"
Contents of the resultant output file (c:\path\to\output.xml):
<?xml version="1.0" encoding="UTF-8"?>
<items>
<item rdf:about="http://temp1/A1234">
<description>apples</description>
<quantity>5127</quantity>
</item>
<item rdf:about="http://temp1/A2345">
<description>bananas</description>
<quantity>235</quantity>
</item>
<item rdf:about="http://temp1/A3456">
<description>pears</description>
<quantity>8756</quantity>
</item>
</items>
Not extensively tested, but the existing compiled executable STELETO.exe will also run on LINUX (using the mono platform) without requiring recompilation. To test this we created a UBUNTU blank workspace on Cloud9 (see http://c9.io/). We installed the mono platform using the following commands:
sudo apt-get update
sudo apt-get install mono-complete
We then uploaded the STELETO /bin/Release directory and the data file and the two .liquid templates from the earlier examples, navigated to the directory containing the data file and templates, and typed the following commands:
$ mono ./bin/Release/STELETO.exe -i:"mydata.csv" -o:"output.txt" -t:"data2text.liquid" -h -d:","
STELETO v2.0
Convert 'mydata.csv' with template 'data2text.liquid'
3 rows converted [time taken: 00:00:00.178]
$ mono ./bin/Release/STELETO.exe -i:"mydata.csv" -o:"output.xml" -t:"data2xml.liquid" -h -d:"," -p:uri:"http://temp1/"
STELETO v2.0
Convert 'mydata.csv' with template 'data2xml.liquid'
3 rows converted [time taken: 00:00:00.311]
The two output files were created successfully as documented in the earlier examples