bilit

package module
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2020 License: MIT Imports: 4 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Bilit

Try it on Go Playground GitHub

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

Powered by Regular Expressions

Examples

OLD API - Basic:
func main() {
	const template = "Hello, I'm {{name}} from ${City}, {{from_state}}"
	var dataSrc = map[string]string{
		"name": "John",
		"City": "Dallas",
		"from_state": "TX",
	}

	var str = bilit.Populate(template, dataSrc)
	fmt.Println(str)
	// "Hello, I'm John from Dallas, TX"
	var data = bilit.Pull(template, str)
	fmt.Println(data)
	// map[City:Dallas from_state:TX name:John]
}

Open Example Folder

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	//GroupRegexp extracts the name of a nunjucks style lookup
	GroupRegexp = regexp.MustCompile(`(?m)[${]{2}(?P<groupName>[^{}$]*)[}]{1,2}`)
	//DefaultPattern is the default pattern for the regex
	DefaultPattern = ".+"
	//Debug enables printing of the map passed to a template
	Debug = false
)

Functions

func Populate

func Populate(template string, data map[string]string) string

Populate for old api compatibility

Example
str := Populate("Hello, I'm {{name}} from {{City}}, {{from_state}}", Data{
	"name":       "John",
	"City":       "Dallas",
	"from_state": "TX",
})
print(str)
Output:
Hello, I'm John from Dallas, TX

func Pull

func Pull(template, str string) map[string]string

Pull for old api compatibility

Types

type Data

type Data map[string]string

Data is a data map for bilit

type Tmpl

type Tmpl struct {
	// contains filtered or unexported fields
}

Tmpl is a bilit template

func Template

func Template(str string, pattern ...string) Tmpl

Template makes a template

func (Tmpl) Populate

func (t Tmpl) Populate(data Data) string

Populate populates a template with data

func (Tmpl) Pull

func (t Tmpl) Pull(str string) map[string]string

Pull extracts data from a populated string using a template

func (Tmpl) RegEx

func (t Tmpl) RegEx() *regexp.Regexp

RegEx makes the pull regular expression

Directories

Path Synopsis
examples
function module
modern module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL