demp
is a Dollar Templating
library.
Go templates use {{ }}
as the template delimeter.
But it might not be the best choice for a end-user facing templating language.
someVar = "$pwd"
# is better than
someVar = "{{ .pwd }}"
demp
exposes a single function ResolveTemplate
.
Which takes 2 arguments.
template
The template stringvariables
The variables to be substituted.
It returns the resolved template string.
import "github.com/pspiagicw/demp"
func main() {
input := "$name is $age years old"
variables := map[string]string{
"name": "John",
"age": "25",
}
fmt.Println(demp.ResolveTemplate(input, variables)) // => "John is 25 years old"
}
demp
uses$
as the template delimeter.- You can use
${someVar}
for convenience. ExamplePlural: ${noun}s
, should printPlural: apples
fornoun=apple
. - Names can only contain
a-z
,A-Z
,0-9
,_
and-
. $$
is used to escape$
. Example:$$name
should print$name
.$$$name
should print$John
forname=John
.
Feel free to open issues and PRs.
MIT