"to be defined" - a really simple way to create text templates with placeholders

tbd

Go Report Card     Release     codecov

"to be defined"

A really simple way to create text templates with placeholders.

This tool is deliberately simple and trivial, no advanced features.

If you need advanced templates rendering which supports complex syntax and a huge list of datasources (JSON, YAML, AWS EC2 metadata, BoltDB, Hashicorp > Consul and Hashicorp Vault secrets), I recommend you use one of these:

How does a template looks like ?

A template is a text document in which you can insert placeholders for the text you want to make dynamic.

  • a placeholder is delimited by {{ and }} - (i.e. {{ FULL_NAME }})
  • all text outside placeholders is copied to the output unchanged

Example:

apiVersion: v1
kind: Pod
metadata:
  name: {{ metadata.name }}
  labels:
    app: {{ metadata.labels.app }}
 spec:
  containers:
    - name: {{ container.1.name }}
      image: {{ container.1.image }}
      ports:
        - containerPort: {{ container.1.port }}
    - name: {{ container.2.name }}
      image: {{ container.2.image }}
      ports:
        - containerPort: {{ container.2.port }}

Another example:

{{ greeting }}

I will be out of the office from {{ start.date }} until {{ return.date }}. 
If you need immediate assistance while I’m away, please email {{ contact.email }}.

Best,
{{ name }}

How can I define placeholders values?

Create a text file in which you enter the values for the placeholders.

  • define a placeholder value using KEY = value (or KEY: value)
  • empty lines are skipped
  • lines beginning with # are treated as comments

Example:

# metadata values
metadata.name = rss-site
metadata.labels.app = web

# containers values
container.1.name = front-end
container.1.image = nginx
container.1.port = 80

container.2.name = rss-reader
container.2.image: nickchase/rss-php-nginx:v1
container.2.port: 88

Another example...

greeting: Greetings
start.date: August, 9 
return.date: August 23
contact.email: [email protected]
name: Pinco Pallo 

How fill in the template?

$ tbd -vars /path/to/your/vars /path/to/your/template

Example:

$ tbd -vars testdata/sample1.vars testdata/sample1.yml.tbd

👉 you can also specify an HTTP url to fetch your template and/or placeholders values.

Example:

$ tbd -vars https://raw.githubusercontent.com/lucasepe/tbd/main/testdata/sample2.vars \
    https://raw.githubusercontent.com/lucasepe/tbd/main/testdata/sample2.txt.tbd

and the output is...

Greetings

I will be out of the office from August, 9 until August 23. 
If you need immediate assistance while I’m away, please email [email protected].

Best,
Pinco Pallo

How to list all template placeholders?

  • simply omit the -vars flag
$ tbd /path/to/your/template

Example:

$ tbd testdata/sample1.yml.tbd

How to install?

If you have golang installed:

$ go install github.com/lucasepe/tbd@latest

This will create the executable under your $GOPATH/bin directory.

Ready-To-Use Releases

If you don't want to compile the sourcecode yourself, here you can find the tool already compiled for:

  • MacOS
  • Linux
  • Windows

Credits

Thanks to @valyala for the fasttemplate library - which I have modified by adding and removing some functions for the tbd purpose.

Owner
Luca Sepe
Software Craftsman [Golang / CLI tools].
Luca Sepe
Similar Resources

Templating system for HTML and other text documents - go implementation

FAQ What is Kasia.go? Kasia.go is a Go implementation of the Kasia templating system. Kasia is primarily designed for HTML, but you can use it for any

Mar 15, 2022

Fusozay Var Var: A CLI tool for quick text template rendering

fvv - Fusozay Var Var A CLI tool for quick text template rendering Fusozay Var Var means "have fun" It is a reference to something I see a lot Fusozay

Dec 11, 2021

mold your templated to HTML/ TEXT/ PDF easily.

mold your templated to HTML/ TEXT/ PDF easily.

mold mold your templated to HTML/ TEXT/ PDF easily. install go get github.com/mayur-tolexo/mold Example 1 //Todo model type Todo struct { Title stri

Jun 7, 2019

A scaffold to quickly create a go project

OpenMix 出品:https://openmix.org Mix CLI 一个快速创建 go 项目的脚手架 A scaffold to quickly create a go project Installation 安装 go get -u github.com/mix-go/mixcli

Nov 16, 2022

Create cross-platform GUI apps with Golang + Elm!

README About Create GUI apps with Wails + Elm! Dev env requirements setup a golang toolchain setup a wails toolchain install elm-live globally: npm in

Oct 5, 2022

Simple and fast template engine for Go

fasttemplate Simple and fast template engine for Go. Fasttemplate performs only a single task - it substitutes template placeholders with user-defined

Dec 30, 2022

Simple template suitable for building a webapp backend MVP written in go

A Simple Go Project Template - Suited for Webapp MVPs A simple go project structure setup with all dependencies you need to get your MVP off the groun

Oct 23, 2022

A sane and simple Go REST API template.

Gosane 🧘‍♀️ A sane and simple Go REST API template. Clone me and edit me to fit your usecase. What is Gosane? Gosane is a cloneable API template to g

Dec 7, 2022

Toothpaste is a simple templating engine for Go web applications, inspired by Blade/Twig

A simple HTML templating engine in Go inspired by Twig. Currently supports Variables, Escaping, If statements, Templating and Functional variables.

Nov 7, 2022
A maroto way to create PDFs. Maroto is inspired in Bootstrap and uses gofpdf. Fast and simple.
A maroto way to create PDFs. Maroto is inspired in Bootstrap and uses gofpdf. Fast and simple.

Maroto A Maroto way to create PDFs. Maroto is inspired in Bootstrap and uses Gofpdf. Fast and simple. Maroto definition: Brazilian expression, means a

Jan 7, 2023
Useful template functions for Go templates.

Sprig: Template functions for Go templates The Go language comes with a built-in template language, but not very many template functions. Sprig is a l

Jan 4, 2023
Programatic document generation as a HTTP service. Render PDFs using LaTeX templates and JSON.
Programatic document generation as a HTTP service. Render PDFs using LaTeX templates and JSON.

LaTTe Generate PDFs using LaTeX templates and JSON. Try out the demo! Find LaTTe on Docker Hub Table of Contents About Obtaining LaTTe Running & Using

Dec 29, 2022
Go templates invoked as functions

Package tmplfunc provides an extension of Go templates in which templates can be invoked as if they were functions. See the package documentation for

Dec 22, 2022
Universal JSON, BSON, YAML, CSV, XML converter with templates
Universal JSON, BSON, YAML, CSV, XML converter with templates

Universal JSON, BSON, YAML, CSV, XML translator to ANY format using templates Key features Various input formats (json, bson, yaml, csv, xml) Flexible

Dec 11, 2022
Allows you to fill in variables in your custom project templates.

go-templater The best project templater go-templater lets you use any project template you want and replace the variables with values from the config.

Nov 6, 2021
Callable Ajax / http requests inside Golang templates

jaco Callable Ajax / http requests inside Golang templates Examples Examples #1 {{ define "content" }} <div id="myTodos"></div> <script>

Dec 5, 2021
Simple system for writing HTML/XML as Go code. Better-performing replacement for html/template and text/template

Simple system for writing HTML as Go code. Use normal Go conditionals, loops and functions. Benefit from typing and code analysis. Better performance than templating. Tiny and dependency-free.

Dec 5, 2022
A PDF document generator with high level support for text, drawing and images
A PDF document generator with high level support for text, drawing and images

GoFPDF document generator Package gofpdf implements a PDF document generator with high level support for text, drawing and images. Features UTF-8 supp

Dec 28, 2022
Article spinning and spintax/spinning syntax engine written in Go, useful for A/B, testing pieces of text/articles and creating more natural conversations

GoSpin Article spinning and spintax/spinning syntax engine written in Go, useful for A/B, testing pieces of text/articles and creating more natural co

Dec 22, 2022