MyNixOS website logo
Description

A dead-simple shell interpolation templating utility.

Tempered

Hackage

A dead-simple templating utility for simple shell interpolation. Use at your own risk and only on trusted templates.

$ tempered --help
Tempered - Templating engine based on shell interpolation

Usage: tempered [templates]
  Interpolate templates to stdout

Available options:
  templates                The templates to interpolate
  -h,--help                Show this help text

Here's a simple use-case:

{{ # inside "post.md" }}
# My Blog Post

by {{ echo $AUTHOR }}
Published on {{ date +'%B %d, %Y' }}

Here's my blog post!

---
{{ cat ./footer.md | tr 'a-z' 'A-Z' }}
{{ # inside "footer.md" }}
Copyright 2017 Chris Penner
Check me out on twitter @chrislpenner!
See you next time!

Then we can render the template with tempered ./post.md to get:

# My Blog Post

by Chris Penner
Published on April 22, 2017

Here's my blog post!

---
COPYRIGHT 2017 CHRIS PENNER
CHECK ME OUT ON TWITTER @CHRISLPENNER!
SEE YOU NEXT TIME!

If you want you can add a shebang to the top of your template and just run it as an executable, tempered will strip the shebang for you automagically:

test.txt

#!/path/to/tempered
interpolate {{ echo $THIS }}
$ chmod +x test.txt
$ export THIS="that"
$ ./test.txt
interpolate that

Examples Here

Installation

Mac and Linux binaries are provided HERE;

Homebrew On Mac

brew update
brew install ChrisPenner/tools/tempered

Stack

If you're familiar with Haskell Stack:

stack update && stack install tempered

FAQ

There's really not much to it; parses the file and runs anything inside {{ }} as a shell expression and pipes stdout into its spot. If you're clever you can do pretty much anything you want with this.

Variables?

Sure; It's bash.

Hello, my name is {{echo $USER}}

You can set up environment overrides in env.yaml, tempered looks up through the file-system to find an env.yaml from the cwd NOT the template location.

Here's an example env.yaml; we can do simple strings or commands here; just make sure to quote any entries that start with {{ or the YAML parser gets mad.

env.yaml

PROJECT: Tempered
DATE: "{{ date +'%B %d, %Y' }}"

Then you can use them just like normal variables.

For Loops?

It's bash; go for it:

{{ for i in 99 98 97 ; do
    cat <<EOF
$i bottles of beer on the wall
EOF
done }}

output:

99 bottles of beer on the wall
98 bottles of beer on the wall
97 bottles of beer on the wall

__: command not found?

Chances are you're forgetting to echo an env-var; {{ $TITLE }} will try to run the contents of $TITLE as a command, you want {{ echo "$TITLE" }}.

Isn't this whole thing a security risk?

Probably.

Metadata

Version

0.2.0

Platforms (75)

    Darwin
    FreeBSD 13
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd13
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd13
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows