gotmpl is a super simple command line program for rendering templates. gotmpl uses environment variables as its context and go-adaptive-functions for its functions. gotmpl uses go-simple-serializer for parsing text into data, such as in the "Render Time Table" example below.
No installation is required. Just grab a release. You might want to rename your binary to just gotmpl
for convenience.
If you do have go already installed, you can just run using go run main.go
or install with make install
See the few examples below.
Note: Since Go templates add the piped value to the end of the positional argument array, gotmpl reorders the piped value to the beginning of the argument array, so go-adaptive-functions can be used. This leads to a more seamless pattern, particularly for functions such as split
, join
, etc.
Get Shell
echo '{{ split .SHELL "/" | last }}' | gotmpl
Clean Path
echo '{{ .PATH | split ":" | set | array | sort | join ":" }}' | gotmpl
Render Time Table
echo '{{ with $items := .data | parse "csv" }}<table style="text-align:left;font-size:16px;"><tr><th>Time</th><th>Title</th>{{ range $items }}<tr><td>{{ .Time }}</td><td>{{ .Title }}</td></tr>{{ end }}</table>{{ end }}' | data=$(cat timetable.csv) gotmpl
Run tests with make test
(or bash scripts/test.sh
), which runs unit tests, go vet
, go vet with shadow
, errcheck, ineffassign, staticcheck, and misspell.
Spatial Current, Inc. is currently accepting pull requests for this repository. We'd love to have your contributions! Please see Contributing.md for how to get started.
This work is distributed under the MIT License. See LICENSE file.