-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
51 lines (46 loc) · 1.18 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package stickgen_test
import (
"fmt"
"github.com/tyler-sommer/stick"
"github.com/veonik/go-stickgen"
)
func ExampleNewGenerator() {
loader := &stick.MemoryLoader{
Templates: map[string]string{
"layout.twig": `Hello, {% block name %}{% endblock %}!`,
"test.twig": `{% extends 'layout.twig' %}{% block name %}World{% endblock %}`,
},
}
g := stickgen.NewGenerator("views", loader)
output, err := g.Generate("test.twig")
if err != nil {
fmt.Printf("An error occured: %s", err.Error())
return
}
fmt.Println(output)
// Output:
// // Code generated by stickgen.
// // DO NOT EDIT!
//
// package views
//
// import (
// "github.com/tyler-sommer/stick"
// "io"
// "fmt"
// )
//
// func blockTestTwigName(env *stick.Env, output io.Writer, ctx map[string]stick.Value) {
// // line 1, offset 43 in test.twig
// fmt.Fprint(output, `World`)
// }
//
// func TemplateTestTwig(env *stick.Env, output io.Writer, ctx map[string]stick.Value) {
// // line 1, offset 0 in layout.twig
// fmt.Fprint(output, `Hello, `)
// // line 1, offset 10 in layout.twig
// blockTestTwigName(env, output, ctx)
// // line 1, offset 37 in layout.twig
// fmt.Fprint(output, `!`)
// }
}