Skip to content
/ temple Public

Sick of sed? Prosaic about perl? Use temple to substitute your variables!

License

Notifications You must be signed in to change notification settings

docwhat/temple

Repository files navigation

Temple

Sick of sed? Peaked about perl? Use temple to substitute your variables!

GitHub release GitHub license GoDoc reference example Go version
release status main branch status Go Report Card
PRs Welcome GitHub contributors GitHub issues

Installation

Binaries

I have pre-built binaries for several platform already. They are available on the releases page.

Source

If you have go v1.6 installed, then you can build the binary with the following command:

go install docwhat.org/temple

Usage

Usage: temple <template-file>

A simple templating engine

Arguments:
  <template-file>    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.<foo>}} 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:

{
  "key": "value",
  "key2": 2
}

YAML Example:

key: "value"
key2: 2

Template Syntax

For complete documentation, read go's text/template and html/template.

Sprig Functions

Temple supports the complete list of Sprig functions.

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 <expr> 99}} -- The 99th item of the array <expr>.
  • {{<expr> | js}} -- <expr> escaped/quoted for JavaScript & JSON.
  • {{<expr> | html}} -- <expr> escaped/quoted for HTML.
  • {{<expr> | urlquery}} -- <expr> escaped/quoted for a URL quoting. i.e. replacing spaces with + and using %NN syntax.
  • {{<expr> | shellquote}} -- <expr> escaped/quoted for POSIX shells.
  • {{<expr> | len}} -- The length of the <expr>.

Flow Control

  • {{if <expr>}}true string{{else}}false string{{end}} -- If/Else syntax. The {{else}} is optional.
  • {{range <array>}} item: {{.}} {{else}} The list is empty {{end}} -- Iterate over <array>. The {{else}} is optional.

Miscellaneous

  • {{<expr> -}} -- Trim whitespace to the right. e.g. {{1 -}} .0 becomes 1.0.
  • {{- <expr>}} -- Trim whitespace to the left.
  • {{- <expr> -}} -- Trim whitespace to the right and left.
  • {{/* comment */}} -- Comments!

Related Projects

Thanks

About

Sick of sed? Prosaic about perl? Use temple to substitute your variables!

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages