Example #1
0
func (self *PongoTemplate) Render(output io.Writer, payload map[string]interface{}) error {
	if self.template != nil {
		return self.template.ExecuteWriter(pongo2.Context(payload), output)
	} else {
		return fmt.Errorf("Cannot execute nil template")
	}
}
Example #2
0
func executeTemplate(template string, vars PlanVars) (string, error) {
	tmpl, err := pongo2.FromString(template)
	if err != nil {
		return "", err
	}

	return tmpl.Execute(pongo2.Context(vars))
}
Example #3
0
func BenchmarkDebugWrapper(b *testing.B) {
	r := renderDebug.Instance("index.tpl", pongo2.Context{"data": "test data"}).(Pongo)
	for n := 0; n < b.N; n++ {
		ctx := pongo2.Context(r.Data.(pongo2.Context))
		err := r.Template.ExecuteWriterUnbuffered(ctx, ioutil.Discard)
		if err != nil {
			b.Fatal(err)
		}
	}
}
Example #4
0
func pongo2() gin.HandlerFunc {
	return func(c *gin.Context) {
		c.Next()

		tmpl, context, err := getContext(c)
		if err == nil {
			c.HTML(http.StatusOK, tmpl+conf.TMPL_SUFFIX, p.Context(context))
		} else {
			log.DebugPrint("Render Error: %v", err)
		}
	}
}
Example #5
0
func (p Pongo) Render(w http.ResponseWriter) error {
	ctx := pongo2.Context(p.Data.(pongo2.Context))
	w.Header().Set("Content-Type", "text/html; charset=utf-8")
	return p.Template.ExecuteWriter(ctx, w)
}
Example #6
0
// Execute - Executes template with context.
func (t *pongoTemplate) Execute(ctx Context, w io.Writer) (err error) {
	err = t.Template.ExecuteWriter(pongo2.Context(ctx), w)
	return
}
Example #7
0
func (node *mapNodeTemplate) Execute(ctx Context) (interface{}, error) {
	res, err := node.template.Execute(pongo2.Context(ctx))
	return res, err
}
Example #8
0
func (p Pongo2) Render(w http.ResponseWriter) error {
	p.writeContentType(w, htmlContentType)
	c := pongo2.Context(p.Data.(Context))

	return p.Template.ExecuteWriter(c, w)
}