Skip to content

Extremely Lightweight Template Processor (for command line tools)

License

Notifications You must be signed in to change notification settings

lestrrat-morgue/tp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tp

Extremely Lightweight Template Processor (for command line tools)

WHAT IS THIS?

There are many occasions where you are writing some sort of shell script and you just want to write that extremely simple template... You fetch a JSON file from somewhere, and just pipe it through a template processor and get the result. tp is that.

tp is minimalistic: It receives variables in JSON format from standard input, a template file from the command line, and spews out the result to standard output. The template is expected to be in Go's text/template format.

That's all. If you look at the source code, it's dead simple.

EXAMPLE

So suppose in an adhoc shell script I'd like create markdown file containing my github repos, and links to them. First I create my template at repos.md.tmpl:

# My Repositories!

{{range .}}* [{{ .name }}]({{ .html_url }})
{{end}}

Then I call:

curl https://api.github.com/users/lestrrat/repos | tp repos.md.tmpl > repos.md

And voila, I get a nice markdown file!

About

Extremely Lightweight Template Processor (for command line tools)

Resources

License

Stars

Watchers

Forks

Packages

No packages published