11package easygen_test
22
33import (
4+ "fmt"
45 "os"
6+ "strings"
57
68 "github.com/go-easygen/easygen"
79 "github.com/go-easygen/easygen/egCal"
@@ -15,21 +17,32 @@ type variable struct {
1517// for standalone test, change package to `main` and the next func def to,
1618// func main() {
1719func ExampleExecute () {
20+ easygen .Opts .Debug = 1
21+
1822 tmpl0 := easygen .NewTemplate ().Customize ()
1923 tmpl := tmpl0 .Funcs (easygen .FuncDefs ()).Funcs (egVar .FuncDefs ()).Funcs (egCal .FuncDefs ())
2024
2125 // define driving data of any tye
2226 v0 := variable {"some-init-method" }
23- easygen .Opts .Debug = 1
24-
2527 // https://godoc.org/github.com/go-easygen/easygen#Execute
2628 // provide full template file name with extension
2729 easygen .Execute (tmpl , os .Stdout , "test/var0.tmpl" , v0 )
2830
31+ // Demo of using driving data of pure slice/array
32+ v1 := []string {"red" , "blue" , "white" }
33+ easygen .Execute (tmpl , os .Stdout , "test/list00.tmpl" , v1 )
34+
35+ // Demo output to string
36+ var b strings.Builder
37+ easygen .Execute (tmpl , & b , "test/list00f.tmpl" , v1 )
38+ fmt .Print (b .String ())
39+
2940 // Output:
3041 // Input: "some-init-method"
3142 // Output 1: "SomeInitMethod"
3243 // Output 2: "SOME_INIT_METHOD"
44+ // The colors are: red, blue, white, .
45+ // The colors are: red, blue, white.
3346}
3447
3548// To show the full code in GoDoc
0 commit comments