Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/docwhat/temple
Sick of sed? Prosaic about perl? Use temple to substitute your variables!
https://github.com/docwhat/temple
go golang substitute template
Last synced: 2 months ago
JSON representation
Sick of sed? Prosaic about perl? Use temple to substitute your variables!
- Host: GitHub
- URL: https://github.com/docwhat/temple
- Owner: docwhat
- License: mit
- Created: 2016-07-29T06:47:49.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2024-10-13T21:46:58.000Z (3 months ago)
- Last Synced: 2024-10-21T21:14:43.194Z (3 months ago)
- Topics: go, golang, substitute, template
- Language: Go
- Homepage: https://pkg.go.dev/docwhat.org/temple
- Size: 197 KB
- Stars: 13
- Watchers: 2
- Forks: 4
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Temple
> Sick of `sed`? Peaked about `perl`? Use `temple` to substitute your variables!
## Installation
### Binaries
I have pre-built binaries for several platform already. They are available on the [releases page](https://github.com/docwhat/temple/releases).
### Source
If you have go v1.6 installed, then you can build the binary with the following command:
```bash
go install docwhat.org/temple
```## Usage
Usage: temple
A simple templating engine
Arguments:
The template file to use ($TEMPLE_TEMPLATE_FILE)Flags:
-h, --help Show context-sensitive help.
--version Show version information
-d, --data=DATA-FILE A YAML or JSON file to use via the {{data.}} interface ($TEMPLE_DATA_FILE)
-H, --html Use HTML templating instead of text templating ($TEMPLE_USE_HTML)Note that the `DATA` file must have an object at the top level. You cannot use a bare string or an array.
JSON Example:
```json
{
"key": "value",
"key2": 2
}
```YAML Example:
```yaml
key: "value"
key2: 2
```## Template Syntax
For complete documentation, read go's [text/template](https://golang.org/pkg/text/template/) and [html/template](https://golang.org/pkg/html/template/).
### Sprig Functions
Temple supports the complete list of [Sprig functions](http://masterminds.github.io/sprig/).
### Data Sources
* `{{hostname}}` -- The systems fully qualified domain name.
* `{{uid}}` -- `UID` of the user running `temple`.
* `{{gid}}` -- `GID` of the user running `temple`.
* `{{euid}}` -- Effective `UID` of the user running `temple`.
* `{{egid}}` -- Effective `GID` of the user running `temple`.
* `{{pwd}}` -- The current working directory.
* `{{json}}` -- Access to your JSON data. Use dot notation to get access to items. e.g. `{{json.authors.greenwood.first_name}}`### Functions
* `{{index 99}}` -- The 99th item of the array ``.
* `{{ | js}}` -- `` escaped/quoted for JavaScript & JSON.
* `{{ | html}}` -- `` escaped/quoted for HTML.
* `{{ | urlquery}}` -- `` escaped/quoted for a URL quoting. i.e. replacing spaces with `+` and using `%NN` syntax.
* `{{ | shellquote}}` -- `` escaped/quoted for POSIX shells.
* `{{ | len}}` -- The length of the ``.### Flow Control
* `{{if }}true string{{else}}false string{{end}}` -- If/Else syntax. The `{{else}}` is optional.
* `{{range }} item: {{.}} {{else}} The list is empty {{end}}` -- Iterate over ``. The `{{else}}` is optional.### Miscellaneous
* `{{ -}}` -- Trim whitespace to the right. e.g. `{{1 -}} .0` becomes `1.0`.
* `{{- }}` -- Trim whitespace to the left.
* `{{- -}}` -- Trim whitespace to the right and left.
* `{{/* comment */}}` -- Comments!## Related Projects
* [gomplate](https://github.com/hairyhenderson/gomplate)
## Thanks
* [@alecthomas](https://github.com/alecthomas) for [kingpin](https://github.com/alecthomas/kingpin)
* [@kballard](https://github.com/kballard) for [go-shellquote](https://github.com/kballard/go-shellquote)
* [@seh](https://github.com/seh) for Go help