fallsimply / bilit

a bidirectional templating engine in golang - pronounced /ˈbilit/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bilit Logo

MIT Licensed Latest Version pkg.go.dev docs

Bilit (pronounced /ˈbilit/) is a bidirectional template library for Go. Inspired by Javascript's Template Literals and Nunjucks

Powered by Regular Expressions

Examples

Modern API - Basic:

Open Example Folder Try it on Go Playground

template := bilit.Template("Hello, I'm {{name}} from ${City}, {{from_state}}")

dataSrc := map[string]string{
	"name":       "John",
	"City":       "Dallas",
	"from_state": "TX",
}

str := template.Populate(dataSrc)
fmt.Println(str, "end")
// "Hello, I'm John from Dallas, TX"

data := template.Pull(tr)
fmt.Println(data)
// map[City:Dallas from_state:TX name:John]

Function API (Old API) - Basic:

Open Example Folder Try it on Go Playground

const template = "Hello, I'm {{name}} from ${City}, {{from_state}}"

dataSrc := map[string]string{
	"name":       "John",
	"City":       "Dallas",
	"from_state": "TX",
}

str := bilit.Populate(template, dataSrc)
fmt.Println(str, "end")
// "Hello, I'm John from Dallas, TX"

data := bilit.Pull(template, str)
fmt.Println(data)
// map[City:Dallas from_state:TX name:John]

About

a bidirectional templating engine in golang - pronounced /ˈbilit/

License:MIT License


Languages

Language:Go 100.0%